Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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(),
    }
Exemplo n.º 4
0
 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,
    }
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
Arquivo: menu.py Projeto: TRex1983/MSR
 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
Exemplo n.º 8
0
 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(),
            }
Exemplo n.º 10
0
def get_tags():
    """Return the published tags"""
    return tags_published()
Exemplo n.º 11
0
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
    }
Exemplo n.º 12
0
 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())
Exemplo n.º 13
0
"""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"),
)
Exemplo n.º 14
0
 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())
Exemplo n.º 15
0
"""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'),
                       )
Exemplo n.º 16
0
 def items(self):
     """Return all tags with coeff"""
     tags = tags_published()
     self.cache(tags)
     return tags
Exemplo n.º 17
0
 def render(self, context):
     context[self.context_var] = tags_published()
     return ''
Exemplo n.º 18
0
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}
Exemplo n.º 19
0
"""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'),
                       )
Exemplo n.º 20
0
 def items(self):
     tags = tags_published()
     self.cache(tags)
     return tags
Exemplo n.º 21
0
def get_tags():
    """Return the published tags"""
    return tags_published()
Exemplo n.º 22
0
 def items(self):
     """Return all tags with coeff"""
     tags = tags_published()
     self.cache(tags)
     return tags
Exemplo n.º 23
0
 def render(self, context):
     context[self.context_var] = tags_published()
     return ''
Exemplo n.º 24
0
 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)