def RenderAjax(self, request, response): """Return the count on unseen notifications.""" response = super(NotificationCount, self).RenderAjax(request, response) number = 0 try: user_fd = aff4.FACTORY.Open(aff4.ROOT_URN.Add("users").Add( request.user), token=request.token) notifications = user_fd.Get(user_fd.Schema.PENDING_NOTIFICATIONS) if notifications: number = len(notifications) except IOError: pass return renderers.JsonResponse(dict(number=number))
def RenderAjax(self, request, response): """Continue polling as long as the flow is in flight.""" super(UpdateAttribute, self).RenderAjax(request, response) self.ParseRequest(request) # Check if the flow is still in flight. try: flow_obj = aff4.FACTORY.Open(self.flow_urn, token=request.token) complete = not flow_obj.GetRunner().IsRunning() except IOError: # Something went wrong, stop polling. complete = True if complete: return renderers.JsonResponse("1")
def RenderAjax(self, request, response): """Return the contents of the hex viewer in JSON.""" try: row_count = int(request.REQ.get("hex_row_count", 10)) except ValueError: row_count = 2 try: offset = int(request.REQ.get("offset", 0)) except ValueError: offset = 0 data = [ ord(x) for x in self.ReadBuffer(request, offset, row_count * self.table_width) ] response = dict(offset=offset, values=data) response["total_size"] = self.total_size return renderers.JsonResponse( dict(offset=offset, values=data, total_size=self.total_size))