def patch(self, task_uuid): ''' Modify task ''' logging.info('request.arguments {0}'.format(self.request.arguments)) logging.info('request.body {0}'.format(self.request.body)) struct = yield check_json(self.request.body) logging.info('patch received struct {0}'.format(struct)) format_pass = (True if not dict(struct).get('errors', False) else False) if not format_pass: self.set_status(400) self.finish({'JSON':format_pass}) return account = self.request.arguments.get('account', [None])[0] logging.info('account {0} uuid {1} struct {2}'.format(account, task_uuid, struct)) result = yield self.modify_task(account, task_uuid, struct) if not result: self.set_status(400) system_error = errors.Error('missing') error = system_error.missing('task', task_uuid) self.finish(error) return self.set_status(200) self.finish({'message': 'update completed successfully'})
def delete(self, account): ''' Delete organization account ''' org = account.rstrip('/') # for each member in members remove member. members = yield self.get_members(org) members = (members['members'] if members['members'] else False) # clean this hack for user in members: rmx = yield self.remove_member(org, user) # check_member = yield self.remove_member(org_id, current_user) result = yield self.remove_account(org) # again with the result['n'] stuff... what is this shit? logging.info('check for n stuff %s' % (result)) if not result['n']: self.set_status(400) system_error = errors.Error('missing') error = system_error.missing('org', org) self.finish(error) return self.set_status(204) self.finish()
def check_json(struct): ''' Check for malformed JSON ''' try: struct = json.loads(struct) except Exception, e: api_error = errors.Error(e) error = api_error.json() logging.exception(e) raise gen.Return(error) return
def delete(self, record_uuid): ''' Delete records handler ''' record_uuid = record_uuid.rstrip('/') result = yield self.remove_record(record_uuid) if not result['n']: self.set_status(400) system_error = errors.Error('missing') error = system_error.missing('record', record_uuid) self.finish(error) return self.set_status(204) self.finish()
def delete(self, task_uuid): ''' Delete tasks handler ''' task_uuid = task_uuid.rstrip('/') result = yield self.remove_task(task_uuid) if not result['n']: self.set_status(400) system_error = errors.Error('missing') error = system_error.missing('task', task_uuid) self.finish(error) return self.set_status(204) self.finish()
def delete(self, account): ''' Delete a user account ''' account = account.rstrip('/') result = yield self.remove_account(account) logging.info("why result['n'] ? %s" % str(result)) if not result['n']: self.set_status(400) system_error = errors.Error('missing') error = system_error.missing('user', account) self.finish(error) return self.set_status(204) self.finish()
def let_it_crash(self, struct, scheme, error, reason): ''' Let it crash ''' str_error = str(error) error_handler = errors.Error(error) messages = [] if error and 'Model' in str_error: message = error_handler.model(scheme) elif error and 'duplicate' in str_error: for name, value in reason.get('duplicates'): if value in str_error: message = error_handler.duplicate(name.title(), value, struct.get(value)) messages.append(message) message = ({'messages': messages} if messages else False) elif error and 'value' in str_error: message = error_handler.value() elif error is not None: logging.warning(str_error) logging.error(struct, scheme, error, reason) message = {'error': u'nonsense', 'message': u'there is no error'} else: quotes = PeopleQuotes() message = {'status': 200, 'message': quotes.get()} raise gen.Return(message)
def get(self, record_uuid=None, start=None, end=None, page_num=0, lapse='hours'): ''' Get records handler ''' logging.info('Get records handler') # -- logging info logging.info(self.request.arguments) #account = (self.request.arguments.get('account', [None])[0] if not account else account) # query string checked from string to boolean #checked = str2bool(str(self.request.arguments.get('checked', [False])[0])) if record_uuid: record_uuid = record_uuid.rstrip('/') if self.current_user: user = self.current_user record = yield self.get_record(user, record_uuid) else: record = yield self.get_record(None, record_uuid) if not record: self.set_status(400) system_error = errors.Error('missing') error = system_error.missing('record', record_uuid) self.finish(error) return self.finish(record) return if self.current_user: user = self.current_user orgs = yield self.get_orgs_list(user) account_list = (orgs['orgs'] if orgs else False) if not account_list: result = yield self.get_record_list( account=user, lapse=lapse, start=start, end=end, page_num=page_num) else: account_list.append(user) result = yield self.get_record_list( account=account_list, lapse=lapse, start=start, end=end, page_num=page_num) else: result = yield self.get_record_list( account=None, lapse=lapse, start=start, end=end, page_num=page_num) result = json_util.dumps(result) self.finish(result)
def get(self, task_uuid=None, start=None, end=None, page_num=0, lapse='hours'): ''' Get tasks handler ''' # -- logging info logging.warning('daaaa fuck1!!{0}'.format(task_uuid)) logging.info(self.request.arguments) #account = (self.request.arguments.get('account', [None])[0] if not account else account) # query string checked from string to boolean #checked = str2bool(str(self.request.arguments.get('checked', [False])[0])) if task_uuid: task_uuid = task_uuid.rstrip('/') if self.current_user: user = self.current_user task = yield self.get_task(user, task_uuid) else: task = yield self.get_task(None, task_uuid) if not task: self.set_status(400) system_error = errors.Error('missing') error = system_error.missing('task', task_uuid) self.finish(error) return self.finish(clean_structure(task)) return if self.current_user: user = self.current_user orgs = yield self.get_orgs_list(user) account_list = (orgs['orgs'] if orgs else False) if not account_list: result = yield self.get_task_list( account=user, lapse=lapse, start=start, end=end, page_num=page_num) else: account_list.append(user) result = yield self.get_task_list( account=account_list, lapse=lapse, start=start, end=end, page_num=page_num) else: result = yield self.get_task_list( account=None, lapse=lapse, start=start, end=end, page_num=page_num) result = json_util.dumps(result) self.finish(result)