Ejemplo n.º 1
0
def category_detail(request, path, page=None, **kwargs):
    """Display the entries of a category"""
    extra_context = kwargs.pop('extra_context', {})

    category = get_category_or_404(path)
    if not kwargs.get('template_name'):
        kwargs['template_name'] = template_name_current_site('entry_list.html')

    extra_context.update({'category': category})
    kwargs['extra_context'] = extra_context

    return object_list(request, queryset=category.entries_published(),
                       **kwargs)
Ejemplo n.º 2
0
def author_detail(request, username, page=None, **kwargs):
    """Display the entries of an author"""
    extra_context = kwargs.pop('extra_context', {})

    author = get_object_or_404(Author, username=username)
    if not kwargs.get('template_name'):
        kwargs['template_name'] = template_name_current_site('entry_list.html')

    extra_context.update({'author': author})
    kwargs['extra_context'] = extra_context

    return object_list(request, queryset=author.entries_published(),
                       **kwargs)
Ejemplo n.º 3
0
def entry_search(request):
    """Search entries matching with a pattern"""
    error = None
    pattern = None
    entries = Entry.published.none()

    if request.GET:
        pattern = request.GET.get('pattern', '')
        if len(pattern) < 3:
            error = _('The pattern is too short')
        else:
            entries = Entry.published.search(pattern)
    else:
        error = _('No pattern to search found')

    return object_list(request, queryset=entries,
                       paginate_by=PAGINATION,
                       template_name=template_name_current_site('entry_search.html'),
                       extra_context={'error': error,
                                      'pattern': pattern})
Ejemplo n.º 4
0
def entry_sluglink(request, slug):
    try:
        entry = Entry.published.on_site().filter(slug=slug)[0]
    except Entry.DoesNotExist:
        raise Http404
    except IndexError:
        # look for 301 redirects
        try:
            current_site = Site.objects.get_current()
            redirect = Redirect.objects.get(sites=current_site, old_slug=slug)
            new_slug = redirect.new_slug

            return HttpResponsePermanentRedirect(reverse('zinnia_entry_sluglink', kwargs={'slug':new_slug}))

        except Redirect.DoesNotExist:
            raise Http404


    data = {'object': entry}

    return render_to_response(template_name_current_site('entry_detail.html'), data, context_instance=RequestContext(request))
Ejemplo n.º 5
0
"""Urls for the Zinnia entries"""
from django.conf.urls.defaults import url
from django.conf.urls.defaults import patterns

from zinnia.models import Entry
from zinnia.settings import ALLOW_EMPTY
from zinnia.settings import ALLOW_FUTURE

from zinnia.views.decorators import template_name_current_site

entry_conf_index = {'template_name': template_name_current_site('entry_archive.html')}

entry_conf = {'date_field': 'creation_date',
              'allow_empty': ALLOW_EMPTY,
              'allow_future': ALLOW_FUTURE,
              'month_format': '%m'}

entry_conf_year = entry_conf.copy()
entry_conf_year['make_object_list'] = True
del entry_conf_year['month_format']

entry_conf_detail = entry_conf.copy()
del entry_conf_detail['allow_empty']
entry_conf_detail['queryset'] = Entry.published.on_site()


urlpatterns = patterns(
    'zinnia.views.entries',
    url(r'^$',
        'entry_index', entry_conf_index,
        name='zinnia_entry_archive_index'),
Ejemplo n.º 6
0
"""Urls for the Zinnia categories"""
from django.conf.urls.defaults import url
from django.conf.urls.defaults import patterns

from zinnia.models import Category
from zinnia.views.decorators import template_name_current_site

category_conf = {'queryset': Category.published.on_site(), 'template_name': template_name_current_site('category_list.html') }

urlpatterns = patterns('django.views.generic.list_detail',
                       url(r'^$', 'object_list',
                           category_conf, 'zinnia_category_list'),
                       )

urlpatterns += patterns('zinnia.views.categories',
                        url(r'^(?P<path>[-\/\w]+)/page/(?P<page>\d+)/$',
                            'category_detail',
                            name='zinnia_category_detail_paginated'),
                        url(r'^(?P<path>[-\/\w]+)/$', 'category_detail',
                            name='zinnia_category_detail'),
                        )
Ejemplo n.º 7
0
"""Views for Zinnia authors"""
from django.shortcuts import get_object_or_404
from django.views.generic.list_detail import object_list

from zinnia.models import Author
from zinnia.views.decorators import update_queryset
from zinnia.views.decorators import template_name_current_site


author_list = update_queryset(object_list, Author.published.all, template_name=template_name_current_site('author_list.html'))


def author_detail(request, username, page=None, **kwargs):
    """Display the entries of an author"""
    extra_context = kwargs.pop('extra_context', {})

    author = get_object_or_404(Author, username=username)
    if not kwargs.get('template_name'):
        kwargs['template_name'] = template_name_current_site('entry_list.html')

    extra_context.update({'author': author})
    kwargs['extra_context'] = extra_context

    return object_list(request, queryset=author.entries_published(),
                       **kwargs)