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

[v18]corrige le nombre de tuto par tag #3533

Merged
merged 2 commits into from
Apr 26, 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
6 changes: 4 additions & 2 deletions zds/tutorialv2/urls/urls_articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from django.conf.urls import url

from zds.tutorialv2.views.views_published import ListArticles, DisplayOnlineArticle, DownloadOnlineArticle
from zds.tutorialv2.views.views_published import ListArticles, DisplayOnlineArticle, DownloadOnlineArticle, \
TagsListView
from zds.tutorialv2.feeds import LastArticlesFeedRSS, LastArticlesFeedATOM

urlpatterns = [
Expand All @@ -25,5 +26,6 @@
name='download-zip'),

# Listing
url(r'^$', ListArticles.as_view(), name='list')
url(r'^$', ListArticles.as_view(), name='list'),
url(r'tags/*', TagsListView.as_view(displayed_types=["ARTICLE"]), name="tags")
]
6 changes: 4 additions & 2 deletions zds/tutorialv2/urls/urls_tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from zds.tutorialv2.views.views_contents import RedirectOldBetaTuto

from zds.tutorialv2.views.views_published import ListTutorials, DisplayOnlineTutorial, DisplayOnlineContainer, \
DownloadOnlineTutorial, RedirectContentSEO
DownloadOnlineTutorial, RedirectContentSEO, TagsListView
from zds.tutorialv2.feeds import LastTutorialsFeedRSS, LastTutorialsFeedATOM


urlpatterns = [
# flux
url(r'^flux/rss/$', LastTutorialsFeedRSS(), name='feed-rss'),
Expand Down Expand Up @@ -40,5 +41,6 @@
url('^beta/(?P<pk>\d+)/(?P<slug>.+)', RedirectOldBetaTuto.as_view(), name="old-beta-url"),

# Listing
url(r'^$', ListTutorials.as_view(), name='list')
url(r'^$', ListTutorials.as_view(), name='list'),
url(r'tags/$', TagsListView.as_view(displayed_types=["TUTORIAL"]), name="tags")
]
11 changes: 8 additions & 3 deletions zds/tutorialv2/views/views_published.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,16 @@ class TagsListView(ListView):
model = Tag
template_name = "tutorialv2/view/tags.html"
context_object_name = 'tags'
displayed_types = ["TUTORIAL", "ARTICLE"]

def get_queryset(self):
tags_pk = [tag['content__tags'] for tag in PublishedContent.objects.values('content__tags').distinct()]
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)\
.annotate(num_content=Count('publishablecontent__publishedcontent'))\
.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