Exemplo n.º 1
0
    def article(self, request, slug=None):
        """Magazine article page view."""

        try:
            article = ArticleHelper.get_article(request, slug)
        except:
            raise Http404('Article could not be found.')

        article.add_view()

        context = {
            'title':
            '%s - %s' % (article.headline, self.SITE_TITLE),
            'meta':
            ArticleHelper.get_meta(
                article,
                default_image=static('images/magazine/cover-social.png')),
            'article':
            article,
            'suggested':
            ArticleHelper.get_random_articles(2,
                                              'magazine',
                                              exclude=article.id),
            'base_template':
            'magazine/base.html'
        }

        t = loader.select_template([
            '%s/%s' % (article.section.slug, article.get_template_path()),
            article.get_template_path()
        ])

        return HttpResponse(t.render(context))
Exemplo n.º 2
0
    def article(self, request, slug=None):
        """Magazine article page view."""

        try:
            article = ArticleHelper.get_article(request, slug)
        except:
            raise Http404('Article could not be found.')

        article.add_view()
        year = article.tags.get(name__icontains="20").name

        magazine_title = self.mag_titles[year]

        subsection = article.subsection.name.lower() if article.subsection else ""

        # determine if user is viewing from mobile
        article_type = 'desktop'
        user_agent = get_user_agent(request)
        if user_agent.is_mobile:
            article_type = 'mobile'

        if not ArticleHelper.is_explicit(article):
            article.content = ArticleHelper.insert_ads(article.content, article_type)

        context = {
            'title': '%s - %s' % (article.headline, self.SITE_TITLE),
            'meta': ArticleHelper.get_meta(article, default_image=static('images/magazine/cover-social.png')),
            'article': article,
            'subsection': subsection,
            'specific_css': 'css/magazine-' + year + '.css',
            'suggested': ArticleHelper.get_random_articles(2, 'magazine', exclude=article.id),
            'base_template': 'magazine/base.html',
            'magazine_title': magazine_title
        }

        t = loader.select_template(['%s/%s' % (article.section.slug, article.get_template_path()), article.get_template_path()])

        return HttpResponse(t.render(context))
Exemplo n.º 3
0
    def article(self, request, section=None, slug=None):
        try:
            article = ArticleHelper.get_article(request, slug)
        except:
            raise Http404('Article could not be found.')

        article.add_view()

        ref = request.GET.get('ref', None)
        dur = request.GET.get('dur', None)

        authors_json_name = json.dumps(
            [a.person.full_name for a in article.authors.all()])

        context = {
            'title':
            '%s - %s' % (article.headline, self.SITE_TITLE),
            'meta':
            ArticleHelper.get_meta(article),
            'article':
            article,
            'reading_list':
            ArticleHelper.get_reading_list(article, ref=ref, dur=dur),
            'suggested':
            lambda: ArticleHelper.get_random_articles(
                2, section, exclude=article.id),
            'base_template':
            'base.html',
            'reading_time':
            ArticleHelper.get_reading_time(article)
        }

        template = article.get_template_path()
        t = loader.select_template([
            '%s/%s' % (article.section.slug, template), template,
            'article/default.html'
        ])
        return HttpResponse(t.render(context))