cls_data = self.table_cls.from_dict(data)
return cls_data.format_http()
- @check.authenticate
+ @web.asynchronous
+ @gen.coroutine
+ @check.is_authorized
+ @check.valid_token
@check.no_body
@check.miss_fields
@check.carriers_exist
pipelines.append({'$match': query})
total_pages = 0
- if page > 0:
- cursor = dbapi.db_list(self.table, query)
- records_count = yield cursor.count()
- total_pages, return_nr = self._calc_total_pages(records_count,
- last,
- page,
- per_page)
- pipelines = self._set_pipelines(pipelines,
- sort,
- return_nr,
- page,
- per_page)
- cursor = dbapi.db_aggregate(self.table, pipelines)
data = list()
- while (yield cursor.fetch_next):
- data.append(self.format_data(cursor.next_object()))
+ cursor = dbapi.db_list(self.table, query)
+ records_count = yield cursor.count()
+ if records_count > 0:
+ if page > 0:
+ total_pages, return_nr = self._calc_total_pages(records_count,
+ last,
+ page,
+ per_page)
+ pipelines = self._set_pipelines(pipelines,
+ sort,
+ return_nr,
+ page,
+ per_page)
+ cursor = dbapi.db_aggregate(self.table, pipelines)
+ while (yield cursor.fetch_next):
+ data.append(self.format_data(cursor.next_object()))
if res_op is None:
res = {self.table: data}
else:
def _get_one(self, data, query=None):
self.finish_request(self.format_data(data))
- @check.authenticate
+ @web.asynchronous
+ @gen.coroutine
@check.not_exist
def _delete(self, data, query=None):
yield dbapi.db_delete(self.table, query)
self.finish_request()
- @check.authenticate
+ @web.asynchronous
+ @gen.coroutine
@check.no_body
@check.not_exist
@check.updated_one_not_exist
update_req['_id'] = str(data._id)
self.finish_request(update_req)
- @check.authenticate
+ @web.asynchronous
+ @gen.coroutine
@check.no_body
@check.not_exist
@check.updated_one_not_exist