예제 #1
0
 def test_notification(self):
     """单个通知"""
     Notification.objects.mark_all_as_read()
     obj = News.objects.create(user=self.user, content="内容示例", reply=True)
     notification_handler(self.other_user, self.user, "C",
                          obj)  # other_user评论了user
     assert Notification.objects.unread().count() == 1
예제 #2
0
 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')
예제 #3
0
파일: views.py 프로젝트: yktimes/wenhu
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"})
예제 #4
0
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)
예제 #5
0
 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')
예제 #6
0
파일: views.py 프로젝트: yktimes/wenhu
def notify_comment(**kwargs):
    """文章有评论时通知作者"""
    actor = kwargs['request'].user
    obj = kwargs['comment'].content_object

    notification_handler(actor, obj.user, 'C', obj)