Ejemplo n.º 1
0
def friends(request, username):
    user = get_object_or_404(User, username=username)
    context = {
        'friends': Friend.get_friends(user.id),
        'pending_friends': Friend.get_pending_friends(user.id),
        'profile': user,
    }
    return render(request, 'users/friends.html', context)
Ejemplo n.º 2
0
    def form_valid(self, form):
        friend = Friend(name=form.cleaned_data['name'],
                        mug_shot=form.cleaned_data['mug_shot'])
        friend.save()

        self.create_friend_accomplishments(form, 'has_accomplished', 'friend',
                                           friend, 'accomplishment')

        return HttpResponseRedirect(self.success_url)
Ejemplo n.º 3
0
def change_friends(request, operation, pk, home):
    user = User.objects.get(pk=pk)
    if operation == 'add':
        Friend.make_friend(request.user, user)
    elif operation == 'remove':
        Friend.lose_friend(request.user, user)
    if (home == 'no'):
        return HttpResponseRedirect("/posts/by/{}".format(user.username))
    else:
        return HttpResponseRedirect("/")
Ejemplo n.º 4
0
def add_or_remove_friends(request, username, verb):
    n_f = get_object_or_404(User, username=username)
    owner = request.user.userprofile
    new_friend = UserProfile.objects.get(user=n_f)

    if verb == "add":
        Friend.make_friend(owner, new_friend)
    else:
        Friend.remove_friend(owner, new_friend)
    return redirect("friends:friend-list")
Ejemplo n.º 5
0
def profile(request, username):
    user = get_object_or_404(User, username=username)

    context = {
        'friends': Friend.get_friends(user.id),
        'games': UserGame.get_games(user.id),
        'profile': user,
        'pending_friends': Friend.get_pending_friends(user.id),
    }

    return render(request, 'users/profile.html', context)
Ejemplo n.º 6
0
def accept_friend_request(request, friend_id):
    context = RequestContext(request)
    a = Author.objects.get(user = request.user)
    context_dict = {}

    friendRequest = FriendRequest.objects.get(author = a, friend_guid = friend_id)
    if friendRequest is not None:
        new_friend = Friend(friend_name=friendRequest.friend_name, host=friendRequest.host, friend_guid=friendRequest.friend_guid, author=a)
        new_friend.save()
        friendRequest.delete()

    return HttpResponseRedirect('/friends')
def load_friend(info):
    address = get_or_load_address(info)
    new_user = User(username=info.get('csq:username'),
                    first_name=info.get('givenName'),
                    last_name=info.get('familyName'))
    if info.has_key('email'):
        new_email.email = info.get('email')
    new_email.save()
    new_friend = Friend(category=category.get(
        info.get('csq:category').get('csq:code').lower()),
                        postal_address=address,
                        user=new_user)
    new_friend.save()
Ejemplo n.º 8
0
 def update(self, inst, valid_data):
     x = valid_data.get('x', inst.x)
     y = valid_data.get('y', inst.y)
     min_pos, max_pos = Friend.world_size()
     inst.x = x if x <= max_pos and x >= min_pos else inst.x
     inst.y = y if y <= max_pos and y >= min_pos else inst.y
     inst.save()
     return inst
Ejemplo n.º 9
0
    def get_or_create_object(self):
        me = Friend.objects.filter(me=True).first()
        if not me:
            x = Friend.random_position()
            y = Friend.random_position()
            me = Friend(x=x, y=y, me=True)
            me.save()
            me.generate_friends()

        return me
Ejemplo n.º 10
0
def add_friend(request, author_guid):
    context = RequestContext(request)

    try:
        u = User.objects.get(username=author_guid)
        a = Author.objects.get(user=u)
    except User.DoesNotExist:
        a = Author.objects.get(guid=author_guid)
        u = a.user

    context_dict = {'author': a}

    if request.method == "POST":
        new_friend_name = request.POST['friend_name']
        new_friend_guid = request.POST['friend_guid']
        new_friend_location = request.POST['friend_location']

        # If it is blank, it will be localhost
        if not new_friend_location:
            new_friend_location = settings.ALLOWED_HOSTS[0]

        # Integrity check, are they trying to give us an invalid host?
        if new_friend_location in settings.ALLOWED_HOSTS:

            if not Friend.objects.filter(author=a, friend_guid=new_friend_guid):

                # Try aren't a friend already
                print "Not a friend already!"
                # Send the friend request
                if( new_friend_location == settings.ALLOWED_HOSTS[0] ): # Local
                    friended_author = Author.objects.get( guid=new_friend_guid )
                    
                    new_friend_request = FriendRequest( author=a, friend_name=friended_author.get_full_name(), host=friended_author.host, friend_guid=friended_author.guid, author_guid=friended_author.guid )
                    new_friend_request.save()
                else: #Remote
                    remote_author_json = { "author": { "id": new_friend_guid, "host": new_friend_location, "displayname": new_friend_name }, "friend": a.json() }
                    r = requests.post("%s/api/friendrequest"%(new_friend_location), data=remote_author_json)
                    print "Remote friend request reponse code: %s" % (r.status_code)

            if request.user.is_authenticated():
                friendingAuthor = Author.objects.get(guid = new_friend_guid)
                new_friend = Friend(friend_name=a.get_full_name(), host=settings.ALLOWED_HOSTS[0], friend_guid=a.guid, author=friendingAuthor)
                new_friend.save()

    return HttpResponseRedirect('/friends/')
Ejemplo n.º 11
0
def removeFriend(request):
    form = CustomUserDetailsForm(request.POST)
    serializer = UserSerializer(request.user, many=False)
    print('[requestFriend] - User <', serializer.data['username'],
          '> is trying to remove friend:', request.POST.get('username', ''))

    if form.is_valid():
        new_friend = CustomUser.objects.get(
            username=form.cleaned_data['username'])
        Friend.remove_friend(request.user, new_friend)

        return Response({
            "success": "true",
            "current_user": serializer.data['username']
        })

    print("Form errors: ", form.errors)
    return HttpResponse(status=500)
Ejemplo n.º 12
0
    def get(self, request):
        Friend.objects.all().delete()

        x = Friend.random_position()
        y = Friend.random_position()
        me = Friend(x=x, y=y, me=True)
        me.save()
        me.generate_friends()

        me_serialized = FriendSerializer(me)

        return Response(me_serialized.data)
Ejemplo n.º 13
0
def set_user(request):
    '''Set the user, save it to the database if needed and redirect'''

    # get query data
    fn = request.GET.get('first_name').capitalize()
    ln = request.GET.get('last_name').capitalize()

    # check if the the user is in the database, add him if not
    if len(Friend.objects.filter(first_name=fn, last_name=ln)) == 0:
        user = Friend(first_name=fn, last_name=ln)
        user.save()
    else:
        user = get_object_or_404(Friend, first_name=fn, last_name=ln)

    # save primary key to the session
    request.session['pk'] = user.pk

    # and redirect
    return redirect('friends')
Ejemplo n.º 14
0
 def update(self, inst, valid_data):
     x = valid_data.get('x', inst.x)
     y = valid_data.get('y', inst.y)
     min_pos, max_pos = Friend.world_size()
     inst.x = x if x <= max_pos and x >= min_pos else inst.x
     inst.y = y if y <= max_pos and y >= min_pos else inst.y
     inst.distance = Friend.objects.filter(
         me=True
     ).first().distance_from(inst.x, inst.y)
     inst.save()
     return inst
Ejemplo n.º 15
0
    def get_or_create_object(self):
        me = Friend.objects.filter(me=True).first()
        if not me:
            x = Friend.random_position()
            y = Friend.random_position()
            me = Friend(x=x, y=y, me=True)
            me.save()
            me.generate_friends()

        return me
Ejemplo n.º 16
0
def add_friend(request):
    '''Handle add friends form'''

    user = get_object_or_404(Friend, pk=request.session['pk'])

    # get friend to add
    fn = request.POST.get('first_name').capitalize()
    ln = request.POST.get('last_name').capitalize()

    # check if the the friend is in the database, add him if not
    if len(Friend.objects.filter(first_name=fn, last_name=ln)) == 0:
        friend = Friend(first_name=fn, last_name=ln)
        friend.save()
    else:
        friend = Friend.objects.get(first_name=fn, last_name=ln)

    # add the friend to the user
    user.friends.add(friend)

    # and redirect
    return redirect('friends')
Ejemplo n.º 17
0
    def get(self, request):
        Friend.objects.all().delete()

        x = Friend.random_position()
        y = Friend.random_position()
        me = Friend(x=x, y=y, me=True)
        me.save()
        me.generate_friends()

        me_serialized = FriendSerializer(me)

        return Response(me_serialized.data)
Ejemplo n.º 18
0
def counters_unseen_summarize(user):
    """
    Summarize items that user does not seen. These uses in mobile app icon
    Counted data:
        - unseen post likes
        - unseen new friends
        - unseen post post comments
        - unseen messages
    :return: sum of unseen items for specific user
    """
    from friends.models import Friend
    from news.models import Like, Comment
    from user_messages.models import Dialog

    likes = Like.get_count_unseen(user)
    comments = Comment.get_count_unseen(user)
    new_friends = Friend.get_count_unseen(user)
    messages = Dialog.get_count_unread_messages(user)
    return sum([likes, comments, new_friends, messages])
Ejemplo n.º 19
0
    def create(self, valid_data):
        x = valid_data.get('x')
        y = valid_data.get('y')
        if x is None or y is None:
            return None
        min_pos, max_pos = Friend.world_size()
        if x > max_pos or x < min_pos:
            return None
        if y > max_pos or y < min_pos:
            return None

        me = Friend.objects.filter(me=True).first()

        distance = me.distance_from(x, y)

        friend = Friend(x=x, y=y, distance=distance)

        me.add_friend(friend)

        return friend
Ejemplo n.º 20
0
def create_friend(request):
    name = request.POST['name']
    sex = request.POST['sex']
    age = request.POST['age']
    phone = request.POST['phone']
    email = request.POST['email']
    live = request.POST['live']
    address = request.POST['address']
    mark = request.POST['mark']

    friend = Friend()
    friend.name = name
    friend.sex = sex
    friend.age = age
    friend.phone = phone
    friend.email = email
    friend.live = live
    friend.address = address
    friend.mark = mark
    friend.save()

    # return HttpResponse("This data has been saved ok! Thanks.")
    return get_all_friends(request)
Ejemplo n.º 21
0
def friend_request_send(request):
    if request.method == 'POST':
        friend_id = request.POST['friend_id']
        Friend.add_friends(request.user.id, friend_id)

    return redirect('accounts:profile')
Ejemplo n.º 22
0
def friend_remove(request):
    Friend.remove_friends(request.user.id, request.POST['friend_id'])
    return redirect('accounts:profile')
Ejemplo n.º 23
0
def friend_request_reject(request):
    if request.method == 'POST':
        Friend.reject_friend(request.user.id, request.POST['friend_id'])
    return redirect('accounts:profile')
Ejemplo n.º 24
0
 def add_friend(user, friend):
     friend_entry = Friend()
     friend_entry.user = user
     friend_entry.friend = friend
     friend.save()
Ejemplo n.º 25
0
 def post(self, request, *args, **kwargs):
     user = request.user
     receiver = self.get_object()
     friend_request = Friend(sender=user, receiver=receiver)
     friend_request.save()
     return Response(self.get_serializer(friend_request).data)
Ejemplo n.º 26
0
def search_friends_games(request):
    if request.method == 'GET':
        context = {'results': Friend.search_friends_games(request.user.id, request.GET['search'])}
        return render(request, "search_games.html", context)