Esempio n. 1
0
def new_post():
    if 'username' in session:
        cat_tags = dbhandler.getCategories()
        media = os.listdir('static/uploads/img')
        return render_template('edit-post.html',
                               cat_tags=cat_tags,
                               media=media)
    else:
        return redirect('/blog-latest')
Esempio n. 2
0
def blog():
    title = 'Blog'
    posts = dbhandler.getPosts()
    cats = dbhandler.getCategories()
    rels = dbhandler.getRelationship()
    posts = posts[::-1]
    return render_template('blog.html',
                           posts=posts,
                           cats=cats,
                           rels=rels,
                           title=title)
Esempio n. 3
0
def manage_db():
    if 'username' in session:
        posts = dbhandler.getPosts()
        tags = dbhandler.getCategories()
        rels = dbhandler.getRelationship()
        users = dbhandler.getusers()
        return render_template('manage-db.html',
                               posts=posts,
                               tags=tags,
                               rels=rels,
                               users=users)
    else:
        return redirect('/blog-latest')
Esempio n. 4
0
def edit_post(postId):
    if 'username' in session:
        media = os.listdir('static/uploads/img')
        data = dbhandler.getPostById(postId)
        tags = dbhandler.getCategories()
        rels = dbhandler.getRelationship()
        ticked_tags = [r for r in rels if r[0] == data[0][0]]
        return render_template('edit-post.html',
                               data=data,
                               cat_tags=tags,
                               ticked_tags=ticked_tags,
                               media=media)
    else:
        return redirect('/blog-latest')
Esempio n. 5
0
def view_post(postid):
    title = 'Blog'
    post = dbhandler.getPostById(postid)
    cats = dbhandler.getCategories()
    rels = dbhandler.getRelationship()
    tags = []
    tag_gen = ((c for c in cats if c[0] == r[1]) for r in rels
               if r[0] == post[0][0])
    for tg in tag_gen:
        for t in tg:
            tags.append(t)
    return render_template('post.html',
                           post=post,
                           cats=cats,
                           tags=tags,
                           title=title)
Esempio n. 6
0
def get_latest_post():
    title = 'Blog'
    posts = dbhandler.getPosts()
    cats = dbhandler.getCategories()
    rels = dbhandler.getRelationship()
    posts = posts[::-1]
    post = posts[:1:]
    tags = []
    tag_gen = ((c for c in cats if c[0] == r[1]) for r in rels
               if r[0] == post[0][0])
    for tg in tag_gen:
        for t in tg:
            tags.append(t)
    return render_template('post.html',
                           post=post,
                           cats=cats,
                           tags=tags,
                           title=title)
Esempio n. 7
0
def get_posts_by_tag(tagid):
    title = 'Blog'
    tagid = tagid
    posts = dbhandler.getPosts()
    rels = dbhandler.getRelationship()
    cats = dbhandler.getCategories()
    search_tag = dbhandler.getCategoryById(tagid)
    searched_posts = ((p for p in posts if p[0] == r[0]) for r in rels
                      if r[1] == int(tagid))
    sp_list = []
    for sp in searched_posts:
        for s in sp:
            sp_list.append(s)
    sp_list = sp_list[::-1]
    return render_template('blog.html',
                           posts=sp_list,
                           cats=cats,
                           search_tag=search_tag,
                           title=title)
Esempio n. 8
0
def admin():
    if 'username' in session:
        cats = dbhandler.getCategories()
        return render_template('settings.html', cats=cats)
    else:
        return redirect('/login')