def edit_news(id): global admin form = NewsForm() if request.method == "GET": session = db_session.create_session() if admin == "да": news = session.query(News).filter(News.id == id).first() else: news = session.query(News).filter( News.id == id, News.user == current_user).first() if news: form.title.data = news.title form.content.data = news.content form.is_private.data = news.is_private else: abort(404) if form.validate_on_submit(): session = db_session.create_session() if admin == "да": news = session.query(News).filter(News.id == id).first() else: news = session.query(News).filter( News.id == id, News.user == current_user).first() if news: news.title = form.title.data news.content = form.content.data news.is_private = form.is_private.data session.commit() return redirect('/') else: abort(404) return render_template('news.html', title='Редактирование новости', form=form)
def add_news(): form = NewsForm() if form.validate_on_submit(): session = db_session.create_session() news = News() news.title = form.title.data news.content = form.content.data news.is_private = form.is_private.data current_user.news.append(news) session.merge(current_user) session.commit() return redirect('/') return render_template('news.html', title='Добавление новости', form=form)
def add_news(): form = NewsForm() if form.validate_on_submit(): session = db_session.create_session() news = News() news.text = form.title.data news.team_lead = form.teamlead_id.data news.work_size = form.work_size.data news.collaborators = form.collaborators.data session = db_session.create_session() session.add(news) session.commit() return redirect('/') return render_template('news.html', title='Добавление новости', form=form)
def edit_news(id): form = NewsForm() session = db_session.create_session() news = session.query(News).filter(News.id == id, News.team_lead == global_user.id).first() if request.method == "GET": if news: form.title.data = news.text form.teamlead_id.data = news.team_lead form.work_size.data = news.work_size form.collaborators.data = news.collaborators if form.validate_on_submit(): news.text = form.title.data news.team_lead = form.teamlead_id.data news.work_size = form.work_size.data news.collaborators = form.collaborators.data session.commit() return redirect('/') return render_template('news.html', title='Редактирование новости', form=form)
def add_news(): form = NewsForm() if request.method == "GET": return render_template("add_news.html", title="Добавление новости", form=form) elif request.method == "POST": session = db_session.create_session() news = News() news.title = request.form.get("title") news.theme = request.form.get("theme") news.content = request.form.get("content") news.user_id = current_user.id private = request.form.get("private") news.is_private = 0 if private is None else 1 session.add(news) session.commit() return redirect("/")
def edit_news(id): form = NewsForm() if request.method == "GET": session = db_session.create_session() news = session.query(News).filter(News.id == id, News.user == current_user).first() if news: form.title = news.title form.theme = news.theme form.content = news.content form.is_private = news.is_private if form.validate_on_submit(): session = db_session.create_session() news = session.query(News).filter(News.id == id, News.user == current_user).first() if news: news.title = request.form.get("title") news.theme = request.form.get("theme") news.content = request.form.get("content") private = request.form.get("private") news.is_private = 0 if private is None else 1 session.commit() return redirect("/") return render_template("news_edit.html", title="Редактирование новости", form=form)