예제 #1
0
def request_song(request, song_id):
    """
    Create a new SongRequest object for the given song id.
    """
    request_user = request.user
    if not request.user.is_authenticated():
        # Set this to None to avoid storing an AnonymousUser in the
        # SongRequest (this would raise an exception).
        request_user = None
        # You can allow anonymous user requests in settings.py.
        if not settings.ALLOW_ANON_REQUESTS:
            # Anonymous user requests not allowed, error out.
            message = JSMessage("You must be logged in to request songs.", 
                                is_error=True)
            return HttpResponse(message)

    # Look the song up and create a request.
    song = Song.objects.get(id=song_id)
    if SongRequest.objects.get_active_requests().filter(song=song):
        # Don't allow requesting a song that is currently in the queue.
        return HttpResponse(JSMessage("Song has already been requested.", 
                                      is_error=True))
    else:
        # Song isn't already in the SongRequest queue, add it.
        request = SongRequest(song=song, requester=request_user)
        request.save()
        return HttpResponse(JSMessage("Song Requested."))
예제 #2
0
def request_song(request):  #, song_id):
    """
	Create a new SongRequest object for the given song id.
	"""
    request_user = request.user
    song_id = long(request.POST['song_id'])
    if not request.user.is_authenticated():
        # Set this to None to avoid storing an AnonymousUser in the
        # SongRequest (this would raise an exception).
        request_user = None
        # You can allow anonymous user requests in settings.py.
        if not settings.ALLOW_ANON_REQUESTS:
            # Anonymous user requests not allowed, error out.
            message = JSMessage("You must be logged in to request songs.",
                                is_error=True)
            return HttpResponse(message)

    # Look the song up and create a request.
    song = Song.objects.get(id=song_id)
    if SongRequest.objects.get_active_requests().filter(song=song):
        # Don't allow requesting a song that is currently in the queue.
        return HttpResponse(
            JSMessage("Song has already been requested.", is_error=True))
    elif SongRequest.objects.get_active_requests().filter(
            requester=request_user).count(
            ) >= settings.MAX_OUTSTANDING_REQUESTS_PER_USER:
        return HttpResponse(
            JSMessage(
                "You've already got the maximum number of outstanding requests.",
                is_error=True))
    else:
        # Song isn't already in the SongRequest queue, add it.
        request = SongRequest(song=song, requester=request_user)
        request.save()
        return HttpResponse(JSMessage("Song Requested."))
예제 #3
0
def enqueue_song(song):
    """
    Given a Song object, create a SongRequest.
    
    song: (Song) The Song object to enqueue.
    """
    new_request = SongRequest(song=song)
    new_request.save()
    def procesar(self,tweet):
        if tweet.text.find("#") > -1:
            pos=tweet.text[tweet.text.find("#"):].find(" ")
            if pos == -1:
                pos = len(tweet.text[tweet.text.find("#"):])
            print "pos: "+str(pos)

            print "buscando :"+tweet.text[tweet.text.find("#"):tweet.text.find("#")+pos]
            song = Song.objects.get(id=int(tweet.text[tweet.text.find("#")+1:int(tweet.text.find("#")+pos)]))
            if SongRequest.objects.get_active_requests().filter(song=song):
                # Don't allow requesting a song that is currently in the queue.
                print "Song has already been requested."
            else:
                # Song isn't already in the SongRequest queue, add it.
                request = SongRequest(song=song, twitter=tweet.username)
                request.save()
                rtn = self.turpial.update_status(self.turpial.list_accounts()[0], "@"+tweet.username+" puso en cola de reproduccion a: "+song.title+" - "+song.artist)
                if rtn.code > 0:
                    print rtn.errmsg
                else:
                    print '\n\n\n\nMessage posted in account %s' % self.turpial.list_accounts()[0].split('-')[0]
                print "***************Song Requested.\n\n\n\n\n"