def formfield_for_manytomany(self, db_field, request, **kwargs): if db_field.name == 'authors': kwargs['queryset'] = authors_published() if db_field.name == 'tags': kwargs['queryset'] = tags_published() return super(CMSLatestEntriesPlugin, self).formfield_for_manytomany( db_field, request, **kwargs)
def get_nodes(self, request): """Return menu's node for tags""" nodes = [] nodes.append(NavigationNode(_("Tags"), reverse("zinnia_tag_list"), "tags")) for tag in tags_published(): nodes.append(NavigationNode(tag.name, reverse("zinnia_tag_detail", args=[tag.name]), tag.pk, "tags")) return nodes
def get_content_stats(template='admin/zinnia/widgets/_content_stats.html'): """Return statistics of the contents""" content_type = ContentType.objects.get_for_model(Entry) discussions = Comment.objects.filter(is_public=True, content_type=content_type) return { 'template': template, 'entries': Entry.published.count(), 'categories': Category.objects.count(), 'tags': tags_published().count(), 'authors': Author.published.count(), 'comments': discussions.filter(flags=None).count(), 'pingbacks': discussions.filter(flags__flag='pingback').count(), 'trackbacks': discussions.filter(flags__flag='trackback').count(), 'rejects': Comment.objects.filter(is_public=False, content_type=content_type).count(), }
def formfield_for_manytomany(self, db_field, request, **kwargs): """Filtering manytomany field""" if db_field.name == "authors": kwargs["queryset"] = Author.published.all() if db_field.name == "tags": kwargs["queryset"] = tags_published() return super(CMSLatestEntriesPlugin, self).formfield_for_manytomany(db_field, request, **kwargs)
def zinnia_statistics(template="zinnia/tags/statistics.html"): """ Return statistics on the content of Zinnia. """ content_type = ContentType.objects.get_for_model(Entry) discussions = get_comment_model().objects.filter(content_type=content_type) entries = Entry.published categories = Category.objects tags = tags_published() authors = Author.published replies = discussions.filter(flags=None, is_public=True) pingbacks = discussions.filter(flags__flag=PINGBACK, is_public=True) trackbacks = discussions.filter(flags__flag=TRACKBACK, is_public=True) rejects = discussions.filter(is_public=False) entries_count = entries.count() replies_count = replies.count() pingbacks_count = pingbacks.count() trackbacks_count = trackbacks.count() if entries_count: first_entry = entries.order_by("creation_date")[0] last_entry = entries.latest() months_count = (last_entry.creation_date - first_entry.creation_date).days / 31.0 entries_per_month = entries_count / (months_count or 1.0) comments_per_entry = float(replies_count) / entries_count linkbacks_per_entry = float(pingbacks_count + trackbacks_count) / entries_count total_words_entry = 0 for e in entries.all(): total_words_entry += e.word_count words_per_entry = float(total_words_entry) / entries_count words_per_comment = 0.0 if replies_count: total_words_comment = 0 for c in replies.all(): total_words_comment += len(c.comment.split()) words_per_comment = float(total_words_comment) / replies_count else: words_per_entry = words_per_comment = entries_per_month = comments_per_entry = linkbacks_per_entry = 0.0 return { "template": template, "entries": entries_count, "categories": categories.count(), "tags": tags.count(), "authors": authors.count(), "comments": replies_count, "pingbacks": pingbacks_count, "trackbacks": trackbacks_count, "rejects": rejects.count(), "words_per_entry": words_per_entry, "words_per_comment": words_per_comment, "entries_per_month": entries_per_month, "comments_per_entry": comments_per_entry, "linkbacks_per_entry": linkbacks_per_entry, }
def formfield_for_manytomany(self, db_field, request, **kwargs): """Filtering manytomany field""" if db_field.name == 'authors': kwargs['queryset'] = Author.published.all() if db_field.name == 'tags': kwargs['queryset'] = tags_published() return super(CMSLatestEntriesPlugin, self).formfield_for_manytomany( db_field, request, **kwargs)
def get_nodes(self, request): nodes = [] nodes.append(NavigationNode(_('Tags'), reverse('zinnia_tag_list'), 'tags')) for tag in tags_published(): nodes.append(NavigationNode(tag.name, reverse('zinnia_tag_detail', args=[tag.name]), tag.pk, 'tags')) return nodes
def get_nodes(self, request): """Return menu's node for tags""" nodes = [] nodes.append( NavigationNode(_('Tags'), reverse('zinnia_tag_list'), 'tags')) for tag in tags_published(): nodes.append( NavigationNode(tag.name, reverse('zinnia_tag_detail', args=[tag.name]), tag.pk, 'tags')) return nodes
def get_content_stats( template='admin/zinnia/widgets/_content_stats.html'): """Return statistics of the contents""" content_type = ContentType.objects.get_for_model(Entry) discussions = Comment.objects.filter( is_public=True, content_type=content_type) return {'template': template, 'entries': Entry.published.count(), 'categories': Category.objects.count(), 'tags': tags_published().count(), 'authors': authors_published().count(), 'comments': discussions.filter(flags=None).count(), 'pingbacks': discussions.filter(flags__flag='pingback').count(), 'trackbacks': discussions.filter(flags__flag='trackback').count(), 'rejects': Comment.objects.filter( is_public=False, content_type=content_type).count(), }
def get_tags(): """Return the published tags""" return tags_published()
def zinnia_statistics(template='zinnia/tags/statistics.html'): """Return statistics on the content of Zinnia""" content_type = ContentType.objects.get_for_model(Entry) discussions = get_comment_model().objects.filter(content_type=content_type) entries = Entry.published categories = Category.objects tags = tags_published() authors = Author.published replies = discussions.filter(flags=None, is_public=True) pingbacks = discussions.filter(flags__flag=PINGBACK, is_public=True) trackbacks = discussions.filter(flags__flag=TRACKBACK, is_public=True) rejects = discussions.filter(is_public=False) entries_count = entries.count() replies_count = replies.count() pingbacks_count = pingbacks.count() trackbacks_count = trackbacks.count() if entries_count: first_entry = entries.order_by('creation_date')[0] last_entry = entries.latest() months_count = (last_entry.creation_date - \ first_entry.creation_date).days / 31.0 entries_per_month = months_count / entries_count comments_per_entry = float(replies_count) / entries_count linkbacks_per_entry = float(pingbacks_count + trackbacks_count) / \ entries_count total_words_entry = 0 for e in entries.all(): total_words_entry += e.word_count words_per_entry = float(total_words_entry) / entries_count if replies_count: total_words_comment = 0 for c in replies.all(): total_words_comment += len(c.comment.split()) words_per_comment = float(total_words_comment) / replies_count else: words_per_comment = 0.0 else: words_per_entry = words_per_comment = entries_per_month = \ comments_per_entry = linkbacks_per_entry = 0.0 return { 'template': template, 'entries': entries_count, 'categories': categories.count(), 'tags': tags.count(), 'authors': authors.count(), 'comments': replies_count, 'pingbacks': pingbacks_count, 'trackbacks': trackbacks_count, 'rejects': rejects.count(), 'words_per_entry': words_per_entry, 'words_per_comment': words_per_comment, 'entries_per_month': entries_per_month, 'comments_per_entry': comments_per_entry, 'linkbacks_per_entry': linkbacks_per_entry }
def test_tags_published(self): self.assertEqual(tags_published().count(), Tag.objects.count()) Tag.objects.create(name='out') self.assertNotEqual(tags_published().count(), Tag.objects.count())
"""Urls for the Zinnia tags""" from django.conf.urls.defaults import url from django.conf.urls.defaults import patterns from zinnia.models import Entry from zinnia.settings import PAGINATION from zinnia.managers import tags_published tag_conf = {"queryset": tags_published(), "template_name": "zinnia/tag_list.html"} tag_conf_entry = {"queryset_or_model": Entry.published.all(), "paginate_by": PAGINATION} urlpatterns = patterns( "zinnia.views.tags", url(r"^$", "tag_list", tag_conf, name="zinnia_tag_list"), url(r"^(?P<tag>[- \w]+)/$", "tag_detail", tag_conf_entry, name="zinnia_tag_detail"), url(r"^(?P<tag>[- \w]+)/page/(?P<page>\d+)/$", "tag_detail", tag_conf_entry, name="zinnia_tag_detail_paginated"), )
def test_tags_published(self): self.assertEquals(tags_published().count(), Tag.objects.count()) Tag.objects.create(name='out') self.assertNotEquals(tags_published().count(), Tag.objects.count())
"""Urls for the Zinnia tags""" from django.conf.urls.defaults import url from django.conf.urls.defaults import patterns from zinnia.models import Entry from zinnia.settings import PAGINATION from zinnia.managers import tags_published tag_conf = {'queryset': tags_published(), 'template_name': 'zinnia/tag_list.html'} tag_conf_entry = {'queryset_or_model': Entry.published.all(), 'paginate_by': PAGINATION} urlpatterns = patterns('zinnia.views.tags', url(r'^$', 'tag_list', tag_conf, name='zinnia_tag_list'), url(r'^(?P<tag>[- \w]+)/$', 'tag_detail', tag_conf_entry, name='zinnia_tag_detail'), url(r'^(?P<tag>[- \w]+)/page/(?P<page>\d+)/$', 'tag_detail', tag_conf_entry, name='zinnia_tag_detail_paginated'), )
def items(self): """Return all tags with coeff""" tags = tags_published() self.cache(tags) return tags
def render(self, context): context[self.context_var] = tags_published() return ''
def zinnia_statistics(template='zinnia/tags/statistics.html'): """Return statistics on the content of Zinnia""" content_type = ContentType.objects.get_for_model(Entry) discussions = get_comment_model().objects.filter( content_type=content_type) entries = Entry.published categories = Category.objects tags = tags_published() authors = Author.published replies = discussions.filter( flags=None, is_public=True) pingbacks = discussions.filter( flags__flag=PINGBACK, is_public=True) trackbacks = discussions.filter( flags__flag=TRACKBACK, is_public=True) rejects = discussions.filter(is_public=False) entries_count = entries.count() replies_count = replies.count() pingbacks_count = pingbacks.count() trackbacks_count = trackbacks.count() if entries_count: first_entry = entries.order_by('creation_date')[0] last_entry = entries.latest() months_count = (last_entry.creation_date - \ first_entry.creation_date).days / 31.0 entries_per_month = months_count / entries_count comments_per_entry = float(replies_count) / entries_count linkbacks_per_entry = float(pingbacks_count + trackbacks_count) / \ entries_count total_words_entry = 0 for e in entries.all(): total_words_entry += e.word_count words_per_entry = float(total_words_entry) / entries_count if replies_count: total_words_comment = 0 for c in replies.all(): total_words_comment += len(c.comment.split()) words_per_comment = float(total_words_comment) / replies_count else: words_per_comment = 0.0 else: words_per_entry = words_per_comment = entries_per_month = \ comments_per_entry = linkbacks_per_entry = 0.0 return {'template': template, 'entries': entries_count, 'categories': categories.count(), 'tags': tags.count(), 'authors': authors.count(), 'comments': replies_count, 'pingbacks': pingbacks_count, 'trackbacks': trackbacks_count, 'rejects': rejects.count(), 'words_per_entry': words_per_entry, 'words_per_comment': words_per_comment, 'entries_per_month': entries_per_month, 'comments_per_entry': comments_per_entry, 'linkbacks_per_entry': linkbacks_per_entry}
"""Urls for the zinnia tags""" from django.conf.urls.defaults import * from zinnia.models import Entry from zinnia.settings import PAGINATION from zinnia.managers import tags_published tag_conf = {'queryset': tags_published(), 'template_name': 'zinnia/tag_list.html'} tag_conf_entry = {'queryset_or_model': Entry.published.all(), 'paginate_by': PAGINATION,} urlpatterns = patterns('zinnia.views.tags', url(r'^$', 'tag_list', tag_conf, name='zinnia_tag_list'), url(r'^(?P<tag>[- \w]+)/$', 'tag_detail', tag_conf_entry, name='zinnia_tag_detail'), url(r'^(?P<tag>[- \w]+)/page/(?P<page>\d+)/$', 'tag_detail', tag_conf_entry, name='zinnia_tag_detail_paginated'), )
def items(self): tags = tags_published() self.cache(tags) return tags
def get_tags(): """Return the published tags""" return tags_published()
def items(self): """Return all tags with coeff""" tags = tags_published() self.cache(tags) return tags
def render(self, context): context[self.context_var] = tags_published() return ''
def formfield_for_manytomany(self, db_field, request, **kwargs): if db_field.name == "authors": kwargs["queryset"] = authors_published() if db_field.name == "tags": kwargs["queryset"] = tags_published() return super(PiecemakerZinniaPlugin, self).formfield_for_manytomany(db_field, request, **kwargs)