Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[beta v18]Rend la topbar cohérente en matière de toptags #3564

Merged
merged 7 commits into from
Apr 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions zds/tutorialv2/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from django.conf import settings
from django.db import models
from zds.utils.models import Tag
from django.db.models import Count


class PublishedContentManager(models.Manager):
Expand Down Expand Up @@ -43,6 +45,20 @@ def get_contents_count(self):
return self.filter(must_redirect=False)\
.count()

def get_top_tags(self, displayed_types, limit=-1):
published = self.filter(
must_redirect=False,
content__type__in=displayed_types).values('content__tags').distinct()
tags_pk = [tag['content__tags'] for tag in published]
queryset = Tag.objects\
.filter(pk__in=tags_pk, publishablecontent__public_version__isnull=False,
publishablecontent__type__in=displayed_types)\
.annotate(num_content=Count('publishablecontent'))\
.order_by('-num_content', 'title')
if limit > 0:
queryset = queryset[:limit]
return queryset


class PublishableContentManager(models.Manager):
"""..."""
Expand Down
12 changes: 1 addition & 11 deletions zds/tutorialv2/views/views_published.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.db import transaction
from django.db.models import Count
from django.http import Http404, HttpResponsePermanentRedirect, StreamingHttpResponse, HttpResponse
from django.shortcuts import get_object_or_404, redirect, render_to_response
from django.template.loader import render_to_string
Expand Down Expand Up @@ -677,13 +676,4 @@ class TagsListView(ListView):
displayed_types = ["TUTORIAL", "ARTICLE"]

def get_queryset(self):
published = PublishedContent.objects.filter(
must_redirect=False,
content__type__in=self.displayed_types).values('content__tags').distinct()
tags_pk = [tag['content__tags'] for tag in published]
queryset = Tag.objects\
.filter(pk__in=tags_pk, publishablecontent__public_version__isnull=False,
publishablecontent__type__in=self.displayed_types)\
.annotate(num_content=Count('publishablecontent'))\
.order_by('-num_content', 'title')
return queryset
return PublishedContent.objects.get_top_tags(self.displayed_types)
22 changes: 3 additions & 19 deletions zds/utils/templatetags/topbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,9 @@ def top_categories_content(_type):
else:
cats[key] = [(csc['subcategory__title'], csc['subcategory__slug'])]

# get all tags from contents
tmp_tags = (PublishedContent.objects
.filter(must_redirect=False)
.values_list('content__tags__pk', flat=True)
.select_related('content')
.distinct()
.filter(content__tags__isnull=False)
[:settings.ZDS_APP['forum']['top_tag_max'] + len(settings.ZDS_APP['forum']['top_tag_exclu'])])

tags_not_filtered = Tag.objects.filter(pk__in=[pk for pk in tmp_tags])

# select tags that are not in the excluded list
tags = []
for tag in tags_not_filtered:
if tag.title not in settings.ZDS_APP['forum']['top_tag_exclu'] \
and len(tags) <= settings.ZDS_APP['forum']['top_tag_max']:
tags.append(tag)

return {"tags": tags, "categories": cats}
return {"tags": PublishedContent.objects.get_top_tags(["TUTORIAL", "ARTICLE"],
limit=settings.ZDS_APP['forum']['top_tag_max']),
"categories": cats}


@register.filter('auth_forum')
Expand Down