Esempio n. 1
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