コード例 #1
0
def set_max_track():
    data = Song.objects().order_by("-track_n")[0]
    print data.track_n
    
    songsMeta = SongsMeta.objects().all()
    if(len(songsMeta)>0):
        m = songsMeta[0]
    else:
        m = SongsMeta()
    m.n = data.track_n
    m.save()
コード例 #2
0
def set_max_track():
    data = Song.objects().order_by("-track_n")[0]
    print data.track_n

    songsMeta = SongsMeta.objects().all()
    if (len(songsMeta) > 0):
        m = songsMeta[0]
    else:
        m = SongsMeta()
    m.n = data.track_n
    m.save()
コード例 #3
0
 def create_next_poll(cls, stream_id , save_in_db = True):
     #pick , 7 songs, 
     # create poll items , 
     # create poll item with the stream Id
     #return 
     total_songs = SongsMeta.objects().get().n
         
     poll = Poll()
     poll.stream_id = stream_id
     if(save_in_db):
         poll.save()
     poll_items = []
     try:
         temp_track_hash = {}
         while(len(poll_items)<7):
             try:
                 random_track_n = random.randint(0,total_songs)
                 if(temp_track_hash.get(random_track_n, None)): continue# dont repeat tracks
                 
                 song = Song.objects(track_n=random_track_n).get()
                 poll_item =  PollItem(song = song , poll_count =0 , poll= poll)
                 poll_items.append(poll_item)
                 temp_track_hash[random_track_n] = True
                 
             except (MultipleObjectsReturned, DoesNotExist) as ex:
                 pass
             
                 
         for poll_item in poll_items:
             if(save_in_db): 
                 poll_item.save()
         
         poll.poll_items = poll_items
         if(save_in_db):
             poll.save()#again with updates pollItems
     except Exception as ex:
         print ex
         poll.delete()
         poll = None
         for poll_item in poll_items:
             if(save_in_db):
                 poll_item.delete()
         
     return poll