示例#1
0
def show_thread(cat, thread_id):
    post = models.Post.query.get(thread_id)

    if post == None: 
        return render_template('404.html'), 404

    allcomm = queries.query_comment(post.id)
    
    comment_data = {
        'name': '',
        'comment': ''
    }

    filename = ''

    if request.method == 'POST':
        comment_data['name'] = request.form['name']
        comment_data['comment'] = request.form['comment']
        comment_time = datetime.datetime.utcnow()
        file = request.files['file']
        if file and allowed_filename(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))


        if comment_data['name'] == '':
            comment_data['name'] = 'Anonymous'

    if comment_data['comment'] != '':
        comment = models.Comment(author=comment_data['name'], comment=comment_data['comment'], time=comment_time, file=filename, post_id=thread_id)
        db.session.add(comment)
        db.session.commit()
        return redirect(cat, code=302)
    
    return render_template('thread.html', post=post, allcomm=allcomm)
示例#2
0
def show_category(cat):
    category = queries.query_category_by_name(cat)
    posts = queries.query_post(category['id'])

    if category['id'] == '' or category['name'] == '' or category['url'] == '':
        return render_template('404.html'), 404

    allcomm = []

    for p in posts:
        allcomm.append(queries.query_comment(p['id']))

    thread_data = {
        'name': '',
        'subject': '',
        'comment': '',
    }

    if request.method == 'POST':
        thread_data['name'] = request.form['name']
        thread_data['subject'] = request.form['subject']
        thread_data['comment'] = request.form['comment']
        file = request.files['file']
        if file and allowed_filename(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        post_time = datetime.datetime.utcnow()

        if thread_data['name'] == '':
            thread_data['name'] = 'Anonymous'

    if thread_data['comment'] != '':
        thread = models.Post(author=thread_data['name'], title=thread_data['subject'], text=thread_data['comment'], time=post_time, file=filename, category_id=category['id'])
        db.session.add(thread)
        db.session.commit()
        return redirect(cat, code=302)
    
    return render_template('board.html', category=category, posts=posts, allcomm=allcomm, cat=cat)