<NME> views.py
<BEF> # -*- coding: utf-8 -*-
import datetime

from django.conf import settings
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from django.views.generic import TemplateView

from advertising.mixins import AdsMixin
from digest.mixins import FeedItemsMixin, FavoriteItemsMixin
from digest.models import Issue, Item
from frontend.models import EditorMaterial

# import the logging library
import logging

# Get an instance of a logger
logger = logging.getLogger(__name__)


class Sitemap(TemplateView):
    content_type = 'text/xml'
    template_name = 'sitemap.html'

    def get_context_data(self, **kwargs):
        ctx = super(Sitemap, self).get_context_data(**kwargs)
        items = [
            {'loc': '', 'changefreq': 'weekly'},
            {'loc': reverse('digest:issues'), 'changefreq': 'weekly'},
            {'loc': reverse('digest:feed'), 'changefreq': 'daily'},
        ]

        for issue in Issue.objects.filter(status='active'):
            items.append({'loc': issue.link, 'changefreq': 'weekly'})

        for item in Item.objects.filter(status='active',
                                        activated_at__lte=datetime.datetime.now()):
            items.append(
                {'loc': '/view/{}'.format(item.pk), 'changefreq': 'weekly'})

        ctx.update(
            {'records': items,
             'domain': 'https://{}'.format(settings.BASE_DOMAIN)})
        return ctx


class IndexView(FavoriteItemsMixin, FeedItemsMixin, AdsMixin, TemplateView):
    """Главная страница."""
    template_name = 'pages/index.html'
    model = Issue
    context_object_name = 'index'

    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)
        issue = False
        try:
            issue = self.model.objects.filter(status='active').latest(
                'published_at')
        except Issue.DoesNotExist as e:
            logger.warning(
                'Not found active Issue for index page: {}'.format(str(e)))

        items = []
        if issue:
            qs = issue.item_set.filter(status='active')
            items = qs.order_by('-section__priority', '-priority')

        context.update({
            'issue': issue,
            'items': items,
            'active_menu_item': 'index',
        })
        return context


class FriendsView(TemplateView):
    template_name = 'pages/friends.html'

    def get_context_data(self, **kwargs):
        context = super(FriendsView, self).get_context_data(**kwargs)
        context['active_menu_item'] = 'friends'
        return context


class ViewEditorMaterial(TemplateView):
    template_name = 'old/editor_material_view.html'

    def get_context_data(self, **kwargs):
        section = kwargs.get('section', 'landing')
        slug = kwargs.get('slug')

        material = get_object_or_404(EditorMaterial,
                                     slug=slug,
                                     section=section,
                                     status='active')

        return {'material': material}
            'material': material
        }

class ItemView(DetailView):
    """
    Просмотр отдельной новости

<MSG> Merge pull request #66 from Krukov/fixes

PEP-8  и мелкие фиксы
<DFF> @@ -197,6 +197,7 @@ class ViewEditorMaterial(TemplateView):
             'material': material
         }
 
+
 class ItemView(DetailView):
     """
     Просмотр отдельной новости

{'addition_count': 1, 'commit_subject': 'Merge pull request #66 from Krukov/fixes', 'deletion_count': 0, 'file_extension': '.py', 'lang': 'py', 'license': 'mit', 'repo_name': 'pythondigest/pythondigest'}