Пример #1
0
def index(request):
    if "p" in request.GET:
        try:
            user_id = int(request.GET["p"])
        except ValueError:
            raise Http404
        else:
            try:
                user = User.objects.get(pk=user_id)
            except User.DoesNotExist:
                raise Http404
        friendships = None
    else:
        user = request.user
        # Displaying the waiting friendships...
        NotificationSystem.receipt(request.user, const.NotifConst.FRIEND_REQ)
        friendships = Friends.objects.filter(Q(friend=request.user)).filter(accepted=False).filter(ignored=False)

    prof.start("profile-stats")
    total_friends = Friends.objects.filter(Q(friend=user) | Q(user=user)).filter(accepted=True).count()
    total_women = (
        Friends.objects.filter(friend=user).filter(accepted=True).filter(user__profile__gender=1).count()
        + Friends.objects.filter(user=user).filter(accepted=True).filter(friend__profile__gender=1).count()
    )
    total_waiting = (
        Friends.objects.filter(Q(friend=user) | Q(user=user)).filter(accepted=False).filter(ignored=False).count()
    )
    total_ignored = Friends.objects.filter(Q(friend=user) | Q(user=user)).filter(ignored=True).count()
    prof.stop("profile-stats")

    return render_to_response(
        "friends/index.html",
        {
            "js": ("friends.js", "news.js", "jquery-multifile.js", "jquery-ui.js", "jquery-form.js"),
            "css": ("ui/ui.css",),
            "curr_page": "friends-index",
            "stats": {
                "total": total_friends,
                "women": total_women,
                "men": total_friends - total_women,
                "waiting": total_waiting,
                "ignored": total_ignored,
            },
            "req_user": user,
            "form_add_news": AddNewsInlineForm(),
            "friendships": friendships,
        },
        context_instance=RequestContext(request),
    )
Пример #2
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")
Пример #3
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')
Пример #4
0
def index(request):
  req_news = False
  if 'n' in request.GET:
    try:
      int(request.GET['n'])
    except ValueError:
      pass
    else:
      try:
        req_news = News.objects.get(id=request.GET['n'].strip())
        req_news.images = Image.objects.filter(news=req_news)
      except News.DoesNotExist:
        pass
      else:
        if 'facebookexternalhit' in request.META['HTTP_USER_AGENT']:
          return render_to_response('profile/for_facebook.html',
                                    {'req_news': req_news},
                                    context_instance=RequestContext(request))
  if request.user.is_authenticated():
    form_add_news = AddNewsInlineForm()
    profile = request.user.get_profile()
    NotificationSystem.receipt(request.user, const.NotifConst.NEW_GOSSIP_ME)
    return render_to_response('profile/index.html',
                              {'profile': profile,
                              'app_url': const.FbConst.APP_URL,
                              'curr_page': 'profile-index',
                              'add_news_about': True,
                              'form_add_news': form_add_news,
                              'js': ('news.js',
                              'jquery-multifile.js', 'jquery-ui.js',
                              'jquery-form.js'),
                              'css': ('ui/ui.css', ),
                              'req_news': req_news, },
                              context_instance=RequestContext(request))
  else:
    redirect_to = '/profile/login?next=/profile'
    if req_news:
      redirect_to += '?n=' + request.GET['n']
    return HttpResponseRedirect(redirect_to)
Пример #5
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")