コード例 #1
0
def delete_news(news_id):
    if 'username' not in session:
        return redirect('/ban')
    nm = NewsModel(news_db.get_connection())
    nm.delete(news_id)
    cm = CommentsModel(comments_db.get_connection())
    cm.news_delete(news_id)
    return redirect("/index")
コード例 #2
0
def news_data(news_id):
    if 'username' not in session:
        return redirect('/ban')
    form = CommentForm()
    if form.validate_on_submit():
        content = form.content.data
        cm = CommentsModel(comments_db.get_connection())
        author_data = UsersModel(users_db.get_connection()).get(
            session['user_id'])
        username = author_data[2] + ' ' + author_data[3]
        cm.insert(session['user_id'], news_id, content, username)
        return redirect("/news/" + str(news_id))
    news = NewsModel(news_db.get_connection()).get(news_id)
    author_data = UsersModel(users_db.get_connection()).get(news[4])
    username = author_data[2] + ' ' + author_data[3]
    cm = CommentsModel(comments_db.get_connection()).get_all(news[0])
    cm.reverse()
    return render_template('news_data.html',
                           title=news[1],
                           author=username,
                           cur_user_id=session['user_id'],
                           news=news,
                           cm=cm,
                           form=form)
コード例 #3
0
def delete_comment(comment_id):
    if 'username' not in session:
        return redirect('/ban')
    cm = CommentsModel(comments_db.get_connection())
    cm.delete(comment_id)
    return redirect("/index")
コード例 #4
0
from commentsmodel import CommentsModel
from editform import EditForm
from shutil import copy
from db import DB
import datetime

app = Flask(__name__)
app.config['SECRET_KEY'] = 'yandexlyceum_secret_key'
users_db = DB('users.db')
news_db = DB('news.db')
comments_db = DB('comments.db')
users_init = UsersModel(users_db.get_connection())
users_init.init_table()
news_init = NewsModel(news_db.get_connection())
news_init.init_table()
comments_init = CommentsModel(comments_db.get_connection())
comments_init.init_table()


@app.route('/')
@app.route('/index')
def index():
    if 'username' not in session:
        return redirect('/ban')
    news = NewsModel(news_db.get_connection()).get_all(session['user_id'])
    news.sort(key=lambda x: x[3])
    news.reverse()
    user_model = UsersModel(users_db.get_connection())
    usernames = {}
    for item in news:
        data = user_model.get(item[4])