Пример #1
0
def add(request):
    if request.is_ajax() or True:
        try:
            friend = User.objects.get(pk=request.GET["id"])
        except User.DoesNotExist:
            raise Http404

        try:
            Friends.objects.get(Q(user=request.user, friend=friend) | Q(user=friend, friend=request.user))
        except Friends.DoesNotExist:
            # Save new request
            f = Friends(user=request.user, friend=friend)
            f.save()

            # Send notification
            NotificationSystem.create(friend, const.NotifConst.FRIEND_REQ)

            return HttpResponse("OK")
        else:
            return HttpResponse("ERR")
Пример #2
0
def _notify(request):
  prof.start('comment-notify')
  comments = Comments.objects.filter(news=request.GET['news_id']).exclude(user=request.user)
  # Notify all the people we need to
  news = News.objects.filter(id=request.GET['news_id']).select_related('user', 'about_id')
  for n in news:
    # Should be only one actually
    if n.user != request.user:
      comments = comments.exclude(user=n.user)
      NotificationSystem.create(n.user, const.NotifConst.NEW_COMMENT_GOSSIP_MINE,
                                {'username': request.user.username,
                                'name': prettyuser.user_or_first_name(request.user),
                                'news_id': request.GET['news_id'],
                                })
    elif n.about_id and n.about_id != request.user:
      comments = comments.exclude(user=n.about_id)
      NotificationSystem.create(n.about_id, const.NotifConst.NEW_COMMENT_GOSSIP_ME,
                                {'username': request.user.username,
                                'name': prettyuser.user_or_first_name(request.user),
                                'news_id': request.GET['news_id'],
                                })
  participants = User.objects.filter(id__in=comments.distinct().values('user'))
  for participant in participants:
    NotificationSystem.create(participant, const.NotifConst.NEW_COMMENT_GOSSIP,
                              {'username': request.user.username,
                              'name': prettyuser.user_or_first_name(request.user),
                              'news_id': request.GET['news_id'],
                              })
  prof.stop('comment-notify')
Пример #3
0
def confirm(request):
    if request.is_ajax() or True:
        if not ("confirm" in request.GET and "id" in request.GET):
            raise Http404

        try:
            friend = User.objects.get(pk=request.GET["id"])
        except User.DoesNotExist:
            raise Http404

        try:
            friendship = Friends.objects.get(user=friend, friend=request.user)
            if friendship.accepted or friendship.ignored:
                return HttpResponse("ERR")

            if request.GET["confirm"] == "accept":
                friendship.accepted = True
                friendship.ignored = False
                friendship.email_sent = True

                # Send an e-mail
                NotificationSystem.create(
                    friend,
                    const.NotifConst.FRIEND_CONFIRM,
                    {"username": friend.username, "name": prettyuser.user_or_first_name(friend)},
                )
            else:
                friendship.accepted = False
                friendship.ignored = True
                friendship.email_sent = True

            friendship.save()
        except Friends.DoesNotExist:
            raise Http404

        return HttpResponse("OK")