Esempio n. 1
0
def setting_avatar():
    user = Account.get_current_user()
    if request.method == 'POST':
        file = request.files['avatar']
        file_name = secure_filename(file.filename)
        file.save(os.path.join('avatar', file_name))
        DBHelper.update_avatar(user.id, '/avatar/' + file_name)
    user = Account.get_current_user()
    return render_template('setting.html', user=user)
Esempio n. 2
0
def setting():
    user = Account.get_current_user()
    if request.method == 'POST':
        DBHelper.update_user(user.id, request.form['username'])
        DBHelper.update_social_account(user.id, request.form['github'],
                                       request.form['weibo'],
                                       request.form['twitter'])
        user = Account.get_current_user()
    return render_template('setting.html', user=user)
Esempio n. 3
0
def discussion(id):
    user = None
    message = None
    isLogin = Account.isLogin()
    if isLogin:
        user = Account.get_current_user()
    if request.method == 'POST':
        if isLogin:
            DBHelper.create_comment(id, user.username, request.form['content'])
            DBHelper.update_comment_count(id)
        else:
            message = 'please login'
    article = DBHelper.get_article(id)
    article.time = post_time(article.create_at)
    comments = DBHelper.get_comments(id)
    if comments:
        for comment in comments:
            comment.time = post_time(comment.create_at)
    statistics = {}
    statistics['user_count'] = DBHelper.get_user_count()
    statistics['article_count'] = DBHelper.get_article_count()
    statistics['comment_count'] = DBHelper.get_comment_count()
    return render_template('discussion.html',
                           user=user,
                           article=article,
                           comments=comments,
                           statistics=statistics,
                           message=message)
Esempio n. 4
0
def setting_password():
    user = Account.get_current_user()
    if request.method == 'POST':
        password_current = request.form['password_current']
        password_new = request.form['password_new']
        if password_current == user.password:
            DBHelper.update_password(user.id, password_new)
    return render_template('setting.html', user=user)
Esempio n. 5
0
def notification():
    user = Account.get_current_user()
    comments = DBHelper.get_notifications(user.username)
    if comments:
        for comment in comments:
            comment['time'] = post_time(comment['create_at'])
            comment_user = DBHelper.get_user_by_name(comment['username'])
            comment['avatar'] = comment_user.avatar
    return render_template('notification.html', user=user, comments=comments)
Esempio n. 6
0
def classify(tag):
    user = None
    message = None
    if Account.isLogin():
        user = Account.get_current_user()
    articles = DBHelper.get_articles_by_tag(tag, 0)
    statistics = {}
    statistics['user_count'] = DBHelper.get_user_count()
    statistics['article_count'] = DBHelper.get_article_count()
    statistics['comment_count'] = DBHelper.get_comment_count()
    return render_template('index.html',
                           user=user,
                           articles=articles,
                           tag=tag,
                           statistics=statistics)
Esempio n. 7
0
def article():
    user = None
    if Account.isLogin():
        user = Account.get_current_user()
    statistics = {}
    statistics['user_count'] = DBHelper.get_user_count()
    statistics['article_count'] = DBHelper.get_article_count()
    statistics['comment_count'] = DBHelper.get_comment_count()
    if request.method == 'GET':
        return render_template('article.html',
                               user=user,
                               statistics=statistics)
    else:
        DBHelper.create_article(user.username, request.form['tag'],
                                request.form['title'],
                                request.form['contentArea'])
        return redirect(url_for('index'))
Esempio n. 8
0
def index():
    user = None
    if Account.isLogin():
        user = Account.get_current_user()
    articles = DBHelper.get_articles(0)
    if articles:
        for article in articles:
            article.time = post_time(article.create_at)
    statistics = {}
    statistics['user_count'] = DBHelper.get_user_count()
    statistics['article_count'] = DBHelper.get_article_count()
    statistics['comment_count'] = DBHelper.get_comment_count()
    return render_template('index.html',
                           user=user,
                           articles=articles,
                           tag='all',
                           statistics=statistics)
Esempio n. 9
0
def user(username):
    user = Account.get_current_user()
    articles = DBHelper.get_articles_by_username(username, 0)
    if articles:
        for article in articles:
            article.time = post_time(article.create_at)
    comments = DBHelper.get_comments_by_username(username, 0)
    commentted_articles = DBHelper.get_articles_by_comments(username, 0)
    if comments:
        index = 0
        for comment in comments:
            comment.article_title = commentted_articles[index].title
            comment.time = post_time(comment.create_at)
            index = index + 1
    return render_template('user.html',
                           user=user,
                           articles=articles,
                           comments=comments)