Example #1
0
def edit_one(post_id):
    post_id = Obfuscator.restore(post_id)
    db = g.db
    post = db.query(Post).filter_by(id=post_id).one()
    if not post:
        return abort(400)
    return render_template('edit.html', post=post, action=url_for('post_update', post_id=post_id), method='PUT')
Example #2
0
def index():
    p = int(request.args.get('p') or 1)
    tag_id = request.args.get('tag')
    author_id = request.args.get('author')
    month_str = request.args.get('month')
    tag_idint = None
    author_idint = None
    tag_name = None
    author_name = None
    month = None

    if tag_id:
        tag_idint = Obfuscator.restore(tag_id)
        tag_name = getattr(Tag.get(tag_idint), 'name', None)
    if author_id:
        author_idint = Obfuscator.restore(author_id)
        author_name = getattr(Author.get(author_idint), 'name', None)
    if month_str:
        try:
            month = datetime.strptime(month_str, '%Y-%m')
        except ValueError:
            month = None

    posts, count = Post.query(p=p, num=SITE['num_per_page'], tag_id=tag_idint, author_id=author_idint, month=month)

    page_num = math.ceil(count / SITE['num_per_page'])
    next_url = url_for('index', p=p+1, tag=tag_id, author=author_id, month=month_str) if p < page_num else None
    prev_url = url_for('index', p=p-1, tag=tag_id, author=author_id, month=month_str) if p > 1 else None

    context = dict(
        posts=posts,
        tag_name=tag_name,
        author_name=author_name,
        month=month,
        next_url=next_url,
        prev_url=prev_url,
        p=p,
        title=SITE['title'],
    )
    return render_template('index.html', **context)
Example #3
0
def manage():
    p = int(request.args.get('p') or 1)
    tag_id = request.args.get('tag') or None
    tag_idint = None
    if tag_id:
        tag_idint = Obfuscator.restore(tag_id)
    deleted = int(request.args.get('deleted') or 0)

    posts, count = Post.query(p=p, num=SITE['num_per_page'], tag_id=tag_idint, author_id=session['author_id'],
                              deleted=deleted)

    tp = math.ceil(count / SITE['num_per_page'])
    prev_url = url_for('manage', p=p-1, tag=tag_id) if p > 1 else ''
    next_url = url_for('manage', p=p+1, tag=tag_id) if p < tp else ''
    return render_template('manage.html', posts=posts, prev_url=prev_url, next_url=next_url, deleted=deleted)
Example #4
0
def post_get(post_id):
    post_id = Obfuscator.restore(post_id)
    db = g.db
    post = db.query(Post).filter_by(id=post_id).first()
    return render_template('post.html', post=post, title=SITE['title'])
Example #5
0
def mpost_get(post_id):
    db = g.db
    post = db.query(Post).filter_by(id=Obfuscator.restore(post_id)).first()
    return render_template('mpost.html', post=post, title=SITE['title'], url=SITE['url'] + '/posts/' + post_id)