def edit_about(): model = About.query.get(1) if model is None: model = About() db.session.add(model) setattr(model, request.form['component'], request.form['content']) return commitAndJsonify()
def admin(): """ This renders the admin page. It is only available to admin users. """ user_check() about = About.query.filter_by().first() form = EditAboutForm() if form.validate_on_submit(): if about: print(about.body) about.body = form.body.data about.en_body = form.en_body.data else: about = About(body=form.body.data, en_body=form.en_body.data) db.session.add(about) db.session.commit() flash(_('Your changes have been saved.')) return redirect(url_for('admin.admin')) elif request.method == 'GET': if about: form.body.data = about.body form.en_body.data = about.en_body return render_template( 'admin/admin.html', title='Admin', form=form, about=about, products=Product.query.all(), items=session['items'], total_products=session['total_products'], total=session['total'], )
def test_about_edit_description(self): db.session.add(About(description="d", quote="q", quotee="qe")) db.session.commit() self.app.post('/update/about/details', data=dict(component="description", content="diefine")) self.assertEqual(About.query.get(1).description, "diefine")
def test_about_model_details_appear_in_view(self): a = About(description="about me!", quote="awesome quote", quotee="coolguy") db.session.add(a) db.session.commit() response = self.app.get('/about/') self.assertIn(b'about me!', response.data) self.assertIn(b'awesome quote', response.data) self.assertIn(b'coolguy', response.data)
def manageabout(): if current_user.is_authenticated: createform = AboutCreateForm() results = About.query.order_by(About.id).all() editform = AboutEditForm() return render_template('manageabout.html', title='Manage About', createform=createform, editform=editform, items=results) if createform.validate_on_submit(): about = About(body=createform.body.data, author=current_user) db.session.add(about) db.session.commit() flash('Posted') return redirect(url_for('manageabout')) else: return redirect(url_for('index'))
def about_add(): form = AboutForm() if form.validate_on_submit(): data = form.data about = About.query.filter_by(name=data["name"]).count() if about == 1: flash("名称已经存在!", "err") return redirect(url_for('admin.about_add')) about = About(name=data["name"], info=data["info"], info_en=data["info_en"], is_enable=0) db.session.add(about) db.session.commit() flash("添加成功!", "ok") oplog = Oplog(admin_id=session["admin_id"], ip=request.remote_addr, reason="关于添加:{}".format(data["name"], )) db.session.add(oplog) db.session.commit() return redirect(url_for("admin.about_add")) return render_template("admin/about_add.html", form=form)