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)
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)
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)
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')
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)
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')
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')
def index(): if not auth.is_authorized(): return render_template( 'index.html', title='Главная', ) # ВОЗВРАЩАЕТ ГЛАВНУЮ СТРАНИЦУ ЧЕРЕЗ НОВУЮ ФУНКЦИЮ И НОВЫЙ ШАБЛОН return redirect('/main')
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)
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)
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'])
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, )
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)
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)
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)
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)
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)
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)
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)
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)
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)