Esempio n. 1
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}
Esempio n. 2
0
 def get_context_data(self, **kwargs):
     artist = self.get_object()
     relevant_contributions = EntityContribution.objects.filter(
         song=OuterRef('pk'), artist=artist)
     songs = filter_visible_to_user(
         Song.objects.all(), self.request.user).annotate(
             relevant=Exists(relevant_contributions)).filter(
                 relevant=True).annotate(num_notes=Count('songnote'))
     context = super().get_context_data(**kwargs)
     context['songs'] = songs
     context['artist'] = artist
     context['notes'] = ArtistNote.items_visible_to(
         self.request.user).filter(artist=self.object)
     return context
Esempio n. 3
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
Esempio n. 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
Esempio n. 5
0
    def handle(self, *args, **options):
        for artist in Artist.objects.all():
            if ArtistNote.objects.filter(artist=artist):
                print('No need to create note for: ' + str(artist))
                continue

            if not artist.description_trevor:
                print('No interesting info about: ' + str(artist))
                continue

            note = ArtistNote()
            note.artist = artist
            note.title = artist.name
            note.image = artist.image
            note.image_url = artist.image_url
            note.image_author = artist.image_author
            note.text_trevor = artist.description_trevor
            # content meta
            note.author = artist.author
            note.reviewed = artist.reviewed
            note.pub_date = artist.pub_date
            note.save()
            print('Created note: %s' % (note.title))