Exemple #1
0
 def test_has_user_voted_for_song(self):
     vote_service = VoteService()
     vote = Vote()
     vote.user_id = 1
     vote.song_id = 1
     vote.created_date = datetime.now()
     vote.like = True
     vote.save()
     user = User()
     user.id = 1
     song = Song
     song.id = 1
     self.assertTrue(vote_service.has_user_voted_for_song(song, user))
Exemple #2
0
 def get_context_data(self, **kwargs):
     context = super(SongthreadDetailView, self).get_context_data(**kwargs)
     context['spotify_embed_url'] = SPOTIFY_EMBED_URL
     songthread_id_kwarg = self.kwargs['pk']
     songs = Song.objects.filter(songthread_id=songthread_id_kwarg)\
                         .annotate(number_of_votes=Count('vote'),
                                   number_of_likes=Sum('vote__like'))\
                         .order_by('number_of_likes')
     vote_service = VoteService()
     for song in songs:
         song.vote = vote_service.get_users_vote_for_song(
             song, self.request.user)
     comments = Comment.objects.filter(songthread_id=songthread_id_kwarg)\
                               .order_by('-created_date')
     context['songs'] = songs
     context['comments'] = comments
     context['anonymous_user'] = User.objects.get(username='******')
     return context
Exemple #3
0
 def clean(self):
     vote_service = VoteService()
     if vote_service.has_user_voted_for_song(self.song, self.user):
         raise ValidationError("Vote already exists")
     else:
         return self