def GetTaskList(self, request): limit = 10 if request.limit is not None: limit = request.limit curs = None if request.cursor is not None: try: curs = Cursor(urlsafe=request.cursor) except BadValueError: raise endpoints.BadRequestException('Invalid cursor %s.' % request.cursor) hQuery = None if request.timestamp is not None: hQuery = Task.query(Task.last_updated <= request.timestamp, Task.user == self.GetUserId()) else: hQuery = Task.query(Task.user == self.GetUserId()) if (curs is not None): tasks, next_curs, more = hQuery.fetch_page(limit, start_cursor=curs) else: tasks, next_curs, more = hQuery.fetch_page(limit) items = [entity.ConvertToResponse() for entity in tasks] if more: return TaskListResponse(task_list=items, cursor=next_curs.urlsafe(), has_more=more) else: return TaskListResponse(task_list=items, has_more=more)
def DeleteUser(self, request): '''API method to delete current user and all his data''' categories = Category.query(Category.user == self.GetUserId()).fetch() for category in categories: category.key.delete() tasks = Task.query(Task.user == self.GetUserId()).fetch() for task in tasks: task.key.delete() user = User.query(User.username == endpoints.get_current_user().email()).get() user.key.delete() return message_types.VoidMessage()
def DeleteCategory(self, request): result = CategoryResponse() category = Category.get_by_id(request.id) if category != None: if Task.query(Task.category == category.key).get() == None: if category.last_updated <= request.client_copy_timestamp and category.user == self.GetUserId(): category.key.delete() result = category.ConvertToResponse() else: raise endpoints.NotFoundException("The item was updated on the outside") else: raise endpoints.NotFoundException("This item has child elements") else: raise endpoints.NotFoundException('No category entity with the id "%s" exists.' % request.id) return result