Exemplo n.º 1
0
def main(request):
    if request.method == "GET":
        cats = session.query(Category).all()
        return display_plain_template('admin/new_page', cats=cats)
    if 'submit' in request.form:
        page = new_page(request)
        return redirect('/admin/edit_page/%d' % page.page_id)
Exemplo n.º 2
0
def main(request):
    if request.method != "POST":
        return display_plain_template('admin/login', message="Not a POST request")
    
    user = request.form.get('a')
    hash = hash_password(request.form.get('b'))
    if admin_cred_match_prim(user, hash):
        cookie = {
            'admin_user': user,
            'admin_hash': hash
        }
        response = redirect('/admin')
        response.set_cookie('admin', mk_secure_cookie(cookie).serialize(), httponly=True)
        return response

    return display_plain_template('admin/login', message="Password incorrect")
Exemplo n.º 3
0
def main(request):
    query = session.query(Comment).order_by(Comment.comment_id.desc());

    if (request.args.get('page')):
        query = query.slice(int(request.args.get('page'))*100, (int(request.args.get('page'))+1)*100)
        all_comments = query
    else:
        all_comments = query.limit(100)
    return display_plain_template('admin/comments', comments=all_comments)
Exemplo n.º 4
0
def main(request, page_id):
    if request.method == "GET":
        page = session.query(Page).filter_by(page_id=page_id).first()
        cats = session.query(Category).all()
        return display_plain_template('admin/edit_page', page=page, cats=cats)

    if 'submit' in request.form:
        return edit_page_submit(request, page_id)
    elif 'publish' in request.form:
        return publish_page(request, page_id)
    elif 'preview' in request.form:
        return edit_page_preview(request, page_id)
Exemplo n.º 5
0
def main(request):
    query = session.query(Page)

    if request.args.get('unpublished') is not None:
        query = query.filter_by(status='draft')
    elif request.args.get('posts') is not None:
        query = query.filter_by(status='post')
    elif request.args.get('pages') is not None:
        query = query.filter_by(status='page')

    all_pages = query.order_by(Page.page_id).all()
    return display_plain_template('admin/pages', pages=all_pages)
Exemplo n.º 6
0
def main(request):
    query = session.query(Page)

    if request.args.get('type') == 'unpublished':
        query = query.filter_by(status='draft')
    elif request.args.get('type') == 'posts':
        query = query.filter_by(status='post')
    elif request.args.get('type') == 'pages':
        query = query.filter_by(status='page')

    if request.args.get('sort') == 'id_desc' or request.args.get('sort') is None:
        query = query.order_by(Page.page_id.desc())
    elif request.args.get('sort') == 'id_asc':
        query = query.order_by(Page.page_id.asc())
    elif request.args.get('sort') == 'created_asc':
        query = query.order_by(Page.created.asc())
    elif request.args.get('sort') == 'created_desc':
        query = query.order_by(Page.created.desc())

    all_pages = query.order_by(Page.page_id).all()
    return display_plain_template('admin/pages', pages=all_pages)
Exemplo n.º 7
0
def edit_page_submit(request, page_id):
    page = session.query(Page).filter_by(page_id=page_id).first()
    page_cat = session.query(Category).filter_by(category_id=request.form['cat_id']).first()

    page.title        = request.form['title']
    page.content      = request.form['content']
    page.excerpt      = request.form['excerpt']
    page.request_path = request.form['request_path']
    page.category     = page_cat
    page.last_update  = datetime.utcnow()

    if page.status == 'draft':
        page.set_meta('draft_tags', request.form['tags'])
    else:
        new_tags = set(tag_list(request.form['tags']))
        old_tags = set([t.name for t in page.tags])

        removed_tags = old_tags-new_tags
        if removed_tags:
            for tag in removed_tags:
                page.delete_tag(tag)

        new_tags = new_tags-old_tags
        if new_tags:
            for tag in new_tags:
                seo_name = tag.replace(' ', '-')
                page.add_tag(Tag(tag, seo_name))

    page.save()
    if config.use_cache:
        cache_del('posts_tags')
        if page.request_path:
            cache_del('individual_page_%s' % page.request_path)

    change_note = request.form['change_note'].strip()
    if change_note:
        Revision(page, change_note).save()

    cats = session.query(Category).all()
    return display_plain_template('admin/edit_page', page=page, cats=cats)
Exemplo n.º 8
0
def main(request):
    cats = session.query(Category).all()
    return display_plain_template('admin/categories', cats=cats)
Exemplo n.º 9
0
def main(request):
    if not logged_in(request):
        return display_plain_template('admin/login')
    return display_plain_template('admin/index')
Exemplo n.º 10
0
def main(request):
    fof = session.query(FouroFour).order_by(FouroFour.date.desc()).all()
    return display_plain_template('admin/404', fof=fof)
Exemplo n.º 11
0
def main(request):
    exc = session.query(Exception).order_by(Exception.date.desc()).all()
    return display_plain_template('admin/exceptions', exc=exc)