Esempio n. 1
0
 def update_share_friends(self):
     if not rc.get('update_share_friends_' + str(self.user_id)):
         now = datetime.now()
         today = datetime.today()
         time_pass = (now - datetime(year=today.year, month=today.month, day=today.day)).seconds
         seconds_left = 24*3600 - time_pass
         rc.set('update_share_friends_' + str(self.user_id), '1', seconds_left)
         CreditCoin(self).add_shared_task()
Esempio n. 2
0
    def create(self, request, *args, **kwargs):
        token = request.token_data
        user_id = token['user_id']
        number = token['number']
        serializer = ArticleNewSerializer(data=request.data, user_id=user_id)
        serializer.is_valid(raise_exception=True)
        data = serializer.validated_data

        content = data['content']
        art_type = data.get('art_type', 0)
        loan_amount = data.get('loan_amount')
        loan_time = data.get('loan_time')
        loan_contact = data.get('loan_contact')

        create_key = 'topics_views_create' + str(user_id)
        if rc.get(create_key):
            raise ValidationError({'msg': '发帖间隔时间过短,请不要刷屏哦'})

        review_t = TimeConfig.objects.get(name='article')
        rc.set(create_key, 1, review_t.article_gap)

        art_default = {
            'art_type': art_type,
            'loan_amount': loan_amount,
            'loan_time': loan_time,
            'loan_contact': loan_contact,
            'number': number
        }

        art = Article.objects.create(user=user_id,
                                     content=content,
                                     **art_default)
        thumbed = art.has_thumbed(user_id)
        ret = ArticleSerializer(art).data
        ret['thumbed'] = thumbed
        url = INTENAL_BASE + reverse('review', args=(art.id, ))
        send_task('text_review', art.id, content, 'art', url)
        return Response(ret)
Esempio n. 3
0
    def comment(self, request, pk):
        serializer = CommentNewSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        data = serializer.validated_data

        token = request.token_data
        user_id = token['user_id']
        number = token['number']
        content = data['content']

        create_key = 'topics_views_comment' + str(user_id)
        if rc.get(create_key):
            raise ValidationError({'msg': '发帖间隔时间过短,请不要刷屏哦'})

        review_t = TimeConfig.objects.get(name='article')
        rc.set(create_key, 1, review_t.article_gap)

        try:
            art = Article.objects.get(id=pk)
        except Article.DoesNotExist:
            raise ValidationError({'msg': '对象不存在'})
        cmt = None
        comment_id = data.get('comment_id')
        if comment_id:
            try:
                cmt = Comment.objects.get(id=comment_id)
            except Comment.DoesNotExist:
                raise ValidationError({'msg': '对象不存在'})

        comment = Comment.objects.create(user=user_id,
                                         content=content,
                                         article=art,
                                         comment=cmt,
                                         number=number)
        url = INTENAL_BASE + reverse('review', args=(comment.id, ))
        send_task('text_review', comment.id, content, 'comment', url)
        return Response({'status': 1})
Esempio n. 4
0
 def update_got_once_ever(self, coupon_id):
     rc.set('update_got_once_ever_%s_%s' % (self.user_id, coupon_id), 1)
     if self.identification:
         rc.set('update_got_once_ever_%s_%s' % (self.identification, coupon_id), 1)
Esempio n. 5
0
 def update_got_once_year(self, coupon_id):
     rc.set('update_got_once_year_%s_%s' % (self.user_id, coupon_id), 1, 364*24*3600)
     if self.identification:
         rc.set('update_got_once_year_%s_%s' % (self.identification, coupon_id), 1, 364*24*3600)