コード例 #1
0
ファイル: event.py プロジェクト: 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)
コード例 #2
0
ファイル: event.py プロジェクト: houdekk/UDJ
def getEvents(request):
  if not request.GET.__contains__('name'):
    return HttpResponseBadRequest("Must include name parameter")
  events = Event.objects.filter(
    name__icontains=request.GET['name'],
    state=u'AC')
  events_json = getJSONForEvents(events)
  return getJSONResponse(events_json)
コード例 #3
0
ファイル: activeplaylist.py プロジェクト: yeoedward/UDJ
def getVotes(request, event_id, user_id):
  votes = Vote.objects.filter(
    playlist_entry__event__id=event_id,
    user__id=user_id, playlist_entry__state=u'QE')
  upvoteIds = [vote.playlist_entry.id for vote in votes if vote.weight==1]
  downvoteIds = [vote.playlist_entry.id for vote in votes if vote.weight==-1]
  return getJSONResponse(json.dumps(
    {'up_vote_ids' : upvoteIds, 'down_vote_ids' : downvoteIds}))
コード例 #4
0
ファイル: activeplaylist.py プロジェクト: yeoedward/UDJ
def getAddRequests(request, event_id, user_id):
  addRequests = ActivePlaylistEntry.objects.filter(
    event__id=event_id, adder__id=user_id).only(
    'client_request_id', 
    'song__host_lib_song_id')
      
  requestIds = [
   {'client_request_id' : add_request.client_request_id,
   'lib_id' : add_request.song.host_lib_song_id}
   for add_request in addRequests]
  return getJSONResponse(json.dumps(requestIds))
コード例 #5
0
ファイル: library.py プロジェクト: houdekk/UDJ
def addSongsToLibrary(request, user_id):

  #TODO catch any exception in the json parsing and return a bad request
  songsToAdd = json.loads(request.raw_post_data)

  toReturn = []
  for libEntry in songsToAdd:
    addedSong = addSongToLibrary(libEntry, user_id)
    toReturn.append(addedSong.host_lib_song_id)

  return getJSONResponse(json.dumps(toReturn), status=201)
コード例 #6
0
ファイル: event.py プロジェクト: houdekk/UDJ
def addToAvailableMusic(request, event_id):
  event = get_object_or_404(Event, pk=event_id)
  toAdd = json.loads(request.raw_post_data)
  added = []
  for song_id in toAdd:
    songToAdd = LibraryEntry.objects.get(
      host_lib_song_id=song_id, owning_user=event.host)
    addedSong , created = AvailableSong.objects.get_or_create(
      event=event, song=songToAdd)
    added.append(song_id)

  return getJSONResponse(json.dumps(added), status=201)
コード例 #7
0
ファイル: event.py プロジェクト: yeoedward/UDJ
def addToAvailableMusic(request, event_id):
  event = get_object_or_404(Event, pk=event_id)
  uuid = request.META[getDjangoUUIDHeader()]
  toAdd = json.loads(request.raw_post_data)
  added = []
  for song_id in toAdd:
    songToAdd = LibraryEntry.objects.get(
      host_lib_song_id=song_id, owning_user=event.host, machine_uuid=uuid)
    addedSong , created = AvailableSong.objects.get_or_create(
        event=event, song=songToAdd, defaults={'state': u'AC'})
    added.append(song_id)

  return getJSONResponse(json.dumps(added), status=201)
コード例 #8
0
ファイル: event.py プロジェクト: houdekk/UDJ
def getAvailableMusic(request, event_id):
  event = Event.objects.get(pk=event_id)
  if(not request.GET.__contains__('query')):
    return HttpResponseBadRequest('Must specify query')
  query = request.GET.__getitem__('query')
  available_songs = AvailableSong.objects.filter(
    event__id=event_id, song__owning_user=event.host)
  available_songs = available_songs.filter(
    Q(song__title__icontains=query) |
    Q(song__artist__icontains=query) |
    Q(song__album__icontains=query))
  if(request.GET.__contains__('max_results')):
    available_songs = available_songs[:request.GET['max_results']]
    
  return getJSONResponse(getJSONForAvailableSongs(available_songs))
コード例 #9
0
ファイル: activeplaylist.py プロジェクト: yeoedward/UDJ
def getActivePlaylist(request, event_id):
  playlistEntries = ActivePlaylistEntry.objects.filter(
    event__id=event_id, state=u'QE').annotate(
      totalvotes=Sum('vote__weight')).order_by('-totalvotes','time_added')

  activePlaylist = getActivePlaylistArray(playlistEntries)
  currentSongDict = {}
  try:
    currentSong = ActivePlaylistEntry.objects.get(
      event__id=event_id, state=u'PL')
    currentSongDict = getActivePlaylistEntryDictionary(currentSong)
    currentSongDict['time_played'] = \
      PlaylistEntryTimePlayed.objects.get(playlist_entry=currentSong).time_played.replace(microsecond=0).isoformat()
  except ObjectDoesNotExist:
    pass

  return getJSONResponse(json.dumps(
    {
      "current_song" : currentSongDict,
      "active_playlist" : activePlaylist
    }
  ))
コード例 #10
0
ファイル: event.py プロジェクト: houdekk/UDJ
def getNearbyEvents(request, latitude, longitude):
  #TODO This is super ineeficient. We need to switch over to a geo database
  locations = EventLocation.objects.filter(event__state=u'AC')
  events_json = getJSONForEventsByLocation(
    latitude, longitude, locations)
  return getJSONResponse(events_json)  
コード例 #11
0
ファイル: event.py プロジェクト: houdekk/UDJ
def getEventGoers(request, event_id):
  eventGoers = EventGoer.objects.filter(event__id=event_id)
  return getJSONResponse(getJSONForEventGoers(eventGoers))
コード例 #12
0
ファイル: event.py プロジェクト: houdekk/UDJ
def getRandomMusic(request, event_id):
  rand_limit = request.GET.get('max_randoms',20)
  randomSongs = AvailableSong.objects.filter(event__id=event_id)
  randomSongs = randomSongs.order_by('?')[:rand_limit]
  return getJSONResponse(getJSONForAvailableSongs(randomSongs))