Exemple #1
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)
Exemple #2
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
Exemple #3
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
Exemple #4
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')
Exemple #5
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)
Exemple #6
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)
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()
Exemple #8
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/')
Exemple #9
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')
Exemple #10
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')
Exemple #11
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)
Exemple #12
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)