def dispatch(self, request, *args, **kwargs): response = StreamingHttpResponse(self._queue(), mimetype='text/event-stream') response['Cache-Control'] = 'no-cache' response['Software'] = 'opps-liveblogging' response.flush() return response
def dispatch(self, request, *args, **kwargs): response = StreamingHttpResponse(self._queue(), mimetype='text/event-stream') response['Cache-Control'] = 'no-cache' response['Software'] = 'opps-liveblogging' response['Access-Control-Allow-Origin'] = '*' response.flush() return response
def dispatch(self, request, *args, **kwargs): self.slug = self.kwargs.get('slug') self.event_obj = self.model.objects.get( channel_long_slug=self.get_long_slug(), slug=self.slug) response = StreamingHttpResponse(self._queue(), mimetype='text/event-stream') response['Cache-Control'] = 'no-cache' response['Software'] = 'opps-liveblogging' response['Access-Control-Allow-Origin'] = '*' response.flush() return response
def dispatch(self, request, *args, **kwargs): self.slug = self.kwargs.get('slug') self.event_obj = self.model.objects.get( channel_long_slug=self.get_long_slug(), slug=self.slug) response = StreamingHttpResponse(self._queue(), mimetype='text/event-stream') response['Cache-Control'] = 'no-cache' response['Software'] = 'opps-liveblogging' response['Access-Control-Allow-Origin'] = '*' response.flush() return response
def match(request, match_pk, mode='response'): """ :mode: response - Django response JSON json - Dumped JSON object python - Pure Python Dictionary """ data = data_match(match_pk) def _json_response(): try: response = JSONPResponse( data, {}, response_mimetype(request), request.GET['callback']) except: response = JSONResponse(data, {}, response_mimetype(request)) return response if mode == 'response': response = _json_response() response['Content-Disposition'] = 'inline; filename=files.json' elif mode == 'sse': def _sse_queue(): redis = Db('goalservematch', match_pk) pubsub = redis.object().pubsub() pubsub.subscribe(redis.key) while True: for m in pubsub.listen(): if m['type'] == 'message': data = m['data'].decode('utf-8') yield u"data: {}\n\n".format(data) yield time.sleep(0.5) response = StreamingHttpResponse(_sse_queue(), mimetype='text/event-stream') response['Cache-Control'] = 'no-cache' response['Software'] = 'opps-goalserve' response.flush() elif mode == 'json': response = _json_response() elif mode == 'python': response = data else: response = \ "Please specify the mode argument as python, json or response" return response