def __init__(self, request): self.request = request self.auth = auth.Authenticator(self) try: if not self.request.body.strip(): self.body = None else: self.body = json.loads(self.request.body) except: abort('Request body must be JSON')
def require_entity(self, cls): user = self.get_current_user() if not user.is_worker(): abort(failure('Invalid credentials: must be a valid worker')) worker = cls.get_by_id(user.id) if worker is None: abort(failure('Invalid credentials: must be a valid worker')) return worker
def __init__(self, request): self.request = request self.auth = auth.Authenticator(self) try: if not self.request.body.strip(): self.body = None else: self.body = json.loads(self.request.body) except: abort("Request body must be JSON")
def get_or_abort(self, param): result = self.request.get(param, None) if result is None: abort('Required parameter \'%s\' is missing' % param) return result
def get_by_id_or_abort(cls, *args, **kwargs): res = cls.get_by_id(*args, **kwargs) if res is None: abort('%s not found' % cls.__name__) return res
def get_by_id_or_abort(cls, *args, **kwargs): res = cls.get_by_id(*args, **kwargs) if res is None: abort("%s not found" % cls.__name__) return res
def get_or_abort(self, param): result = self.request.get(param, None) if result is None: abort("Required parameter '%s' is missing" % param) return result