Exemple #1
0
def index():
    model.connect_to_db()  # connect to database, using code from model
    # do I need the post id?
    # what exactly is happening here?
    posts = model.get_all_posts()

    return render_template("index.html", all_posts=posts)
Exemple #2
0
def blog():
    filters = []
    tag = request.args.get('tag')
    date = request.args.get('date')
    if tag:
        filters.append(filter_post_by_tag(tag))
    if date:
        date = datetime.datetime.strptime(date, DATE_FORMAT).date()
        filters.append(filter_post_by_date(date))
    all_posts = get_all_posts(filters)
    page = int(request.args.get('page', 1))
    num_pages = (len(all_posts) - 1) // POSTS_PER_PAGE + 1
    begin = min(len(all_posts), (page - 1) * POSTS_PER_PAGE)
    end = min(len(all_posts), page * POSTS_PER_PAGE)
    posts = all_posts[begin:end]
    prev_page = None
    next_page = None
    if page > 1:
        params = request.args.copy()
        params['page'] = page - 1
        prev_page = url_for('blog', **params)
    if page < num_pages:
        params = request.args.copy()
        params['page'] = page + 1
        next_page = url_for('blog', **params)
    return render_template(
            'blog.html', 
            posts=posts, 
            prev_page=prev_page,
            next_page=next_page)
Exemple #3
0
def get_posts():
    assignment_id = request.values.get('assignment_id')
    if not assignment_id:
        return jsonify({'success': False, 'errorMessage': 'Missing Params.'})
    response = get_all_posts(assignment_id)
    if response:
        return response
    else:
        return jsonify({'success': True, 'Message': 'No response.'})
Exemple #4
0
def login():   
    model.connect_to_db()
    email = request.args.get('email')
    password = request.args.get('password')  
    title = model.get_all_posts()

    if model.login(email, password):
        return render_template('recent_posts.html', title=title)
    else:
        return redirect("/")
Exemple #5
0
def show_user_profile(username):
    rows = model.get_all_posts(username)
    message = "Sorry!" + session.get(user_id) + "You don't have any Posts"
    if rows == None:
        flash(message)
        return redirect(url_for("index"))
    else:
        user_id = session.get("user_id")
        #author_name = model.get_username_by_author_id(session.get("user_id"))
        return render_template("wall.html", rows=rows, username=username, 
                                )
def show_user_profile(username):
    rows = model.get_all_posts(username)
    message = "Sorry!" + session.get(user_id) + "You don't have any Posts"
    if rows == None:
        flash(message)
        return redirect(url_for("index"))
    else:
        user_id = session.get("user_id")
        #author_name = model.get_username_by_author_id(session.get("user_id"))
        return render_template("wall.html", rows=rows, username=username, 
                                )
Exemple #7
0
def home():
    if 'username' in session:
        username = session['username']
        user = model.get_user(username)
        logging.debug("user in homepage: (%s)" % user)
        try:
            posts_to_show = model.get_all_posts(username)
        except Exception as e:
            logging.debug("home: Found exception(%s)" % e)
            return error("Error: Could not load posts")

        if user:
            return render_template('home.html', current_user=user, posts=posts_to_show)
    return redirect(url_for('login'))
Exemple #8
0
def main():
    model.connect_to_db()
    posts = model.get_all_posts()
    return render_template("index.html", posts = posts)
Exemple #9
0
def dash_posts():
    posts = get_all_posts()
    return render_template('dash_posts.html', posts=posts)
Exemple #10
0
 def GET(self):
     login_form = login
     posts = model.get_all_posts()
     return render.index(posts, login_form)
Exemple #11
0
def posts():
    posts = db.get_all_posts()
    for post in posts:
        post[3] = get_date(post[3])
    return render_template("posts.html", posts=posts)
Exemple #12
0
def add():
    table = db.get_all_posts()
    return render_template("edit.html", action="write", table=table)