Пример #1
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)
Пример #2
0
    def surveys_view(survey_id: int):
        survey = Surveys.query.filter_by(id=survey_id).first()
        if not survey:
            abort(404)
        session['last_page'] = '/surveys/{}'.format(str(survey_id))

        if survey.voted_users_id and str(
                session['user_id']) in survey.voted_users_id.split():
            user_voted = True
        else:
            user_voted = False
            if request.method == 'POST':
                if not auth.is_authorized():
                    return redirect('/login')

                chosen_ans = request.form['chosen-ans']
                if chosen_ans == 'да':
                    Surveys.plus_yes(survey)
                else:
                    Surveys.plus_no(survey)

                Surveys.vote_add(survey, session['user_id'])

                return redirect(session['last_page'])

        return render_template('survey.html',
                               title='Опрос',
                               survey=survey,
                               user_voted=user_voted)
Пример #3
0
 def news_list():
     if not auth.is_authorized():
         return redirect('/login')
     news_list = News.query.filter_by(user_id=auth.get_user().id)
     return render_template('news-list.html',
                            title="Новости",
                            news_list=news_list)
Пример #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 main_list():
        if not auth.is_authorized():
            return redirect('/login')
        character_list = Character.query.all()

        return render_template('main-list.html',
                               title='Персонажи',
                               character_list=character_list)
Пример #6
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')
Пример #7
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')
Пример #8
0
 def index():
     if not auth.is_authorized():
         return render_template(
             'index.html',
             title='Главная',
         )
     # ВОЗВРАЩАЕТ ГЛАВНУЮ СТРАНИЦУ ЧЕРЕЗ НОВУЮ ФУНКЦИЮ И НОВЫЙ ШАБЛОН
     return redirect('/main')
Пример #9
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)
Пример #10
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)
Пример #11
0
    def survey_checked(survey_id: int):
        if not auth.is_authorized():
            return redirect('/login')
        if session['username'] != 'admin':
            abort(403)

        survey = Surveys.query.filter_by(id=survey_id).first()
        Surveys.mark_as_checked(survey)

        return redirect(session['last_page'])
Пример #12
0
 def characters_list():
     if not auth.is_authorized():
         return redirect('/login')
     character_list = Character.query.filter_by(user_id=auth.get_user().id)
     messages = Post.query.filter_by(to=auth.get_user().username)
     return render_template(
         'character-list.html',
         title="Персонажи",
         character_list=character_list,
         messages=messages,
     )
Пример #13
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)
Пример #14
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)
Пример #15
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)
Пример #16
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)
Пример #17
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)
Пример #18
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)
Пример #19
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)
Пример #20
0
    def user_surveys():
        session['last_page'] = '/surveys'

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

        on_check_surveys = Surveys.query.filter_by(user_id=session['user_id'],
                                                   on_admin_check=True)
        hidden_surveys = Surveys.query.filter_by(
            user_id=session['user_id'],
            on_admin_check=False,
            publicity_check=False,
        )
        shown_surveys = Surveys.query.filter_by(user_id=session['user_id'],
                                                on_admin_check=False,
                                                publicity_check=True)
        surveys_on_check = Surveys.query.filter_by(on_admin_check=True)

        return render_template('my_surveys.html',
                               on_check_surveys=on_check_surveys,
                               hidden_surveys=hidden_surveys,
                               shown_surveys=shown_surveys,
                               surveys_on_check=surveys_on_check)
Пример #21
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)