def accounts_create(): form = AccountForm(request.form) if not form.validate(): return render_template("accounts/account_form.html", form = form) account = Account.query.filter_by(username=form.username.data).first() if account: return render_template("accounts/account_form.html", form = form, error = "Username is taken, please select another one" ) account = Account( form.name.data, form.username.data, sha256_crypt.encrypt(form.password.data), form.email.data ) db.session.add(account) db.session.commit() return redirect(url_for("login"))
def accountgroup_new_account(accountgroup_id): accountform = AccountForm(request.form) print("Yritetään lisätä uutta tiliä ryhmään " + str(accountform.accountgroup_id.data)) if not accountform.validate(): return render_template( "accountgroups/list.html", action="FixNewAccount", targetgroup=accountgroup_id, targetaccount=-1, accountgroups=AccountGroup.findAllGroupsAndAccounts( current_user.get_entity_id()), newaccountgroupform=AccountGroupForm(), fixnewaccountform=accountform, newaccountform=AccountForm()) a = Account(accountform.number.data, accountform.name.data, accountform.description.data, accountform.inuse.data, accountgroup_id, current_user.get_entity_id()) try: db.session().add(a) db.session().commit() except: ## TÄHÄN VIRHETILANTEEN KÄSITTELY print("Tapahtui virhe lisätessä uutta tiliä tietokantaan") pass return redirect(url_for("accountgroups_index"))
def accountgroup_edit_account(account_id): print("Tehdään tilille jotain") editaccountform = AccountForm(request.form) print("id:", editaccountform.id.data) print("group_id:", editaccountform.accountgroup_id.data) if not editaccountform.validate(): print("Tilin validointi editoidessa ei onnistunut") return render_template( "accountgroups/list.html", action="EditAccount", targetgroup=editaccountform.accountgroup_id.data, targetaccount=account_id, accountgroups=AccountGroup.findAllGroupsAndAccounts( current_user.get_entity_id()), newaccountgroupform=AccountGroupForm(), newaccountform=AccountForm(), editaccountform=editaccountform) if "action_update" in request.form: print("Yritetään tallentaa") account = Account.query.filter( Account.entity_id == current_user.get_entity_id(), Account.id == account_id).first() account.name = editaccountform.name.data account.description = editaccountform.description.data account.inuse = editaccountform.inuse.data try: db.session().commit() except: ## TÄHÄN VIRHETILANTEEN KÄSITTELY pass elif "action_delete" in request.form: print("Yritetään poistaa") obsolete = Account.query.filter( Account.entity_id == current_user.get_entity_id(), Account.id == account_id).first() try: db.session().delete(obsolete) db.session.commit() except: ## TÄHÄN VIRHETILANTEEN KÄSITTELY pass return redirect(url_for("accountgroups_index"))