def createEvent(request): user = getUserForTicket(request) event = json.loads(request.raw_post_data) if 'name' not in event: return HttpResponseBadRequest("Must include a name attribute") newEvent = Event(name=event['name'], host=user) newEvent.save() if 'coords' in event: if 'latitude' not in event['coords'] or 'longitude' not in event['coords']: return HttpResponseBadRequest("Must include both latitude and " "longitude with coords") else: EventLocation(event=newEvent, latitude=event['coords']['latitude'], longitude=event['coords']['longitude']).save() if 'password' in event: m = hashlib.sha1() m.update(event[password]) EventPassword(event=newEvent, password_hash=m.hexdigest()).save() hostInsert = EventGoer(user=user, event=newEvent) hostInsert.save() return getJSONResponse('{"event_id" : ' + str(newEvent.id) + '}', status=201)
def createEvent(request): user = getUserForTicket(request) event = json.loads(request.raw_post_data) if 'name' not in event: return HttpResponseBadRequest("Must include a name attribute") toInsert = Event(name=event['name'], host=user) if 'coords' in event: if 'latitude' not in event['coords'] or 'longitude' not in event['coords']: return HttpResponseBadRequest("Must include both latitude and " "longitude with coords") else: toInsert.latitude = event['coords']['latitude'] toInsert.longitude = event['coords']['longitude'] if 'password' in event: m = hashlib.sha1() m.update(event[password]) toInsert.password_hash = m.hexdigest() toInsert.save() return HttpResponse('{"event_id" : ' + str(toInsert.id) + '}', status=201)