Exemplo n.º 1
0
 def perform_create(self, serializer):
     redis_handle.incr(REDIS_PREFIX + 'article_comment:' +
                       str(serializer.validated_data['article'].id),
                       amount=1)
     redis_handle.incr(COUNT_PREFIX + 'comments', amount=1)
     today = datetime.date.today()
     redis_handle.hincrby(COUNT_PREFIX + 'comment', str(today), amount=1)
     serializer.save()
Exemplo n.º 2
0
 def retrieve(self, request, *args, **kwargs):
     instance = self.get_object()
     serializer = self.get_serializer(instance)
     redis_handle.incr(REDIS_PREFIX + 'view:' + str(instance.id), amount=1)
     redis_handle.incr(REDIS_PREFIX + "total_view", amount=1)
     today = date.today()
     redis_handle.hincrby(COUNT_PREFIX + 'view', str(today), amount=1)
     return Response(serializer.data)
Exemplo n.º 3
0
 def perform_create(self, serializer):
     serializer.save()
     send_mails.delay(theme='订阅通知', title=serializer.instance.title, url='http://blog.messstack.com/detail/' +
                      str(serializer.instance.id) + '/')
     category = serializer.validated_data["category"]
     category.num += 1
     category.save()
     redis_handle.incr(REDIS_PREFIX + "total_article", amount=1)
     tag = serializer.validated_data['tag']
     for i in tag:
         redis_handle.hincrby(COUNT_PREFIX + 'tag', i.tag, amount=1)
Exemplo n.º 4
0
 def update(self, request, *args, **kwargs):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     if serializer.validated_data['like']:
         redis_handle.zadd(
             REDIS_PREFIX + "article_like:" + str(kwargs['pk']),
             {request.user.id: 0})
         redis_handle.zadd(USER_PREFIX + 'like:' + str(request.user.id),
                           {kwargs['pk']: 0})
         redis_handle.incr(REDIS_PREFIX + "total_like", amount=1)
         today = datetime.date.today()
         redis_handle.hincrby(COUNT_PREFIX + 'like', str(today), amount=1)
         data = {"result": '感谢点赞'}
     else:
         redis_handle.zrem(
             REDIS_PREFIX + "article_like:" + str(kwargs['pk']),
             request.user.id)
         redis_handle.zrem(USER_PREFIX + 'like:' + str(request.user.id),
                           kwargs['pk'])
         redis_handle.incr(REDIS_PREFIX + "total_like", amount=-1)
         data = {"result": "已取消"}
     return Response(data, status=status.HTTP_200_OK)
Exemplo n.º 5
0
 def perform_create(self, serializer):
     redis_handle.incr(COUNT_PREFIX + "users", amount=1)
     today = date.today()
     redis_handle.hincrby(COUNT_PREFIX + 'user', str(today), amount=1)
     return serializer.save()
Exemplo n.º 6
0
 def perform_update(self, serializer):
     serializer.save()
     tag = serializer.validated_data.get('tag', '')
     if tag:
         redis_handle.hincrby(COUNT_PREFIX + 'tag', tag[-1].tag, amount=1)