Пример #1
0
 def obj_create(self,bundle,**kwargs):
     track = StationTrack.objects.get(pk=bundle.data['pk'])
     user = kwargs['request'].user
     print user
     listen = Listen(track=track,user=user)
     listen.save()
     return listen
Пример #2
0
def update_recording(quip_id):
    parser = reqparse.RequestParser()
    parser.add_argument('duration', type=int, location='json')
    parser.add_argument('position', type=int, location='json')
    parser.add_argument('progress', type=int, location='json')
    parser.add_argument('isPublic', type=bool, location='json')
    update = parser.parse_args()

    Recording.objects(Q(id=quip_id)).modify(
        upsert=True,
        set__isPublic=update['isPublic']
    )

    Listen.objects(Q(user=g.user['id']) & Q(recording=quip_id)).modify(
        upsert=True,
        set__progress=update['progress'],
        set__position=update['position'],
        set__duration=update['duration'],
    )

    return QuipMapper.to_web_dto(Recording.objects.get_or_404(Q(id=quip_id))), 200
Пример #3
0
def play(request, userId):
    # Get songs
    songs = Song.objects.all()
    # get songs with best average
    listens = Listen.objects.values('song').annotate(
        avg=Avg('user_rating')).order_by('-avg')

    listens = listens[:5]

    # select one randomly, get the id, do a lookup in SONG, get path

    from random import choice
    listens = choice(listens)

    song_id = listens['song']

    play_song = Song.objects.get(pk=song_id)

    # extract file name
    path = play_song.file.path
    filename = path[(path.rfind('/') + 1):]

    # Create new listen object
    currentUser = User.objects.get(pk=userId)
    newListen = Listen(user_rating=5,
                       perc_listened=100,
                       time_started=datetime.now(),
                       song=play_song,
                       user=currentUser)
    newListen.save()

    return render(request, 'play.html', {
        'filename': filename,
        'listenId': newListen.id,
        'userId': userId
    })