def perform_create(self, serializer): instance = serializer.save() q = Question.objects.filter(id=serializer.data['question']) print(q[0].user.username) if q: if q[0].user.username != self.request.user.username: print(self.request.user, q[0].user) notification_handler(self.request.user, q[0].user, 'A', q[0])
def reply_this(self, user, text): parent = self.get_parent() News.objects.create(user=user, content=text, reply=True, parent=parent) notification_handler(user, parent.user, 'R', parent, id_value=str(parent.uuid_id), key='social_update')
def notify_comment(**kwargs): """ 文章有评论时通知作者 :param kwargs: :return: """ actor = kwargs['request'].user obj = kwargs['comment'].comtent_object notification_handler(actor, obj, 'c', obj)
def perform_create(self, serializer): new_instance = serializer.save() if new_instance.reply: parent = new_instance.parent if new_instance.parent else new_instance notification_handler(new_instance.user, parent.user, 'R', parent, id_value=str(parent.uuid_id), key='social_update')
def switch_like(self, user): """点赞/取消点赞, 这里的动作是由某一个用户去执行的""" if user in self.liked.all(): # self.liked.all()==> 所有赞过的用户,self.liked==>多对多外键字段 # 如果用户已经赞过,则取消赞 self.liked.remove(user) else: # 如果用户没有赞过,则添加赞 self.liked.add(user) # 通知楼主 notification_handler(user, self.user, "L", self, id_value=str(self.uuid_id), key="social_update")
def perform_update(self, serializer): """do what switch like do""" new_instance = serializer.save() if new_instance.user.username != self.request.user.username and\ self.request.user in new_instance.liked.all(): notification_handler(self.request.user, new_instance.user, 'L', new_instance, id_value=str(new_instance.uuid_id), key='social_update')
def accept_answer(request): """ 接受回答,AJAX POST请求 已经被接受的回答用户不能取消 """ answer_id = request.POST["answer"] answer = Answer.objects.get(pk=answer_id) # 如果当前登录用户不是提问者,抛出权限拒绝错误 if answer.question.user.username != request.user.username: raise PermissionDenied answer.accept_answer() notification_handler(request.user, answer.user, 'W', answer) return JsonResponse({'status': 'true'}, status=200)
def switch_like(self, user): ''' 点赞或者取消赞 ''' if user in self.liked.all(): self.liked.remove(user) else: self.liked.add(user) notification_handler(user, self.user, 'L', self, id_value=str(self.uuid_id), key='social_update')
def switch_like(self, user): """点赞或取消赞""" if user in self.liked.all(): # 如果用户已经赞过,则取消赞 self.liked.remove(user) else: # 如果用户没有赞过,则添加赞 self.liked.add(user) # 通知楼主,给自己点赞时不通知 if user.username != self.user.username: notification_handler(user, self.user, 'L', self, id_value=str(self.uuid_id), key='social_update')
def reply_this(self, user, text): """ 回复首页的动态 :param user: 登录的用户 :param text: 回复的内容 :return: None """ parent = self.get_parent() News.objects.create(user=user, content=text, reply=True, parent=parent) # 通知楼主 notification_handler(user, parent.user, 'R', parent, id_value=str(parent.uuid_id), key='social_update')
def perform_create(self, serializer): """文章有評論時通知作者""" comment = serializer.save(user=self.request.user) actor = self.request.user obj = comment.content_object notification_handler(actor, obj.user, 'C', obj, id_value=obj.slug)
def notify_comment(**kwargs): '''文章有评论通知作者 ''' actor = kwargs['request'].user obj = kwargs['comment'].content_object notification_handler(actor, obj.user, 'C', 'obj')