Пример #1
0
 def get_object(self, queryset=None):
     obj = super(ArticleDetailView, self).get_object()
     # 未发表文章不能显示
     if obj.status == 'd' and not self.request.user.is_superuser:
         raise Http404
     add_views_or_likes(target_article=obj, views_or_likes='views')
     obj.save()
     # obj.body = markdown2.markdown(
         # obj.body, ['codehilite'], extras=['fenced-code-blocks'])
     obj.attachment_url = obj.attachment_url.split('/')
     client_ip, referer = get_client_ip(self.request)
     save_client_ip.delay(client_ip, obj.id, referer=referer)
     logger.debug("get article: %s", self.kwargs[self.pk_url_kwarg])
     return obj
Пример #2
0
 def get_queryset(self):
     # models中已经定义了meta类,所以可以不用.order_by('name')
     # request在self中已经传入
     if self.request.user.is_superuser:
         article_list = Article.objects.filter(
             created_time__lte=timezone.now())
     else:
         article_list = Article.objects.filter(
             created_time__lte=timezone.now(), status='p')
     client_ip, referer = get_client_ip(self.request)
     save_client_ip.delay(client_ip, referer=referer)
     # cache.set('tcdlejl', 'value', timeout=100)
     # logging.info(cache.get('tcdlejl'))
     return article_list
Пример #3
0
 def get_queryset(self):
     # models中已经定义了meta类,所以可以不用.order_by('name')
     # request在self中已经传入
     if self.request.user.is_superuser:
         article_list = Article.objects.filter(
             created_time__lte=timezone.now())
     else:
         article_list = Article.objects.filter(
             created_time__lte=timezone.now(), status='p')
     client_ip, referer = get_client_ip(self.request)
     save_client_ip.delay(client_ip, referer=referer)
     # cache.set('tcdlejl', 'value', timeout=100)
     # logging.info(cache.get('tcdlejl'))
     return article_list
Пример #4
0
    def get_object(self, queryset=None):
        obj = super(ArticleDetailView, self).get_object()
        # 未发表文章不能显示
        if obj.status == 'd':
            raise Http404
        add_views_or_likes(target_article=obj, views_or_likes='views')
        obj.save()
        obj.body = markdown2.markdown(
            obj.body, ['codehilite'], extras=['fenced-code-blocks'])
        obj.attachment_url = obj.attachment_url.split('/')
        client_ip = get_client_ip(self.request)
        save_client_ip.delay(client_ip, obj.id)

        return obj