Example #1
0
from flask import Flask, request, render_template, redirect
from db import DB
from newsmodel import NewsModel
from usermodel import UsersModel
from add_news import AddNewsForm, LoginForm
import sqlite3
from werkzeug.security import generate_password_hash, check_password_hash

app = Flask(__name__)

session = {}
db = DB()
con = db.get_connection()
print(con)
nws = NewsModel(con)
nws.init_table()

print(nws.get_all())
cursor = nws.connection.cursor()
cursor.execute("SELECT * FROM news ")
rows = cursor.fetchall()
print(rows)
app.config.update(
    dict(SECRET_KEY="powerful secretkey",
         WTF_CSRF_SECRET_KEY="a csrf secret key"))


@app.route('/login', methods=['GET', 'POST'])
def login():
    form = LoginForm()
    if request.method == 'POST':
Example #2
0
from newsmodel import NewsModel
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: