Пример #1
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['carousel_items'] = CarouselItem.objects.filter(archived=False)
     context['events'] = get_events_for(self.request.user)
     context['posts'] = (Post.items_visible_to(self.request.user)
                         .order_by('-pub_date')[:SiteIndex.POST_COUNT])
     context['songs'] = (Song.items_visible_to(self.request.user)
                         .order_by('-pub_date')[:SiteIndex.SONG_COUNT])
     context['annotation'] = (SongNote.items_visible_to(self.request.user)
                              .order_by('-pub_date').first())
     context['annotations'] = (
         SongNote.items_visible_to(self.request.user)
         .order_by('-pub_date')[:SiteIndex.ANNOTATION_COUNT])
     return context
Пример #2
0
def to_review(request):
    to_review = []
    to_review.extend(Article.items_reviewable_by(request.user))
    to_review.extend(ArtistNote.items_reviewable_by(request.user))
    to_review.extend(Post.items_reviewable_by(request.user))
    to_review.extend(Song.items_reviewable_by(request.user))
    to_review.extend(SongNote.items_reviewable_by(request.user))
    return {'to_review': to_review}
Пример #3
0
    def test_edit_song_note(self):
        author = testing.create_user()
        note = SongNote.create_for_testing(author)

        data = {'title': 'tytul', 'text_trevor': put_text_in_trevor('CDE')}
        response = testing.get_user_client(user=author).post(
            note.get_edit_url(), data=data)
        self.assertEqual(302, response.status_code)
        self.assertRedirects(response, note.song.get_absolute_url())
Пример #4
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['article'] = (Article.items_visible_to(self.request.user)
                           .order_by('-pub_date').first())
     context['events'] = get_events_for(self.request.user)
     context['posts'] = (Post.items_visible_to(self.request.user)
                         .order_by('-pub_date')[:SiteIndex.POST_COUNT])
     context['songs'] = (Song.items_visible_to(self.request.user)
                         .order_by('-pub_date')[:SiteIndex.SONG_COUNT])
     context['song_of_the_day'] = self.get_song_of_the_day()
     context['annotation'] = (SongNote.items_visible_to(self.request.user)
                              .order_by('-pub_date').first())
     song_notes = SongNote.items_visible_to(self.request.user).order_by(
         '-pub_date')[:SiteIndex.ANNOTATION_COUNT]
     artist_notes = ArtistNote.items_visible_to(self.request.user).order_by(
         '-pub_date')[:SiteIndex.ANNOTATION_COUNT]
     notes = (list(song_notes) + list(artist_notes))
     notes.sort(key=lambda x: x.pub_date, reverse=True)
     context['annotations'] = notes[:SiteIndex.ANNOTATION_COUNT]
     return context
Пример #5
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     if 'transposition' in self.kwargs:
         context['json'] = True
         transposition = int(self.kwargs['transposition'])
         context['transposition'] = transposition
     else:
         transposition = 0
     context['lyrics'] = render_lyrics(self.object.lyrics, transposition)
     context['notes'] = SongNote.items_visible_to(self.request.user).filter(
         song=self.object)
     context['mentions'] = SongMention.objects.filter(song=self.object)
     return context
Пример #6
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     authors = []
     for user in User.objects.filter(is_active=True):
         author = {}
         author['user'] = user
         author['annotations'] = SongNote.items_live().filter(
             author=user).count() + ArtistNote.items_live().filter(
                 author=user).count()
         author['songs'] = Song.items_live().filter(author=user).count()
         author['articles'] = Article.items_live().filter(
             author=user).count()
         author['total'] = (author['annotations'] + author['songs'] +
                            self.ARTICLE_FACTOR * author['articles'])
         if author['total']:
             authors.append(author)
     context['authors'] = sorted(
         authors, key=lambda k: k['total'], reverse=True)
     return context