Esempio n. 1
0
def diary_day(author_sid, year, month, day):
    author = User.query.filter_by(sid = uidify(author_sid)).first()
    if author:
        try:
            the_date = date(year, month, day)
        except ValueError:
            return page_not_found()
        else:
            post = author.posts.filter(Post.posted_date == the_date).first()
            if post:
                return render_diary(author, [post], the_date.strftime('%B %d, %Y'), template="diary-single.html")
            else:
                return page_not_found()
    else:
        return page_not_found()
Esempio n. 2
0
def diary_latest(author_sid):
    author = User.query.filter_by(sid = uidify(author_sid)).first()
    if author:
        posts = author.posts.order_by(Post.posted_date.desc()).all()
        return render_diary(author, posts, "")
    else:
        return page_not_found()
Esempio n. 3
0
def diary_month(author_sid, year, month):
    author = User.query.filter_by(sid = uidify(author_sid)).first()
    if author:
        try:
            min_date = date(year, month, 1)
            max_date = date(year, month, calendar.monthrange(year, month)[1])
        except ValueError:
            return page_not_found()
        else:
            posts = author.posts\
                    .filter(Post.posted_date >= min_date)\
                    .filter(Post.posted_date <= max_date)\
                    .order_by(Post.posted_date.asc())\
                    .all()
            return render_diary(author, posts, min_date.strftime(''))
    else:
        return page_not_found()
Esempio n. 4
0
def diary(author_sid):
    # Dict of year: [list months]
    author = User.query.filter_by(sid = uidify(author_sid)).first()
    if author:
        posts = (author.posts.order_by(Post.posted_date.desc())
                 .limit(7).all())
        return render_diary(author, posts, template="diary-search.html")
    else:
        return page_not_found()
Esempio n. 5
0
def fetch_next_post(author_sid, datestamp):
    author = User.query.filter_by(sid=author_sid).first()
    if author:
        y, m, d = map(int, datestamp.split("-"))
        cur_date = date(y, m, d)
        post = author.posts.filter(Post.posted_date < cur_date).order_by(Post.posted_date.desc()).first()
        if post:
            return render_template("entry-base.html", p=post)
        else:
            return "no more"
    else:
        return page_not_found()
Esempio n. 6
0
def diary_search(author_sid):
    author = User.query.filter_by(sid = uidify(author_sid)).first()
    if author:
        print(request.form['search_term'])
        posts = (author.posts
                 .order_by(Post.posted_date.desc())
                 .filter(Post.content.ilike('%%%s%%' % request.form['search_term']))
                 .limit(100).all())
        posts = [p for p in posts if p.viewable_by(g.user, g.date)]
        return render_diary(author, posts, template="diary-search.html",
                            search_term = request.form['search_term'])
    else:
        return page_not_found()
Esempio n. 7
0
def change_password():
    if not g.user:
        return page_not_found()

    old_pass = request.form.get('old_pass')
    new_pass = request.form.get('new_pass')

    if len(new_pass) < 3:
        return 'Please enter a new password at least 3 characters long.'

    if g.user.verify_password(old_pass):
        g.user.set_password(new_pass)
        db.session.commit()
        return 'password changed!'
    else:
        return 'wrong old password'
Esempio n. 8
0
def edit_settings_action():
    if not g.user:
        return page_not_found()

    setting_name = request.form.get('setting_name')
    setting_value = request.form.get('setting_value')

    if setting_name == 'private':
        # True
        if int(setting_value):
            g.user.publicity = 0
        else:
            g.user.publicity = 2
        db.session.commit()
        return 'saved!'
    elif setting_name == 'secret_days':
        if setting_value == 'Hidden':
            g.user.publicity = 1
        elif setting_value == 'Forever':
            g.user.publicity = 0
        else:
            g.user.publicity = 2
            g.user.secret_days = int(setting_value)
        db.session.commit()
        return 'saved!'
    elif setting_name == 'theme':
        g.user.theme = setting_value
        db.session.commit()
        return 'refresh to see theme'
    elif setting_name == 'color':
        # User selection of color is taken as a suggestion only.
        # Each theme will incorporate the colors differently.
        g.user.color = setting_value
        print("I am now a", g.user.color)
        db.session.commit()
        return 'refresh to see color'
    else:
        return 'error'
    return 'Jim messed up'
Esempio n. 9
0
def diary_search_page(author_sid):
    author = User.query.filter_by(sid = uidify(author_sid)).first()
    if author:
        return render_diary(author, [], template="diary-search.html")
    else:
        return page_not_found()
Esempio n. 10
0
def edit_settings():
    if not g.user:
        return page_not_found()

    private = (g.user.publicity == 0)
    return render_template('settings.html', private=private)