示例#1
0
def profile(request):
    profile = UserProfile.objects.get(user=request.user)
    if request.method == 'POST':
        form = ProfileForm(request.POST, instance=profile)
        if form.is_valid():
            profile = form.save(commit=False)
            profile.post_code = request.POST['zipcode']
            profile.county = request.POST['county']
            profile.district = request.POST['district']
            profile.save()

    form = ProfileForm(instance=profile)
    return render(request, 'member/profile.html', {'form': form})
示例#2
0
def profileedit(request):
    instance_a = get_object_or_404(MemberProfile, user=request.user)
    instance_b = get_object_or_404(User, pk=request.user.id)

    a = ProfileForm(request.POST or None, instance=instance_a)
    b = UserForm(request.POST or None, instance=instance_b)

    if a.is_valid() and b.is_valid():
        a.save() and b.save()
        return HttpResponseRedirect('/dashboard/account/')


    return render(request, 'member/profile-edit.html', {
        'form': a,
        'forms': b,
        })
示例#3
0
def profileedit(request):
    instance_a = get_object_or_404(MemberProfile, user=request.user)
    instance_b = get_object_or_404(User, pk=request.user.id)

    a = ProfileForm(request.POST or None, instance=instance_a)
    b = UserForm(request.POST or None, instance=instance_b)

    if a.is_valid() and b.is_valid():
        a.save() and b.save()
        return HttpResponseRedirect('/dashboard/account/')


    return render(request, 'dashboard/profile-edit.html', {
        'form': a,
        'forms': b,
        })
示例#4
0
def personal(request):
    """
    Personal data of the user profile
    """
    profile, created = Profile.objects.get_or_create(user=request.user)

    if request.method == "POST":
        old_profile = copy.copy(profile)
        form = ProfileForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            messages.success(request, _("Your profile information has been updated successfully."), fail_silently=True)
            signal_responses = signals.post_signal.send(sender=personal, request=request, form=form, extra={'old_profile':old_profile})
            last_response = signals.last_response(signal_responses)
            if last_response:
                return last_response
    else:
        form = ProfileForm(instance=profile)

    template = "member/profile/personal.html"
    data = { 'section': 'personal', 'GOOGLE_MAPS_API_KEY': GOOGLE_MAPS_API_KEY,
             'form': form, }
    signals.context_signal.send(sender=personal, request=request, context=data)
    return render_to_response(template, data, context_instance=RequestContext(request))
示例#5
0
def profile_update(request):
    user = request.user
    if not user.is_authenticated():
        return redirect('member:login')
    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES)
        form.is_valid()
        form.update(user)
        return redirect('member:profile')
    else:
        form = ProfileForm(initial={
            'nickname': user.nickname,
            'introduction': user.introduction,
        })
    context = {
        'form': form,
    }
    return render(request, 'member/profile_update.html', context)
示例#6
0
def personal(request):
    """
    Personal data of the user profile
    """
    profile, created = Profile.objects.get_or_create(user=request.user)

    if request.method == "POST":
        old_profile = copy.copy(profile)
        form = ProfileForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            messages.success(
                request,
                _("Your profile information has been updated successfully."),
                fail_silently=True)
            signal_responses = signals.post_signal.send(
                sender=personal,
                request=request,
                form=form,
                extra={'old_profile': old_profile})
            last_response = signals.last_response(signal_responses)
            if last_response:
                return last_response
    else:
        form = ProfileForm(instance=profile)

    template = "member/profile/personal.html"
    data = {
        'section': 'personal',
        'GOOGLE_MAPS_API_KEY': GOOGLE_MAPS_API_KEY,
        'form': form,
    }
    signals.context_signal.send(sender=personal, request=request, context=data)
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
示例#7
0
 def test_valid_profile_form(self):
     data = {}
     form = ProfileForm(data=data)
     self.assertTrue(form.is_valid())