Пример #1
0
def add_news():
    if 'admin' in session and session['admin']:
        return redirect('/news')
    if 'user_id' not in session or session['user_id'] == None:
        return redirect('/login')
    if request.method == 'GET':
        form = AddNewsForm()
        return render_template('add_news.html',
                               title='Добавление новости',
                               form=form)


##            if not('username' in session.keys()) or not('remember_me' in session.keys()):
##                return redirect("/login")
##            if not session['remember_me']:
##                session['remember_me'] = None
##            return '''<head>
##                    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
##
##                </head>
##                <body class="bg-secondary">
##
##                </body>
##
##                    '''
    elif request.method == 'POST':
        form = AddNewsForm()
        news = NewsModel(dbase.get_connection())
        news.insert(form.title.data, form.content.data, session['user_id'])
        return redirect('/news')
Пример #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():
    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
Пример #4
0
def edit_news(news_id):
    global session
    if 'username' not in session:
        return redirect('/login')

    form = AddNewsForm()

    item = Text.query.filter_by(id=news_id).first()
    if request.method == 'GET':
        return render_template('edit_news.html',
                               title='Изменить цель',
                               form=form,
                               item=item)

    elif request.method == 'POST':

        db.session.delete(Text.query.filter_by(id=news_id).first())
        new = Text(user=session['user_id'], text=request.form['content'])

        db.session.add(new)
        db.session.commit()
        return redirect('/success')

    return render_template('edit_news.html',
                           title='Изменить цель',
                           form=form,
                           item=item)
Пример #5
0
def all_of():
    global session

    form = AddNewsForm()

    if 'username' not in session:
        return redirect('/login')
    news = Text.query.filter_by(user=session['user_id'])
    return render_template('all_of.html',
                           title='Все цели',
                           form=form,
                           news=news)
Пример #6
0
def add_news():
    global session
    if 'username' not in session:
        return redirect('/login')

    form = AddNewsForm()
    if request.method == 'GET':
        return render_template('add_news.html',
                               title='Добавить цель',
                               form=form)

    elif request.method == 'POST':
        new = Text(user=session['user_id'], text=request.form['content'])

        db.session.add(new)
        db.session.commit()
        return redirect('/success')

    return render_template('add_news.html', title='Добавить цель', form=form)