コード例 #1
0
ファイル: views.py プロジェクト: ciclocidade/andy
def profile(request):
    msg = ""
    try:
        member = request.user.get_profile()
        msg = u"Olá %s! Atualize os seus dados cadastrais :-)" % request.user.get_full_name()
    except ObjectDoesNotExist:
        member = Member(user=request.user)
    if request.method == "POST":
        form = MemberForm(request.POST, instance=member)
        if form.is_valid():
            member = form.save()
            messages.add_message(request, messages.SUCCESS, "Seu perfil foi atualizado com sucesso!")
            if member.is_complete() and request.user.is_active:
                try:
                    BikeUsageSurvey.objects.get(member=member)
                    return HttpResponseRedirect(reverse("cadastro_pay"))
                except BikeUsageSurvery.DoesNotExist:
                    return HttpResponseRedirect(reverse("cadastro_survey"))
    else:
        form = MemberForm(instance=member)
    if not member.is_complete():
        msg = "Complete os dados do seu perfil!"
    if not form.fields["name"].initial:
        form.fields["name"].initial = request.user.get_full_name()
    if not form.fields["address_city"].initial:
        form.fields["address_city"].initial = u"São Paulo"
    messages.add_message(request, messages.WARNING, msg)
    return render_to_response(
        "profile.html", {"user": request.user, "form": form}, context_instance=RequestContext(request)
    )
コード例 #2
0
ファイル: views.py プロジェクト: brunogola/andy
def profile(request):
    msg = ''
    nex = request.GET.get('next', None)
    if nex:
        request.session['next'] = nex
    try:
        member = request.user.get_profile()
    except ObjectDoesNotExist:
        member = Member(user=request.user)
    if request.method == 'POST':
        form = MemberForm(request.POST, instance=member)
        if form.is_valid():
            member = form.save()
            messages.add_message(request, messages.SUCCESS, 'Seu perfil foi atualizado com sucesso!')
            if member.is_complete() and request.user.is_active:
                return HttpResponseRedirect(request.session.get('next', reverse('cadastro_survey')))
    else:
        form = MemberForm(instance=member)
    if not member.is_complete():
        messages.add_message(request, messages.WARNING, 'Complete os dados do seu perfil!')
    if not form.fields['name'].initial:
        form.fields['name'].initial = request.user.get_full_name()
    if not form.fields['address_city'].initial:
        form.fields['address_city'].initial = u'São Paulo' 
    return render_to_response('profile.html', {'user': request.user, 'form': form}, context_instance=RequestContext(request))