def _api_PUSHES(self): """Returns a JSON representation of pushes.""" rpp = util.get_int_arg(self.request, 'rpp', 50) offset = util.get_int_arg(self.request, 'offset', 0) state = util.get_str_arg(self.request, 'state', '') user = util.get_str_arg(self.request, 'user', '') filters = [] if state != '': filters.append(db.push_pushes.c.state == state) if user != '': filters.append(db.push_pushes.c.user == user) push_query = db.push_pushes.select( whereclause=SA.and_(*filters), order_by=db.push_pushes.c.modified.desc(), ) pushes_count = push_query.alias('pushes_count').count() if offset > 0: push_query = push_query.offset(offset) if rpp > 0: push_query = push_query.limit(rpp) db.execute_transaction_cb([ push_query, pushes_count, ], self._on_PUSHES_db_response)
def _api_PUSHES(self): """Returns a JSON representation of pushes.""" rpp = util.get_int_arg(self.request, 'rpp', 50) offset = util.get_int_arg(self.request, 'offset', 0) state = util.get_str_arg(self.request, 'state', '') user = util.get_str_arg(self.request, 'user', '') filters = [] if state != '': filters.append(db.push_pushes.c.state == state) if user != '': filters.append(db.push_pushes.c.user == user) push_query = db.push_pushes.select( whereclause=SA.and_(*filters), order_by=db.push_pushes.c.modified.desc(), ) pushes_count = push_query.alias('pushes_count').count() if offset > 0: push_query = push_query.offset(offset) if rpp > 0: push_query = push_query.limit(rpp) db.execute_transaction_cb([push_query, pushes_count, ], self._on_PUSHES_db_response)
def _api_PUSH(self): """Returns a JSON representation of a push.""" push_id = util.get_int_arg(self.request, 'id') if not push_id: return self.send_error(404) query = db.push_pushes.select(db.push_pushes.c.id == push_id) db.execute_cb(query, self._on_PUSH_db_response)
def _api_REQUEST(self): """Returns a JSON representation of a push request.""" request_id = util.get_int_arg(self.request, 'id') if not request_id: return self.send_error(404) query = db.push_requests.select(db.push_requests.c.id == request_id) db.execute_cb(query, self._on_REQUEST_db_response)
def _api_PUSHCONTENTS(self): """Returns a set of JSON representations of requests in a given push.""" push_id = util.get_int_arg(self.request, 'id') if not push_id: return self.send_error(404) query = db.push_requests.select(SA.and_( db.push_requests.c.id == db.push_pushcontents.c.request, db.push_pushcontents.c.push == push_id, )) db.execute_cb(query, self._on_PUSHCONTENTS_db_response)
def _api_PUSHBYREQUEST(self): """Returns a JSON representation of a PUSH given a request id.""" request_id = util.get_int_arg(self.request, 'id') if not request_id: return self.send_error(404) query = db.push_pushes.select(SA.and_( db.push_pushes.c.state != "discarded", db.push_pushcontents.c.push == db.push_pushes.c.id, db.push_pushcontents.c.request == request_id, )) db.execute_cb(query, self._on_PUSHBYREQUEST_db_response)
def _api_PUSHCONTENTS(self): """Returns a set of JSON representations of requests in a given push.""" push_id = util.get_int_arg(self.request, 'id') if not push_id: return self.send_error(404) query = db.push_requests.select( SA.and_( db.push_requests.c.id == db.push_pushcontents.c.request, db.push_pushcontents.c.push == push_id, )) db.execute_cb(query, self._on_PUSHCONTENTS_db_response)
def _api_PUSHBYREQUEST(self): """Returns a JSON representation of a PUSH given a request id.""" request_id = util.get_int_arg(self.request, 'id') if not request_id: return self.send_error(404) query = db.push_pushes.select( SA.and_( db.push_pushes.c.state != "discarded", db.push_pushcontents.c.push == db.push_pushes.c.id, db.push_pushcontents.c.request == request_id, )) db.execute_cb(query, self._on_PUSHBYREQUEST_db_response)
def _api_PUSHITEMS(self): """Returns a JSON representation of a list of requests given a push id""" push_id = util.get_int_arg(self.request, 'push_id') if not push_id: return self.send_error(404) query = db.push_requests.select( SA.and_( db.push_requests.c.id == db.push_pushcontents.c.request, db.push_requests.c.state != 'pickme', db.push_pushcontents.c.push == push_id, ), order_by=(db.push_requests.c.user, db.push_requests.c.title), ) db.execute_cb(query, self._on_PUSHITEMS_db_response)
def _api_PUSHDATA(self): """Returns all the information on a push in JSON. This is the same data that is shown on the push page""" push_id = util.get_int_arg(self.request, 'id') if not push_id: return self.send_error(404) push_info_query = db.push_pushes.select(db.push_pushes.c.id == push_id) contents_query = db.push_requests.select( SA.and_( db.push_requests.c.id == db.push_pushcontents.c.request, db.push_pushcontents.c.push == push_id, ), order_by=(db.push_requests.c.user, db.push_requests.c.title), ) available_query = db.push_requests.select( db.push_requests.c.state == 'requested', ) db.execute_transaction_cb([push_info_query, contents_query, available_query], self._on_PUSHDATA_db_response)
def _api_PUSHDATA(self): """Returns all the information on a push in JSON. This is the same data that is shown on the push page""" push_id = util.get_int_arg(self.request, 'id') if not push_id: return self.send_error(404) push_info_query = db.push_pushes.select(db.push_pushes.c.id == push_id) contents_query = db.push_requests.select( SA.and_( db.push_requests.c.id == db.push_pushcontents.c.request, db.push_pushcontents.c.push == push_id, ), order_by=(db.push_requests.c.user, db.push_requests.c.title), ) available_query = db.push_requests.select( db.push_requests.c.state == 'requested', ) db.execute_transaction_cb( [push_info_query, contents_query, available_query], self._on_PUSHDATA_db_response)
def _api_REQUESTSEARCH(self): """Returns a list of requests matching a the specified filter(s).""" filters = [] # Tag constraint for tag in self.request.arguments.get('tag', []): filters.append(db.push_requests.c.tags.op('regexp')('[[:<:]]' + tag + '[[:>:]]')) # Timestamp constraint mbefore = util.get_int_arg(self.request, 'mbefore') mafter = util.get_int_arg(self.request, 'mafter') if mbefore: filters.append(db.push_requests.c.modified < mbefore) if mafter: filters.append(db.push_requests.c.modified > mafter) cbefore = util.get_int_arg(self.request, 'cbefore') cafter = util.get_int_arg(self.request, 'cafter') if cbefore: filters.append(db.push_requests.c.created < cbefore) if cafter: filters.append(db.push_requests.c.created > cafter) # State constraint states = self.request.arguments.get('state', []) if states: filters.append(db.push_requests.c.state.in_(states)) # User constraint users = self.request.arguments.get('user', []) if users: filters.append(db.push_requests.c.user.in_(users)) # Repository constraint repos = self.request.arguments.get('repo', []) if repos: filters.append(db.push_requests.c.repo.in_(repos)) # Branch constraint branches = self.request.arguments.get('branch', []) if branches: filters.append(db.push_requests.c.branch.in_(branches)) # Revision constraint revisions = self.request.arguments.get('rev', []) if revisions: filters.append(db.push_requests.c.revision.in_(revisions)) # Review constraint reviews = self.request.arguments.get('review', []) if reviews: filters.append(db.push_requests.c.reviewid.in_(reviews)) # Title constraint for title in self.request.arguments.get('title', []): filters.append(db.push_requests.c.title.like('%' + title + '%')) # Only allow searches with at least one constraint (to avoid # accidental dumps of the entire table) if not filters: return self.send_error(409) query = db.push_requests.select(SA.and_(*filters)) query = query.order_by(db.push_requests.c.id.desc()) limit = util.get_int_arg(self.request, 'limit') if limit > 0: limit = max(min(1000, limit), 1) query = query.limit(limit) db.execute_cb(query, self._on_REQUESTSEARCH_db_response)
def _api_REQUESTSEARCH(self): """Returns a list of requests matching a the specified filter(s).""" filters = [] # Tag constraint for tag in self.request.arguments.get('tag', []): filters.append( db.push_requests.c.tags.op('regexp')('[[:<:]]' + tag + '[[:>:]]')) # Timestamp constraint mbefore = util.get_int_arg(self.request, 'mbefore') mafter = util.get_int_arg(self.request, 'mafter') if mbefore: filters.append(db.push_requests.c.modified < mbefore) if mafter: filters.append(db.push_requests.c.modified > mafter) cbefore = util.get_int_arg(self.request, 'cbefore') cafter = util.get_int_arg(self.request, 'cafter') if cbefore: filters.append(db.push_requests.c.created < cbefore) if cafter: filters.append(db.push_requests.c.created > cafter) # State constraint states = self.request.arguments.get('state', []) if states: filters.append(db.push_requests.c.state.in_(states)) # User constraint users = self.request.arguments.get('user', []) if users: filters.append(db.push_requests.c.user.in_(users)) # Repository constraint repos = self.request.arguments.get('repo', []) if repos: filters.append(db.push_requests.c.repo.in_(repos)) # Branch constraint branches = self.request.arguments.get('branch', []) if branches: filters.append(db.push_requests.c.branch.in_(branches)) # Revision constraint revisions = self.request.arguments.get('rev', []) if revisions: filters.append(db.push_requests.c.revision.in_(revisions)) # Review constraint reviews = self.request.arguments.get('review', []) if reviews: filters.append(db.push_requests.c.reviewid.in_(reviews)) # Title constraint for title in self.request.arguments.get('title', []): filters.append(db.push_requests.c.title.like('%' + title + '%')) # Only allow searches with at least one constraint (to avoid # accidental dumps of the entire table) if not filters: return self.send_error(409) query = db.push_requests.select(SA.and_(*filters)) query = query.order_by(db.push_requests.c.id.desc()) limit = util.get_int_arg(self.request, 'limit') if limit > 0: limit = max(min(1000, limit), 1) query = query.limit(limit) db.execute_cb(query, self._on_REQUESTSEARCH_db_response)