示例#1
0
def homepage(request):
    try:
        issue, cache_key = check_smart_cache(request, 'homepage_view')
        if not issue:
            issue = Issue.objects.filter(published=True).latest('published_at')

            cache.set(cache_key, issue)
            cache.set('%s.stale' % cache_key, STALE_CREATED)
            update_cache_dependency(request, issue, cache_key)

        return render(request, ['homepage/%s' % issue.display_type.template_name, 'homepage/default'], {'issue': issue})
    except Issue.DoesNotExist:
        return render(request, ['homepage/default'])
示例#2
0
 def render(self, context):
     # Build a unicode key for this fragment and all vary-on's.
     args = [self.fragment_name] + \
         [force_unicode(resolve_variable(var, context)) for var in self.vary_on]
     value, cache_key = check_smart_cache(context['request'], *args)
     if value is None:
         context.push()
         context['cache_key'] = cache_key
         value = self.nodelist.render(context)
         context.pop()
         cache.set(cache_key, value, self.expire_time)
         cache.set('%s.stale' % cache_key, STALE_CREATED, self.stale_time)
         obj = resolve_variable(self.cache_obj, context) if self.cache_obj else None
         update_cache_dependency(context['request'], obj, cache_key)
     return value
示例#3
0
def article_detailed(request, section=None, slug=None, year=None, month=None, day=None, template=None):
    article, cache_key = check_smart_cache(request, 'article_view', slug, year, month, day)
    if not article:
        kwargs = {'section__full_path': section,
                  'slug': slug}
        if year and month and day:
            kwargs['published_at__year'] = int(year)
            kwargs['published_at__month'] = int(month)
            kwargs['published_at__day'] = int(day)
        if not request.user.is_superuser:
            kwargs['status__published'] = True
        article = Article.objects.get(**kwargs)

        cache.set(cache_key, article)
        cache.set('%s.stale' % cache_key, STALE_CREATED)
        update_cache_dependency(request, article, cache_key)

    return render(request, [template, 'articles/%s/%s' % (article.section.path, article.display_type.template_name), 'articles/%s' % article.display_type.template_name, 'articles/%s' % settings.DISPLAY_TYPE_TEMPLATE_FALLBACK], {'article': article})