def post(self):
        request = get_post_json(self.request)
        if (not request):
            return self.finish({
                'code': RESP['ERROR']['CODE'],
                'msg': RESP['ERROR']['MSG']
            })
        account = Account.get_by_pk(request['id'])
        account.edit(request)
        old_asks = AccountAsk.get_by_account(account)

        update_asks_id = []
        times = 0
        for new_ask in request['asks']:
            try:
                account_ask = AccountAsk.get_by_ask(account, new_ask['ask'])
                account_ask.edit(new_ask)
                update_asks_id.append(new_ask['id'])
            except DoesNotExist:
                new_ask['account'] = account
                pass_ask = AccountAsk.new(new_ask)
                update_asks_id.append(pass_ask.id)
        for old_ask in old_asks:
            if not old_ask.id in update_asks_id:
                old_ask.remove()

        return self.finish({
            'code': RESP['SUCCESS']['CODE'],
            'msg': RESP['SUCCESS']['MSG']
        })
 def get(self):
     account_id = self.get_argument('id', '')
     account = Account.get_by_pk(account_id)
     if not account:
         return self.finish({
             'code': RESP['ERROR']['CODE'],
             'msg': RESP['ERROR']['MSG']
         })
     AccountAsk.remove_by_account(account)
     account.remove()
     return self.finish({
         'code': RESP['SUCCESS']['CODE'],
         'msg': RESP['SUCCESS']['MSG']
     })