Ejemplo n.º 1
0
    def get_context_data(self, **kwargs):
        context = super(MangaDetail, self).get_context_data(**kwargs)
        update_poster_if_nsfw(self.object, self.request.user)
        print(self.object.poster)
        context['object'].source = context['object'].source.split(',')[0]

        genres = []
        for genre in context['object'].genre.all():
            genres.append(genre.title)
        context['genres'] = ', '.join(genres)

        if self.request.user.is_authenticated():
            context['suggestion_form'] = SuggestionForm(
                instance=Suggestion(user=self.request.user, work=self.object))
            try:
                if Rating.objects.filter(user=self.request.user,
                                         work=self.object,
                                         choice='favorite').count() > 0:
                    context['rating'] = 'favorite'
                else:
                    context['rating'] = self.object.rating_set.get(
                        user=self.request.user).choice
            except Rating.DoesNotExist:
                pass
        return context
Ejemplo n.º 2
0
    def get_context_data(self, **kwargs):
        context = super(AnimeDetail, self).get_context_data(**kwargs)
        anime = self.object
        update_poster_if_nsfw(anime, self.request.user)
        context['object'].source = anime.source.split(',')[0]

        genres = []
        for genre in anime.genre.all():
            genres.append(genre.title)
        context['genres'] = ', '.join(genres)

        if self.request.user.is_authenticated():
            context['suggestion_form'] = SuggestionForm(instance=Suggestion(user=self.request.user, work=self.object))
            try:
                context['rating'] = anime.rating_set.get(user=self.request.user).choice
            except Rating.DoesNotExist:
                pass

        context['references'] = []
        for reference in anime.reference_set.all():
            for domain, name in REFERENCE_DOMAINS:
                if reference.url.startswith(domain):
                    context['references'].append((reference.url, name))

        nb = Counter(Rating.objects.filter(work=anime).values_list('choice', flat=True))
        labels = {'favorite': 'Ajoutés aux favoris', 'like': 'Ont aimé', 'neutral': 'Neutre', 'dislike': 'N\'ont pas aimé', 'willsee': 'Ont envie de voir', 'wontsee': 'N\'ont pas envie de voir'}
        seen_ratings = ['favorite', 'like', 'neutral', 'dislike']
        total = sum(nb.values())
        if total > 0:
            context['stats'] = []
            seen_total = sum(nb[rating] for rating in seen_ratings)
            for rating in labels:
                if seen_total > 0 and rating not in seen_ratings:
                    continue
                context['stats'].append({'value': nb[rating], 'colors': RATING_COLORS[rating], 'label': labels[rating]})
            context['seen_percent'] = round(100 * seen_total / float(total))

        anime_events = anime.event_set.filter(date__gte=timezone.now())
        if anime_events.count() > 0:
            my_events = {}
            if self.request.user.is_authenticated():
                my_events = dict(self.request.user.attendee_set.filter(
                    event__in=anime_events).values_list('event_id', 'attending'))

            context['events'] = [
                {
                    'id': event.id,
                    'attending': my_events.get(event.id, None),
                    'type': event.get_event_type_display(),
                    'channel': event.channel,
                    'date': event.get_date(),
                    'link': event.link,
                    'location': event.location,
                    'nb_attendees': event.attendee_set.filter(attending=True).count(),
                } for event in anime_events
            ]
            
        return context
Ejemplo n.º 3
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        update_poster_if_nsfw(self.object, self.request.user)
        context['object'].source = context['object'].source.split(',')[0]

        genres = []
        if self.request.user.is_authenticated():
            context['suggestion_form'] = SuggestionForm(instance=Suggestion(user=self.request.user, work=self.object))
            try:
                context['rating'] = self.object.rating_set.get(user=self.request.user).choice
            except Rating.DoesNotExist:
                pass
        return context
Ejemplo n.º 4
0
    def get_context_data(self, **kwargs):
        context = super(AnimeDetail, self).get_context_data(**kwargs)
        anime = self.object
        update_poster_if_nsfw(anime, self.request.user)
        context['object'].source = anime.source.split(',')[0]

        genres = []
        for genre in anime.genre.all():
            genres.append(genre.title)
        context['genres'] = ', '.join(genres)

        if self.request.user.is_authenticated():
            context['suggestion_form'] = SuggestionForm(
                instance=Suggestion(user=self.request.user, work=self.object))
            try:
                if Rating.objects.filter(user=self.request.user,
                                         work=anime,
                                         choice='favorite').count() > 0:
                    context['rating'] = 'favorite'
                else:
                    context['rating'] = anime.rating_set.get(
                        user=self.request.user).choice
            except Rating.DoesNotExist:
                pass

        context['references'] = []
        for reference in anime.reference_set.all():
            for domain, name in REFERENCE_DOMAINS:
                if reference.url.startswith(domain):
                    context['references'].append((reference.url, name))

        nb = Counter(
            Rating.objects.filter(work=anime).values_list('choice', flat=True))
        labels = {
            'favorite': 'Ajoutés aux favoris',
            'like': 'Ont aimé',
            'neutral': 'Neutre',
            'dislike': 'N\'ont pas aimé',
            'willsee': 'Ont envie de voir',
            'wontsee': 'N\'ont pas envie de voir'
        }
        context['stats'] = []
        for rating in [
                'favorite', 'like', 'neutral', 'dislike', 'willsee', 'wontsee'
        ]:
            context['stats'].append({
                'value': nb[rating],
                'colors': RATING_COLORS[rating],
                'label': labels[rating]
            })
        return context
Ejemplo n.º 5
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        self.object.source = self.object.source.split(',')[0]

        context['config'] = VANILLA_UI_CONFIG_FOR_RATINGS

        context['genres'] = ', '.join(genre.title
                                      for genre in self.object.genre.all())

        if self.request.user.is_authenticated:
            context['suggestion_form'] = SuggestionForm(
                work=self.object,
                instance=Suggestion(user=self.request.user, work=self.object))
        context['rating'] = current_user_rating(self.request, self.object)

        context['references'] = []
        for reference in self.object.reference_set.all():
            for domain, name in REFERENCE_DOMAINS:
                if reference.url.startswith(domain):
                    context['references'].append((reference.url, name))

        nb = Counter(
            Rating.objects.filter(work=self.object).values_list('choice',
                                                                flat=True))
        labels = OrderedDict([
            ('favorite', 'Ajoutés aux favoris'),
            ('like', 'Ont aimé'),
            ('neutral', 'Neutre'),
            ('dislike', 'N\'ont pas aimé'),
            ('willsee', 'Ont envie de voir'),
            ('wontsee', 'N\'ont pas envie de voir'),
        ])
        seen_ratings = {'favorite', 'like', 'neutral', 'dislike'}
        total = sum(nb.values())
        if total > 0:
            context['stats'] = []
            seen_total = sum(nb[rating] for rating in seen_ratings)
            for rating, label in labels.items():
                if seen_total > 0 and rating not in seen_ratings:
                    continue
                context['stats'].append({
                    'value': nb[rating],
                    'colors': RATING_COLORS[rating],
                    'label': label
                })
            context['seen_percent'] = round(100 * seen_total / float(total))

        return context
Ejemplo n.º 6
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        self.object.source = self.object.source.split(',')[0]

        context['config'] = VANILLA_UI_CONFIG_FOR_RATINGS

        context['genres'] = ', '.join(genre.title for genre in self.object.genre.all())

        if self.request.user.is_authenticated:
            context['suggestion_form'] = SuggestionForm(work=self.object, instance=Suggestion(user=self.request.user, work=self.object))
        context['rating'] = current_user_rating(self.request, self.object)

        context['references'] = []
        for reference in self.object.reference_set.all():
            for domain, name in REFERENCE_DOMAINS:
                if reference.url.startswith(domain):
                    context['references'].append((reference.url, name))

        nb = Counter(Rating.objects.filter(work=self.object).values_list('choice', flat=True))
        labels = OrderedDict([
            ('favorite', 'Ajoutés aux favoris'),
            ('like', 'Ont aimé'),
            ('neutral', 'Neutre'),
            ('dislike', 'N\'ont pas aimé'),
            ('willsee', 'Ont envie de voir'),
            ('wontsee', 'N\'ont pas envie de voir'),
        ])
        seen_ratings = {'favorite', 'like', 'neutral', 'dislike'}
        total = sum(nb.values())
        if total > 0:
            context['stats'] = []
            seen_total = sum(nb[rating] for rating in seen_ratings)
            for rating, label in labels.items():
                if seen_total > 0 and rating not in seen_ratings:
                    continue
                context['stats'].append({'value': nb[rating], 'colors': RATING_COLORS[rating], 'label': label})
            context['seen_percent'] = round(100 * seen_total / float(total))

        events = self.object.event_set \
            .filter(date__gte=timezone.now()) \
            .annotate(nb_attendees=Sum(Case(
            When(attendee__attending=True, then=Value(1)),
            default=Value(0),
            output_field=IntegerField(),
        )))
        if len(events) > 0:
            my_events = {}
            if self.request.user.is_authenticated:
                my_events = dict(self.request.user.attendee_set.filter(
                    event__in=events).values_list('event_id', 'attending'))

            context['events'] = [
                {
                    'id': event.id,
                    'attending': my_events.get(event.id, None),
                    'type': event.get_event_type_display(),
                    'channel': event.channel,
                    'date': event.get_date(),
                    'link': event.link,
                    'location': event.location,
                    'nb_attendees': event.nb_attendees,
                } for event in events
            ]

        return context