Esempio n. 1
0
File: event.py Progetto: houdekk/UDJ
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)
Esempio n. 2
0
def addToPlaylist(request, event_id):
  user = getUserForTicket(request)
  songsToAdd = json.loads(request.raw_post_data)
  for song_request in songsToAdd:
    addSong2ActivePlaylist(song_request, event_id, user)

  return HttpResponse(status = 201)
Esempio n. 3
0
def addToPlaylist(request, event_id):
  user = getUserForTicket(request)
  songsToAdd = json.loads(request.raw_post_data)
  toReturn = { 'added_entries' : [], 'request_ids' : [], 'already_played' : [] }
  for song in songsToAdd:
    inQueue = ActivePlaylistEntry.objects.filter(
      adder=user, 
      client_request_id=song['client_request_id'],
      event__id=event_id)

    #If the song is already in the queue
    if inQueue.exists():
      addedSong = inQueue[0]
      upvotes = UpVote.objects.filter(playlist_entry=addedSong).count()
      downvotes = DownVote.objects.filter(playlist_entry=addedSong).count()
      toReturn['added_entries'].append(
        getActivePlaylistEntryDictionary(addedSong, upvotes, downvotes))
      toReturn['request_ids'].append(song['client_request_id'])

    #If the song has already been played
    elif hasBeenPlayed(song, event_id, user):
      toReturn['already_played'].append(song['client_request_id'])

    #If we actually need to add the song
    else:
      addedSong = addSong2ActivePlaylist(song, event_id, user)
      toReturn['added_entries'].append(
        getActivePlaylistEntryDictionary(addedSong, 1, 0))
      toReturn['request_ids'].append(song['client_request_id'])
  
  return HttpResponse(json.dumps(toReturn), status = 201)
Esempio n. 4
0
 def wrapper(*args, **kwargs):
     request = args[0]
     user = getUserForTicket(request)
     activePlayer = kwargs["activePlayer"]
     if activePlayer.owning_user == user:
         return function(*args, **kwargs)
     else:
         return HttpResponseForbidden()
Esempio n. 5
0
 def wrapper(*args, **kwargs):
   request = args[0]
   user = getUserForTicket(request)
   hosts = Event.objects.filter(host=user).exclude(state__exact=u'FN')
   if hosts.exists():
     return HttpResponse(status=409)
   else:
     return function(*args, **kwargs)
Esempio n. 6
0
def voteSong(request, event_id, playlist_id, VoteType):
  votingUser = getUserForTicket(request)
  entryToVote = get_object_or_404(ActivePlaylistEntry, pk=playlist_id)
  if hasAlreadyVoted(votingUser, entryToVote, VoteType):
    return HttpResponseForbidden()

  VoteType(playlist_entry=entryToVote, user=votingUser).save()
  return HttpResponse()
Esempio n. 7
0
 def wrapper(*args, **kwargs):
   request = args[0]
   event = get_object_or_404(Event, id__exact=kwargs['event_id'])
   user = getUserForTicket(request)
   if event.host != user:
     return HttpResponseForbidden("Only the host may do that")
   else:
     return function(*args, **kwargs)
Esempio n. 8
0
 def wrapper(*args, **kwargs):
   request = args[0]
   event = get_object_or_404(Event, id__exact=kwargs['event_id'])
   user = getUserForTicket(request)
   if event.host == user or user.id == int(kwargs['user_id']):
     return function(*args, **kwargs)
   else:
     return HttpResponseForbidden()
Esempio n. 9
0
 def wrapper(*args, **kwargs):
     request = args[0]
     user = getUserForTicket(request)
     activePlayer = kwargs['activePlayer']
     if activePlayer.owning_user == user:
         return function(*args, **kwargs)
     else:
         return HttpResponseForbidden()
Esempio n. 10
0
 def wrapper(*args, **kwargs):
   request = args[0]
   user = getUserForTicket(request)
   event = get_object_or_404(Event, id__exact=kwargs['event_id'])
   event_goers = EventGoer.objects.filter(user=user, event=event)
   if len(event_goers) != 1:
     return HttpResponseForbidden()
   else:
     return function(*args, **kwargs)
Esempio n. 11
0
def removeFromAvailableMusic(request, event_id, song_id):
  host = getUserForTicket(request)
  try:
    AvailableSong.objects.get(
      library_entry__host_lib_song_id=song_id,
      library_entry__owning_user=host).delete()
  except DoesNotExist:
    return HttpResponseNotFound("id " + str(song_id) + " doesn't exist")
  return HttpResponse()
Esempio n. 12
0
File: event.py Progetto: houdekk/UDJ
def leaveEvent(request, event_id, user_id):
  requestingUser = getUserForTicket(request)
  try:
    event_goer = EventGoer.objects.get(
      user=requestingUser, event__id=event_id)
    event_goer.state=u'LE';
    event_goer.save()
    return HttpResponse("left event")
  except ObjectDoesNotExist:
    return HttpResponseForbidden(
      "You must be logged into the party to do that")
Esempio n. 13
0
def addToAvailableMusic(request, event_id):
  host = getUserForTicket(request)
  toAdd = json.loads(request.raw_post_data)
  added = []
  for song_id in toAdd:
    addSong = AvailableSong(library_entry=LibraryEntry.objects.get(
      host_lib_song_id=song_id, owning_user=host))
    addSong.save()
    added.append(song_id)

  return HttpResponse(json.dumps(added), status=201)
Esempio n. 14
0
 def wrapper(*args, **kwargs):
     request = args[0]
     user = getUserForTicket(request)
     activePlayer = kwargs["activePlayer"]
     if activePlayer.owning_user == user or userParticipates(activePlayer, user):
         kwargs["user"] = user
         return function(*args, **kwargs)
     else:
         toReturn = HttpResponse(status=401)
         toReturn["WWW-Authenticate"] = "begin-participating"
         return toReturn
Esempio n. 15
0
 def wrapper(*args, **kwargs):
     request = args[0]
     user = getUserForTicket(request)
     activePlayer = kwargs['activePlayer']
     if activePlayer.owning_user == user or userParticipates(
             activePlayer, user):
         kwargs['user'] = user
         return function(*args, **kwargs)
     else:
         toReturn = HttpResponse(status=401)
         toReturn['WWW-Authenticate'] = 'begin-participating'
         return toReturn
Esempio n. 16
0
File: event.py Progetto: houdekk/UDJ
def endEvent(request, event_id):
  #TODO We have a race condition here. Gonna need to wrap this in a transaction
  #in the future
  toEnd = Event.objects.get(pk=event_id)
  toEnd.state = u'FN'
  toEnd.save()
  EventEndTime(event=toEnd).save()
  user = getUserForTicket(request) 
  host = EventGoer.objects.get(user=user, event__id=event_id)
  host.state=u'LE'
  host.save()
  return HttpResponse("Party ended")
Esempio n. 17
0
  def wrapper(*args, **kwargs):
    request = args[0]
    event_id = kwargs['event_id']
    playlist_id = kwargs['playlist_id']
    user = getUserForTicket(request)
    event = get_object_or_404(Event, pk=event_id)
    playlistEntry = ActivePlaylistEntry.objects.get(pk=playlist_id)

    if event.host != user and playlistEntry.adder != user:
      return HttpResponseForbidden("Only the host of that event or song adder may do that")
    else:
      return function(*args, **kwargs)
Esempio n. 18
0
 def wrapper(*args, **kwargs):
   request = args[0]
   event_id = kwargs['event_id'] 
   requestingUser = getUserForTicket(request)
   event_goers = EventGoer.objects.filter(
     user=requestingUser, event__id=event_id,
     state=u'IE')
   if not event_goers.exists():
     return HttpResponseForbidden(
       "You must be logged into the party to do that")
   elif event_goers[0].event.state == u'FN':
     return HttpResponse(status=410)
   else:
     return function(*args, **kwargs)
Esempio n. 19
0
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)
Esempio n. 20
0
def joinEvent(request, event_id):
  joining_user = getUserForTicket(request)
  event_to_join = Event.objects.get(id=event_id)
  event_goer = EventGoer(user=joining_user, event=event_to_join)
  event_goer.save()
  return HttpResponse("joined event", status=201)