コード例 #1
0
 def send_message():
     if not auth.is_authorized():
         return redirect('/login')
     form = WriteMessageForm()
     if form.validate_on_submit():
         receiver_id = request.args.get('sel')
         user = User.query.filter_by(id=receiver_id).first()
         message = form.message.data
         Post.add(from_who=auth.get_user().username,
                  to=user.username,
                  message=message,
                  user=auth.get_user())
         return redirect('/main')
     return render_template('message-write.html',
                            title='Написать сообщение',
                            form=form)
コード例 #2
0
 def dark_Books_list():
     if not auth.is_authorized():
         return redirect('/dark_login')
     Books_list = Books.query.filter_by(user_id=auth.get_user().id)
     return render_template('dark_books-list.html',
                            title="Книги",
                            books_list=Books_list)
コード例 #3
0
 def news_delete(id: int):
     if not auth.is_authorized():
         return redirect('/login')
     news = News.query.filter_by(id=id).first()
     if news.user_id != auth.get_user().id:
         abort(403)
     News.delete(news)
     return redirect('/news')
コード例 #4
0
 def characters_delete(id: int):
     if not auth.is_authorized():
         return redirect('/login')
     character = Character.query.filter_by(id=id).first()
     if character.user_id != auth.get_user().id:
         abort(403)
     Character.delete(character)
     return redirect('/characters')
コード例 #5
0
 def Book_delete(id: int):
     if not auth.is_authorized():
         return redirect('/login')
     book = Books.query.filter_by(id=id).first()
     if book.user.id != auth.get_user().id:
         abort(403)
     Books.delete(book)
     return redirect('/books')
コード例 #6
0
 def index():
     if not auth.is_authorized():
         return render_template(
             'index.html',
             title='Главная',
         )
     news_list = News.query.filter_by(user_id=auth.get_user().id)
     return render_template('news-list.html',
                            title="Главная",
                            news_list=news_list)
コード例 #7
0
 def dark_index():
     if not auth.is_authorized():
         return render_template(
             'dark_index.html',
             title='Главная',
         )
     all_book_list = Books.query.filter_by(user_id=auth.get_user().id)
     return render_template('books-list.html',
                            title="Мои книги",
                            books_list=all_book_list)
コード例 #8
0
 def news_create_form():
     if not auth.is_authorized():
         return redirect('/login')
     form = NewsCreateForm()
     if form.validate_on_submit():
         title = form.title.data
         content = form.content.data
         News.add(title=title, content=content, user=auth.get_user())
         return redirect('/')
     return render_template('news-create.html',
                            title='Создать новость',
                            form=form)
コード例 #9
0
 def news_view(id: int):
     if not auth.is_authorized():
         return redirect('/login')
     news = News.query.filter_by(id=id).first()
     if not news:
         abort(404)
     if news.user_id != auth.get_user().id:
         abort(403)
     user = news.user
     return render_template('news-view.html',
                            title='Новость - ' + news.title,
                            news=news,
                            user=user)
コード例 #10
0
 def characters_view(id: int):
     if not auth.is_authorized():
         return redirect('/login')
     character = Character.query.filter_by(id=id).first()
     if not character:
         abort(404)
     if character.user_id != auth.get_user().id and not character.ispublic:
         abort(403)
     user = character.user
     return render_template('character-view.html',
                            title='Персонаж - ' + character.title,
                            character=character,
                            user=user)
コード例 #11
0
 def dark_Books_view(id: int):
     if not auth.is_authorized():
         return redirect('/login')
     Book = Books.query.filter_by(id=id).first()
     if not Book:
         abort(404)
     if Books.user_id != auth.get_user().id:
         abort(403)
     user = Book.user
     return render_template('dark_books-view.html',
                            title='Книга - ' + Book.title,
                            book=Book,
                            author=Book.author,
                            content=Book.content,
                            user=user,
                            link=Book.link)
コード例 #12
0
 def dark_Books_create_form():
     if not auth.is_authorized():
         return redirect('/login')
     form = BooksCreateForm()
     if form.validate_on_submit():
         title = form.title.data
         author = form.author.data
         content = form.content.data
         link = form.link.data
         Books.add(title=title,
                   author=author,
                   content=content,
                   link=link,
                   user=auth.get_user())
         return redirect('/')
     return render_template('dark_books-create.html',
                            title='Создать книгу',
                            form=form)
コード例 #13
0
 def character_create_form():
     if not auth.is_authorized():
         return redirect('/login')
     form = CharacterCreateForm()
     if form.validate_on_submit():
         name = form.name.data
         title = form.title.data
         city = form.city.data
         age = form.age.data
         info = form.info.data
         ispublic = form.ispublic.data
         Character.add(name=name,
                       title=title,
                       city=city,
                       age=age,
                       info=info,
                       ispublic=ispublic,
                       user=auth.get_user())
         return redirect('/characters')
     return render_template('character-create.html',
                            title='Создать новость',
                            form=form)
コード例 #14
0
    def add_survey():
        session['last_page'] = '/surveys/create'

        if not auth.is_authorized():
            return redirect('/login')

        if request.method == 'POST':
            title = request.form['survey-title']
            category = request.form['survey-category']
            publicity_check = eval(request.form['publicity_check'])
            on_admin_check = publicity_check
            if not publicity_check:
                publicity_check = False
                on_admin_check = False
            Surveys.add(title=title,
                        category=category,
                        publicity_check=publicity_check,
                        on_admin_check=on_admin_check,
                        user=auth.get_user())
            return redirect(session['last_page'])

        return render_template('survey_create.html',
                               title='Создание опроса',
                               category_list=categories)
コード例 #15
0
 def render_template(*args, **kwargs):
     kwargs['auth_user'] = auth.get_user()
     return flask_render_template(*args, **kwargs)