def post(self, operation): if operation == "add": event = Event() event.type = self.request.get("type") event.source = re.sub("\n", " ", self.request.get("source")) event.message = self.request.get("message") event.owner = self.request.get("owner") db.put(event) self.response.set_status(200) self.response.out.write("OK")
def make_event(self, entry): event = Event() event.type = self.type event.title = entry.title event.uid = entry.id event.url = entry.link event.created = time.mktime(entry.updated_parsed) event.author = entry.get("author", "unknown") if entry.has_key("content"): event.content = entry.content[0].value elif entry.has_key("summary"): event.content = entry.summary else: event.content = "" self.post_init(event, entry) return event
def gatraPlayer_PostEvent(request, id): allowed_methods = ['POST', 'OPTIONS'] if request.method == 'OPTIONS': response = HttpResponse('', status=http_REQUEST_OK) response['Allow'] = ', '.join(allowed_methods) return response if request.method != 'POST': return HttpResponse('', status=http_NOT_ALLOWED) if 'HTTP_GATRA_HASH' in request.META.keys(): _hash = request.META['HTTP_GATRA_HASH'] try: h = Hash.objects.get(valid_hash = _hash) except: return HttpResponse(_hash, status=http_UNAUTHORIZED) else: return HttpResponse('', status=http_UNAUTHORIZED) if id is None: return HttpResponse('', status=http_BAD_REQUEST) try: jsonData = json.loads(request.body) except: return HttpResponse('Could not load json', status=http_BAD_REQUEST) if ('type' in jsonData.keys() and 'trigger' in jsonData.keys() and 'width' in jsonData.keys() and 'container_height' in jsonData.keys() and 'container_width' in jsonData.keys() and 'state' in jsonData.keys() and 'position' in jsonData.keys() and 'fullscreen' in jsonData.keys() and 'volume' in jsonData.keys()): try: play_id = Play.objects.get(id = id) except: return HttpResponse('Play ID not found', status=http_BAD_REQUEST) event = Event() event.play = play_id event.type = jsonData['type'] event.trigger = jsonData['trigger'] event.width = jsonData['width'] event.container_height = jsonData['container_height'] event.container_width = jsonData['container_width'] event.state = jsonData['state'] event.position = jsonData['position'] event.fullscreen = jsonData['fullscreen'] event.volume = jsonData['volume'] if 'bitrate' in jsonData.keys(): event.bitrate = jsonData['bitrate'] if 'bandwidth' in jsonData.keys(): event.bandwidth = jsonData['bandwidth'] if 'media_seq' in jsonData.keys(): event.media_seq = jsonData['media_seq'] if 'load_time' in jsonData.keys(): event.load_time = jsonData['load_time'] if 'quality_label' in jsonData.keys(): event.quality_label = jsonData['quality_label'] event.save() status = http_POST_OK return HttpResponse('', status=status, content_type='application/json') return HttpResponse('Mandatory json value not found', status=http_BAD_REQUEST)