Esempio n. 1
0
 def post(self):
     with STATS.add_account.time():
         # create a new account
         form = AccountForm(request.data)
         if form.validate():
             acct = Account(
                 form.name.data,
                 form.acct_type,
                 form.description.data
             )
             db.session.add(acct)
             db.session.commit()
             STATS.success += 1
             return jsonify({
                 'message': 'Successfully added Account',
                 'account_id': acct.account_id
             })
         STATS.validation += 1
         resp = jsonify({"errors": form.errors})
         resp.status_code = 400
         return resp
Esempio n. 2
0
 def put(self, account_id):
     with STATS.update_account.time():
         # update a single account
         acct = Account.query.get(account_id)
         if acct is None:
             STATS.notfound += 1
             return abort(404)
         form = AccountForm(request.data)
         if form.validate():
             acct = Account.query.get(account_id)
             acct.name = form.name.data
             acct.account_type_id = form.account_type_id.data
             acct.description = form.description.data
             db.session.add(acct)
             db.session.commit()
             STATS.success += 1
             return jsonify({
                 'message': 'Successfully updated Account'
             })
         STATS.validation += 1
         resp = jsonify({'errors': form.errors})
         resp.status_code = 400
         return resp