Skip to content

Commit

Permalink
[beta v18]Rend la topbar cohérente en matière de toptags (#3564)
Browse files Browse the repository at this point in the history
* rend la topbar cohérente

* typo

* typo

* typo

* typo

* typo

* typo
  • Loading branch information
artragis authored and gustavi committed Apr 30, 2016
1 parent e36d154 commit 1d1a5b0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
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

0 comments on commit 1d1a5b0

Please sign in to comment.