Пример #1
0
def add_news(book):
    if book == "none":
        if 'username' not in session:
            return redirect('/login')
        form = AddNewsForm()
        if form.validate_on_submit():
            title = form.title.data
            content = form.content.data
            nm = NewsModel(db.get_connection())
            nm.insert("Без книги", title, content, session['user_id'])
            return redirect("/index")
        return render_template('add_news.html',
                               title='Добавление заметки',
                               form=form,
                               username=session['username'],
                               admins=admins,
                               book="")
    else:
        if 'username' not in session:
            return redirect('/login')
        form = AddNewsForm()
        if form.validate_on_submit():
            title = form.title.data
            content = form.content.data
            nm = NewsModel(db.get_connection())
            nm.insert(book, title, content, session['user_id'])
            return redirect("/index")
        return render_template('add_news.html',
                               title='Добавление заметки',
                               form=form,
                               username=session['username'],
                               admins=admins,
                               book=book)
Пример #2
0
def add_news():
    if 'username' not in session:
        return redirect('/login')
    form = AddNewsForm()
    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data
        nm = NewsModel(db.get_connection())
        nm.insert(title, content, session['user_id'])
        return redirect("/index")
    return render_template('add_news.html', title='Добавление новости', form=form, username=session['username'])
Пример #3
0
def add_news():
    form = AddNewsForm()
    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data
        nm = NewsModel(db.get_connection())
        nm.insert(title, content)
        return redirect("/news_list")
    return render_template('add_news.html',
                           username=session['username'],
                           form=form)
Пример #4
0
def add_news():
    if 'username' not in session:  # if you try to get to /add_news without logging in you will be redirected to login page
        return redirect('/login')
    form = AddNewsForm()
    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data
        nm = NewsModel(db.get_connection())
        nm.insert(title, content, session['user_id'])
        return redirect("/index")
    return render_template('add_news.html',
                           title='Добавление новости',
                           form=form,
                           username=session['username']
                           )  # get all news if something/nothing changed
Пример #5
0
def index():
    if 'username' not in session:  # if you are not loginned you should login
        return redirect('/login')
    form = PostForm()
    if form.validate_on_submit():  # if news_title is not empty
        title = form.title.data
        content = form.content.data
        nm = NewsModel(db.get_connection())
        nm.insert(title, content, session['user_id'])
        return redirect("/index")
    news = NewsModel(db.get_connection()).get_all(
        session['user_id'])  # add note to news db
    return render_template(
        'index.html',
        username=session['username'],
        # update page because of the new note added
        news=reversed(news),
        form=form)
Пример #6
0
def main():
    if 'username' not in session:
        return redirect('/login')
    nm = NewsModel(db.get_connection())
    nm.init_table()
    um = UsersModel(db.get_connection())
    um.init_table()
    # nm.delete_all()
    if request.method == "POST":
        content = request.form["comment"]
        # content = request.files["uploadingfiles"]
        avatar = um.get_avatar(session['username'])
        print(avatar)
        nm.insert(str(time.asctime(time.localtime(time.time()))), content,
                  session['username'], avatar)
        for i in nm.get_all():
            check_if_avatar_exists(i)
        return redirect("/main")
    else:
        print(nm.get_all())
        return render_template('home.html',
                               title='Добавление новости',
                               username=session['username'],
                               news=nm.get_all())
Пример #7
0
 def post(self):
     args = parser.parse_args()
     news = NewsModel(db.get_connection())
     news.insert(args['title'], args['content'], args['user_id'])
     return jsonify({'success': 'OK'})