"""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.settings import PAGINATION from zinnia.views.decorators import update_queryset from zinnia.views.decorators import template_name_for_entry_queryset_filtered author_list = update_queryset(object_list, Author.published.all) 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_for_entry_queryset_filtered( 'author', author.username) extra_context.update({'author': author}) kwargs['extra_context'] = extra_context return object_list(request, queryset=author.entries_published(), paginate_by=PAGINATION, page=page, **kwargs)
"""Views for zinnia authors""" from django.contrib.auth.models import User from django.shortcuts import get_object_or_404 from django.http import Http404 from django.views.generic.list_detail import object_list from zinnia.managers import authors_published from zinnia.managers import entries_published from zinnia.views.decorators import update_queryset from zinnia.settings import PAGINATION from zinnia.settings import ZINNIA_BLOG_ACTIVE from zinnia.models import Blog author_list = update_queryset(object_list, authors_published) def author_detail(request, **kwargs): """Display the entries of an author""" username = kwargs.pop('username') page = kwargs['page'] if 'page' in kwargs else None author = get_object_or_404(User, username=username) extra_context = {'author': author} filter = {} if ZINNIA_BLOG_ACTIVE: blog_slug = kwargs.pop('blog_slug') blog = get_object_or_404(Blog, slug = blog_slug) # We check if author is a blog author if author not in blog.authors.all(): raise Http404('User not valid') filter = {'blog__slug': blog_slug} extra_context.update({'blog': blog, 'filters': filter})
"""Views for zinnia entries""" from django.views.generic.list_detail import object_list from django.views.generic.date_based import object_detail from django.views.generic.date_based import archive_year from django.views.generic.date_based import archive_month from django.views.generic.date_based import archive_day from django.shortcuts import get_object_or_404 from zinnia.models import Entry from zinnia.models import Blog from zinnia.views.decorators import update_queryset from django.contrib.comments.views.comments import post_comment from django.contrib.comments.views.comments import comment_done entry_index = update_queryset(object_list, Entry.published.all) entry_year = update_queryset(archive_year, Entry.published.all) entry_month = update_queryset(archive_month, Entry.published.all) entry_day = update_queryset(archive_day, Entry.published.all) entry_detail = update_queryset(object_detail, Entry.published.all) def zinnia_post_comment(request, blog_slug): """Post comment wrapper, add blog_slug to context""" blog = get_object_or_404(Blog, slug = blog_slug) request.session['blog'] = blog return post_comment(request) def zinnia_comment_done(request, blog_slug):
"""Views for Zinnia entries""" from django.shortcuts import redirect from django.shortcuts import get_object_or_404 from django.views.generic.list_detail import object_list from django.views.generic.date_based import archive_year from django.views.generic.date_based import archive_month from django.views.generic.date_based import archive_day from django.views.generic.date_based import object_detail from zinnia.models import Entry from zinnia.views.decorators import protect_entry from zinnia.views.decorators import update_queryset entry_index = update_queryset(object_list, Entry.published.all) entry_year = update_queryset(archive_year, Entry.published.all) entry_month = update_queryset(archive_month, Entry.published.all) entry_day = update_queryset(archive_day, Entry.published.all) entry_detail = protect_entry(object_detail) def entry_shortlink(request, object_id): """ Redirect to the 'get_absolute_url' of an Entry, accordingly to 'object_id' argument """ entry = get_object_or_404(Entry, pk=object_id) return redirect(entry, permanent=True)
"""Views for Zinnia tags""" from django.views.generic.list_detail import object_list from tagging.views import tagged_object_list from zinnia.models import Entry from zinnia.settings import PAGINATION from zinnia.managers import tags_published from zinnia.views.decorators import update_queryset from zinnia.views.decorators import template_name_for_entry_queryset_filtered tag_list = update_queryset(object_list, tags_published) def tag_detail(request, tag, page=None, **kwargs): """Display the entries of a tag""" if not kwargs.get('template_name'): # populate the template_name if not provided in kwargs. kwargs['template_name'] = template_name_for_entry_queryset_filtered( 'tag', tag) return tagged_object_list(request, tag=tag, queryset_or_model=Entry.published.all(), paginate_by=PAGINATION, page=page, **kwargs)
"""Views for zinnia tags""" from django.views.generic.list_detail import object_list from tagging.views import tagged_object_list from zinnia.models import Entry from zinnia.managers import tags_published from zinnia.views.decorators import update_queryset tag_list = update_queryset(object_list, tags_published) tag_detail = update_queryset(tagged_object_list, Entry.published.all, 'queryset_or_model')
"""Views for Zinnia tags""" from django.views.generic.list_detail import object_list from tagging.views import tagged_object_list from zinnia.models import Entry from zinnia.settings import PAGINATION from zinnia.managers import tags_published from zinnia.views.decorators import update_queryset from zinnia.views.decorators import template_name_for_entry_queryset_filtered tag_list = update_queryset(object_list, tags_published) def tag_detail(request, tag, page=None, **kwargs): """Display the entries of a tag""" if not kwargs.get('template_name'): kwargs['template_name'] = template_name_for_entry_queryset_filtered( 'tag', tag) return tagged_object_list(request, tag=tag, queryset_or_model=Entry.published.all(), paginate_by=PAGINATION, page=page, **kwargs)
"""Views for Zinnia tags""" from django.views.generic.list_detail import object_list from tagging.views import tagged_object_list from zinnia.models import Entry from zinnia.managers import tags_published from zinnia.views.decorators import update_queryset tag_list = update_queryset(object_list, tags_published) tag_detail = update_queryset(tagged_object_list, Entry.published.all, 'queryset_or_model')
"""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)