def fn_get_reverse_relationship(_id): """Returns either a listing of the reverse relationship or the data itself, depending on the linkage parameter. """ if request.method == "OPTIONS": return response_doc = JsonAPIResponse(request.url) if target.via: query = target.target.select().join( target.via).where(reverse_field == _id) else: query = target.target.select().where(reverse_field == _id) for entry in query: data, included = self.__entry_to_resource( entry, include=request.query.include.split(","), fields=util.parse_fields_parameter(), linkage=linkage) response_doc.data.append(data) response_doc.included += included return json.dumps(dict(response_doc), sort_keys=True)
def fn_get_relationship(_id): """Returns either a listing of the relationship or the data itself depending on the linkage parameter. """ if request.method == "OPTIONS": return response_doc = JsonAPIResponse(request.url) entry = self.model.select().where( self.model._meta.primary_key == _id).get() relation = getattr(entry, relationship) # non existant relationships must return successful with data: null data, included = self.__entry_to_resource( relation, include=request.query.include.split(","), fields=util.parse_fields_parameter(), linkage=linkage) if relation else (None, []) response_doc.data = data response_doc.included = included return json.dumps(dict(response_doc), sort_keys=True)
def fn_get_reverse_relationship(_id): """Returns either a listing of the reverse relationship or the data itself, depending on the linkage parameter. """ if request.method == "OPTIONS": return response_doc = JsonAPIResponse(request.url) if target.via: query = target.target.select().join(target.via).where( reverse_field == _id ) else: query = target.target.select().where(reverse_field == _id) for entry in query: data, included = self.__entry_to_resource( entry, include=request.query.include.split(","), fields=util.parse_fields_parameter(), linkage=linkage ) response_doc.data.append(data) response_doc.included += included return json.dumps(dict(response_doc), sort_keys=True)
def fn_get_relationship(_id): """Returns either a listing of the relationship or the data itself depending on the linkage parameter. """ if request.method == "OPTIONS": return response_doc = JsonAPIResponse(request.url) entry = self.model.select().where( self.model._meta.primary_key == _id ).get() relation = getattr(entry, relationship) # non existant relationships must return successful with data: null data, included = self.__entry_to_resource( relation, include=request.query.include.split(","), fields=util.parse_fields_parameter(), linkage=linkage ) if relation else (None, []) response_doc.data = data response_doc.included = included return json.dumps(dict(response_doc), sort_keys=True)
def __get(self, _id): """Retrieves a singlar resource by its ID.""" response_doc = JsonAPIResponse(request.url) entry = self.model.select().where( self.model._meta.primary_key == _id).get() data, included = self.__entry_to_resource( entry, include=request.query.include.split(","), fields=util.parse_fields_parameter()) response_doc.data = data response_doc.included = included return json.dumps(dict(response_doc), sort_keys=True)
def __get(self, _id): """Retrieves a singlar resource by its ID.""" response_doc = JsonAPIResponse(request.url) entry = self.model.select().where( self.model._meta.primary_key == _id ).get() data, included = self.__entry_to_resource( entry, include=request.query.include.split(","), fields=util.parse_fields_parameter() ) response_doc.data = data response_doc.included = included return json.dumps(dict(response_doc), sort_keys=True)
def fn_list(): """Returns a listing of resources.""" if request.method == "OPTIONS": return self.listener.before_list() response_doc = JsonAPIResponse(request.url) for entry in self.model.select(): data, included = self.__entry_to_resource( entry, include=request.query.include.split(","), fields=util.parse_fields_parameter()) response_doc.data.append(data) response_doc.included += included self.listener.after_list(response_doc) return json.dumps(dict(response_doc), sort_keys=True)
def fn_list(): """Returns a listing of resources.""" if request.method == "OPTIONS": return self.listener.before_list() response_doc = JsonAPIResponse(request.url) for entry in self.model.select(): data, included = self.__entry_to_resource( entry, include=request.query.include.split(","), fields=util.parse_fields_parameter() ) response_doc.data.append(data) response_doc.included += included self.listener.after_list(response_doc) return json.dumps(dict(response_doc), sort_keys=True)