Ejemplo n.º 1
0
def user_profile(request, user_id):
    ref = request.META.get('HTTP_REFERER')
    try:
        visited_user = User.objects.get(pk=int(user_id))
        fav = Favorites.objects.filter(user=request.user,
                                       favorite=visited_user)
        try:
            photo = Photo.objects.get(user=visited_user)
            data = pre_fill_profile(request.user)
            form = ProfileForm(data)
            return render_to_response(
                'users/details.html', {
                    'visited_user': visited_user,
                    'fav': fav,
                    'ref': ref,
                    'form': form,
                    'photo': photo
                }, RequestContext(request))
        except Photo.DoesNotExist:
            data = pre_fill_profile(request.user)
            form = ProfileForm(data)
            return render_to_response('users/details.html', {
                'visited_user': visited_user,
                'fav': fav,
                'ref': ref,
                'form': form
            }, RequestContext(request))
    except User.DoesNotExist:
        request.user.message_set.create(
            message="L'utilisateur demandé n'existe pas.")
        return HttpResponseRedirect(ref)
Ejemplo n.º 2
0
def user_profile(request,user_id):
    ref = request.META.get('HTTP_REFERER')
    try:
        visited_user = User.objects.get(pk=int(user_id))
        fav = Favorites.objects.filter(user=request.user,favorite=visited_user)
        try:
            photo = Photo.objects.get(user=visited_user)
            data = pre_fill_profile(request.user)
            form = ProfileForm(data)
            return render_to_response('users/details.html',{'visited_user':visited_user,'fav':fav,'ref':ref,'form':form,'photo':photo},RequestContext(request))
        except Photo.DoesNotExist:
            data = pre_fill_profile(request.user)
            form = ProfileForm(data)
            return render_to_response('users/details.html',{'visited_user':visited_user,'fav':fav,'ref':ref,'form':form},RequestContext(request))
    except User.DoesNotExist:
        request.user.message_set.create(message="L'utilisateur demandé n'existe pas.")
        return HttpResponseRedirect(ref)
Ejemplo n.º 3
0
def edit_profile(request):
    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            request.user.first_name = form.cleaned_data['first_name']
            request.user.last_name = form.cleaned_data['last_name']
            request.user.email = form.cleaned_data['email']
            request.user.save()
            request.user.message_set.create(
                message="Vos informations personnelles ont bien été modifiées."
            )
            return HttpResponseRedirect('/users/%d/' % request.user.id)
        else:
            try:
                photo = Photo.objects.get(user=request.user)
                return render_to_response('users/details.html', {
                    'form': form,
                    'photo': photo,
                    'visited_user': request.user
                }, RequestContext(request))
            except Photo.DoesNotExist:
                return render_to_response('users/details.html', {
                    'form': form,
                    'visited_user': request.user
                }, RequestContext(request))
    else:
        data = pre_fill_profile(request.user)
        form = ProfileForm(data)
        try:
            photo = Photo.objects.get(user=request.user)
            return render_to_response('users/details.html', {
                'form': form,
                'photo': photo,
                'visited_user': request.user
            }, RequestContext(request))
        except Photo.DoesNotExist:
            return render_to_response('users/details.html', {
                'form': form,
                'visited_user': request.user
            }, RequestContext(request))
Ejemplo n.º 4
0
def edit_profile(request):
    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            request.user.first_name = form.cleaned_data['first_name']
            request.user.last_name = form.cleaned_data['last_name']
            request.user.email = form.cleaned_data['email']
            request.user.save()
            request.user.message_set.create(message="Vos informations personnelles ont bien été modifiées.")
            return HttpResponseRedirect('/users/%d/'%request.user.id)
        else:
            try:
                photo = Photo.objects.get(user=request.user)
                return render_to_response('users/details.html', {'form':form,'photo':photo,'visited_user':request.user}, RequestContext(request))
            except Photo.DoesNotExist:
                return render_to_response('users/details.html', {'form':form,'visited_user':request.user}, RequestContext(request))
    else:
        data = pre_fill_profile(request.user)
        form = ProfileForm(data)
        try:
            photo = Photo.objects.get(user=request.user)
            return render_to_response('users/details.html', {'form':form,'photo':photo,'visited_user':request.user}, RequestContext(request))
        except Photo.DoesNotExist:
            return render_to_response('users/details.html', {'form':form, 'visited_user':request.user}, RequestContext(request))