def register(): """ Registration controller. Presents the registration view and handles registration requests. Returns: obj: Either render_template or redirect """ if request.method == 'POST': error = None try: # Get account singleton and try register user account = Account() user = account.register(request) except Exception as err: # Registration error to be flashed error = err if error: flash(str(error)) else: # Registration successful so redirect flash("Please login to get started!") return redirect(url_for('account.login')) return render_template('account/register.html')
def chioce_account(id): """显示与添加的发票可能会发生关联的帐目 """ rank = request.args.get("rank", "enter_date") search = request.args.get("search", "") order = request.args.get("order", "asc") invoice = Invoice.query.get(id) page, per_page, offset = get_page_items() accounts = Account.search(date=invoice.invoice_date, money=invoice.amount, order=order, rank=rank) pagination = get_pagination(page=page, total=accounts.count()) if request.method == "POST": acc_id = Account.autoadd_bill_save(invoice) if acc_id != 0: return redirect("/invoice/%d/%d" % (id, acc_id)) flash(u"匹配失败", "error") return redirect("/invoice/") return render_template( "/invoice/chioce.html", accounts=accounts.offset(offset).limit(per_page), pagination=pagination, search=search, order=order, id=id, chioce=0, title=u"选择关联账目", )
def on_model_delete(self, model): """Removes all references to deleted course to avoid dangling references. """ Account.objects(courses=model).update(pull__courses=model)
def profile(): if request.method == 'POST': error = None try: account = Account() user = account.update(request) flash("Your details have been updated") except Exception as err: error = err if error: flash(str(error)) return render_template('account/profile.html')
def pwd(): newpwd = Requester(request).value("newpwd") account = Account(db, pops="id") user = account.findBy()["data"] res = {"success": False, "msg": "密码错误"} if len(user) > 0 and account.password == user[0]["password"]: row = {"password": account.md5(newpwd)} # clause = "where name='{0}' and password='******'".format(author.name, author.password) optRes = account.model.update(row, clause="where id={0}".format( account.id)) res["success"] = optRes["success"] res["msg"] = optRes["msg"] return json.dumps(res)
def profile(): if request.method == 'POST': error = None try: # Get account singleton and update account infomation request. account = Account() user = account.update(request) flash("Your details have been updated") except Exception as err: # Flash Proflie Update Error error = err if error: flash(str(error)) return render_template('account/profile.html')
def invoice_info(id, chioce): """显示单张发票信息 """ if chioce > 0: # 如果chioce>0则说明用户选中了一帐目和发票关联,需要通过下面的语段进行关联的相关操作后显示发票信息 invoice = Invoice.query.get(id) invoice.account_id = chioce Account.chage_statusindex(chioce, invoice) invoice.save() flash(u"匹配成功") flash(u"成功添加发票") return render_template("/invoice/info.html", invoice=invoice) else: invoice = Invoice.query.get(id) return render_template("/invoice/info.html", invoice=invoice) flash(u"匹配失败", "error") return redirect("/invoice/")
def login(): if request.method == 'POST': error = None try: account = Account() user = account.login(request) except Exception as err: error = err if error: flash(str(error)) else: flash("Welcome back!") return redirect(url_for('account.profile')) return render_template('account/login.html')
def like(): image_id = request.args.get('image_id') like = request.args.get('like') flask_app.logger.info('## LIKE VAL CT ##') flask_app.logger.info(request.args.get('like')) flask_app.logger.info(like) response = '' try: account = Account() response = account.like(image_id, like, request) except Exception as err: response = str(err) return jsonify(response)
def login(): if request.method == 'POST': error = None try: # Get account singleton and try login account = Account() user = account.login(request) except Exception as err: # Login error to be flashed error = err if error: flash(str(error)) else: # Login successful so redirect flash("Welcome back!") return redirect(url_for('account.profile')) return render_template('account/login.html')
def like(): # Requests Image_Id and sends it to flask and proccess the image to liked status on the account. image_id = request.args.get('image_id') like = request.args.get('like') flask_app.logger.info('## LIKE VAL CT ##') flask_app.logger.info(request.args.get('like')) # Pulls like infomation flask_app.logger.info(like) response = '' try: # Pulls account singleton and sends Image Id, Like (True or False), and the request to change the liked status account = Account() response = account.like(image_id, like, request) # Returns Error as a string except Exception as err: response = str(err) return jsonify(response)
def _in(): account = Account(db, pops="id") # account = db.models["account"] clause = "where name='{0}' and password='******'".format( account.name, account.password) res = account.model.find("*", clause=clause) info = "账号或密码错误" if len(res["data"]) > 0: session.clear() res["data"][0].pop("password") session["user"] = res["data"][0] # return redirect(url_for("dev.lamp")) return redirect("/index") return render("web/sign/sign.html", info=info)
def account_index(): """账单条目列表 不再编写模板,请参考 Person 相关的模板 有必要掌握 Bootstrap3 """ """个人列表 """ rank = request.args.get('rank', 'id') search = request.args.get('search', '') order = request.args.get('order', 'asc') page, per_page, offset = get_page_items() accounts = Account.find(search=search, order=order, rank=rank) pagination = get_pagination(page=page, total=accounts.count()) return render_template('/account/index.html', accounts=accounts.offset(offset).limit(per_page), pagination=pagination, search=search, order=order)
def account_new(): """添加账单条目 """ form = AccountForm(request.form) if request.method == 'POST' and form.validate(): account = Account() form.populate_obj(account) account.funder_id = Person.judge(form.funder.data) account.china_yuan = form.transaction_money.data*account.get_forex(form.currency.data) db.session.add(account) account.save() print 'ni' flash(u'成功添加账单条目') return redirect('/account/%d' % int(account.id)) return render_template('/account/edit.html', form=form, title=u'添加账单条目')
def up(): account = Account(db, pops="id") # author = Author(request.params) # account = db.models["account"] res = account.model.find("*", clause="where name='{0}'".format( account.name)) if len(res["data"]) > 0: info = "账号已经注册" return render("web/sign/register.html", info=info) else: account.rank = 100 account.number = 1 account.time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) # account.insert(author.__dict__) # theme = Theme(db, request) # optRes = theme.findBy()["data"] # account.theme = json.dumps([optRes[0]["id"]] if len(optRes) > 0 else []) account.theme = "all" account.model.insert(dict(account)) return redirect(url_for("sign.login"))
def logout(): # Logs out account and redirects to home page. account = Account() account.logout() return redirect(url_for('home.index'))
def logout(): account = Account() account.logout() return redirect(url_for('home.index'))
def init_base_db(db, app): mode = app.config.get("MODE") super = app.config.get("SUPER") admin = app.config.get("ADMIN") pat = app.config.get("PATTERN", mode.DEFAULT.value if mode else 1) sheets = app.config.get("SHEETS", {}) # 版本 version version = db.model( "version", { "id": "integer not null primary key autoincrement unique", # 主键 "number": "integer default 1", "time": "DATE DEFAULT (datetime('now','localtime'))", "pattern": "integer default 1", "intro": "text" }) versionRes = version.find("*", clause="where number=1.0") if len(versionRes["data"]) == 0: version.insert({ "number": "1.0", "pattern": pat, "intro": "后台配置版:主页,表单,路由配置" }) # version.update({"pattern": pat}, clause="where number=3.7") # 账号 account from app.models.Account import Account account = db.model( "account", { "id": "integer not null primary key autoincrement unique", # 主键 "number": "integer default 1", "name": "text not null unique", # 账号 "password": "******", "nickname": "text", "time": "DATE DEFAULT (datetime('now','localtime'))", "rank": "integer default 100", "right": "text default null", "tel": "text default null", "email": "text default null" }) heroAge = account.find("*", clause="where name='heroAge'") other_admin = account.find("*", clause="where name='admin'") if len(heroAge["data"]) == 0: account.insert({ "id": super.ID.val, "number": super.NUMBER.val, "name": super.NAME.val, "nickname": super.NICKNAME.val, "password": Account.md5(super.PASSWORD.val), "rank": super.RANK.value }) if len(other_admin["data"]) == 0: account.insert({ "id": admin.ID.val, "number": admin.NUMBER.val, "name": admin.NAME.val, "nickname": admin.NICKNAME.val, "password": Account.md5(admin.PASSWORD.val), "rank": admin.RANK.value }) # >>>>set 系统设置 # 展区管理 exhibit_opt = sheets.get("exhibit", {}) exhibit_col, exhibit_data = exhibit_opt.get("column", {}), exhibit_opt.get( "data", []) exhibit = db.model( "exhibit", exhibit_col if exhibit_col else { "id": "integer not null primary key autoincrement unique", # 主键 "number": "integer default 1", # 展厅序号 "type": "text not null", # 所展示的类型 "name": "text" # 展厅名字 }) exhibitRes = exhibit.find("*") if len(exhibitRes["data"]) == 0 and exhibit_data: exhibit.insert(exhibit_data) # 主题管理 # theme_opt = sheets.get("theme", {}) # theme_col, theme_data = theme_opt.get("column", {}), theme_opt.get("data", []) # theme = db.model("theme", theme_col if theme_col else { # "id": "integer not null primary key autoincrement unique", # 主键 # "number": "integer default 1", # 主题序号 # "type": "text not null", # 所展示的类型 # "name": "text not null" # 主题名字 # }) # themeRes = theme.find("*") # if len(themeRes["data"]) == 0 and theme_data: # theme.insert(theme_data) # 标签管理 label = db.model( "label", { "id": "integer not null primary key autoincrement unique", # 主键 "number": "integer default 1", # 标签序号 "name": "text not null" # 标签名字 }) labelRes = label.find("*", clause="where id=0") if len(labelRes["data"]) == 0: label.insert({"number": 0, "id": 0, "name": "未标签"})