Beispiel #1
0
def add_friend(request):
    from_user=request.user
    if request.GET.has_key('username'):
        username=request.GET['username']
        
        
        
        to_user=get_object_or_404(User,username=username)
        
        
        friendship = None
        created=False
        
        try :
            friendship=Friendship.objects.get(from_friend=from_user,to_friend=to_user)
        except ObjectDoesNotExist :
            try :
                friendship=Friendship.objects.get(from_friend=to_user,to_friend=from_user)
            except ObjectDoesNotExist :
                friendship=Friendship(from_friend=from_user,to_friend=to_user)
                created=True
        
        
        if not created:
            friendship.invite_status=True
            
        
        friendship.save()       
        
    if request.META.has_key("HTTP_REFERER"):
        return HttpResponseRedirect(request.META['HTTP_REFERER'])
    
    return HttpResponseRedirect("/")
def friend_add(request):
    if 'username' in request.GET.keys():
        friend = get_object_or_404(User, username=request.GET['username'])
        friendship = Friendship(from_friend=request.user, to_friend=friend)
        friendship.save()
        return HttpResponseRedirect('/friends/{}/'.format(request.user.username))
    else:
        raise Http404('user not found')
Beispiel #3
0
def register_page(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.cleaned_data['username'],
                password=form.cleaned_data['password1'],
                email=form.cleaned_data['email'])
            if 'invitation' in request.session:
                # Retrieve the invitation object.
                invitation = \
                    Invitation.objects.get(id=request.session['invitation'])
                # Create friendship from user to sender.
                friendship = Friendship(from_friend=user,
                                        to_friend=invitation.sender)
                friendship.save()
                # Create friendship from sender to user.
                friendship = Friendship(from_friend=invitation.sender,
                                        to_friend=user)
                friendship.save()
                # Delete the invitation from the database and session.
                invitation.delete()
                del request.session['invitation']
            return HttpResponseRedirect('/register/success/')
    else:
        form = RegistrationForm()
    context = {'form': form}
    return render(request, 'registration/register.html', context)
Beispiel #4
0
def friend_add(request):
    if 'username' in request.GET:
        friend = get_object_or_404(User, username=request.GET['username'])
        friendship = Friendship(
            from_friend=request.user,
            to_friend=friend
        )
        try:
            friendship.save()
            messages.add_message(request, messages.INFO,
                                 u'%s를 친구로 추가했습니다.' % friend.username
                                 )
        except:
            messages.add_message(request, messages.INFO,
                                 u'%s는 이미 친구입니다.' % friend.username
                                 )
        return HttpResponseRedirect(
            '/friends/%s/' % request.user.username
        )
    else:
        raise Http404
def register_page(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.cleaned_data['username'],
                email=form.cleaned_data['email'],
                password=form.cleaned_data['password1']
            )
            if 'invitation' in request.session:
                #Retrieve the invitation object
                invitation = Invitation.objects.get(id=request.session['invitation'])
                #Create friendship from user to sender
                friendship = Friendship(from_friend=user, to_friend=invitation.sender)
                friendship.save()
                #Create friendship from sender to user
                friendship = Friendship(from_friend=invitation.sender, to_friend=user)
                friendship.save()
                #Delete the invitation from the database
                invitation.delete()
                del request.session['invitation']
            return HttpResponseRedirect('/register/success/') 
    else:
        form = RegistrationForm()
        print(form.as_p())
    variables = RequestContext(request, {'form' : form})
    return render_to_response('registration/register.html', variables)
Beispiel #6
0
def friend_add(request):
	if 'username' in request.GET:
		friend = get_object_or_404(User,username=request.GET['username'])
		
		friendship = Friendship(from_friend=request.user,to_friend=friend)
		friendship.save()
		
		reverse_friendship = Friendship(from_friend=friend,to_friend=request.user)
		reverse_friendship.save()
		
		return HttpResponseRedirect('/friends/%s/' % request.user.username)
		
	else:
		raise Http404