Hi everyone...

I'm having an strange behavior with a form.

It's a simple sign-up form.

When I call the page using the url http://xxx/membro/cadastro/3/ the
form show the data for de mebro.id=3, so after that, if I call the
page using the url http://xxx/membro/cadastro/ the form should not
show any data, but it does. It shows the data of the membro.id=3, no
matter what...

It's not a browser cache problem because I called http://xxx/membro/cadastro/3/
on Firefox and http://xxx/membro/cadastro/ on IE and the IE form
showed the data too..

I'm not using any session...

Below is my code:

FILE urls.py:
-------------------------------------------
from django.conf.urls.defaults import *
from django.conf import settings

urlpatterns = patterns('megavenda.membro.views',

    (r'^cadastro/(?P<id>\d+)/$', 'cadastro'),
    (r'^cadastro/$', 'cadastro'),
    (r'^ativar/(?P<chaveConfirmacao>.*)/$', 'ativar'),
)
------------------------------------------

FILE views.py
------------------------------------------
#-*- coding: utf-8 -*-

from django import newforms as forms
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect
from django.newforms import widgets
from django.core import validators
from models import Membro

def ativar(request, chaveConfirmacao=None):
    m = Membro.objects.get(chaveConfirmacao=chaveConfirmacao)
    m.status = 'A' #muda o status para Ativado
    m.save()
    errorMessage = m.email
    return render_to_response('megavenda/membro/
loginform.html',locals())


def cadastro(request, id=None):
    import forms as membroForms
    errorMessage = ''

    if request.method == 'POST':
        form = membroForms.MembroForm(request.POST)
        if form.is_valid():
            try:
                if id is None:
                    m = Membro()
                    m.criar_inativo(email=form.clean_data['email'],
 
nomeExibicao=form.clean_data['nomeExibicao'],
                                        senha =
form.clean_data['senha'],
                                        enviar_email=True)
                    return HttpResponseRedirect("../../")
                else:
                    m = Membro.objects.get (id=id)
                    m.email = form.clean_data['email']
                    m.nomeExibicao = form.clean_data['nomeExibicao']
                    m.senha = form.clean_data['senha']
                    m.save()
            except Exception, e:
                if e.args[0]==1062:
                    errorMessage = 'Já existe um usuário cadastrado
com este "'+membro._meta.fields[int( e.args[1]
[len(e.args[1])-1])-1].verbose_name+'"'
                else:
                    errorMessage = e
    else:

        if id is None: #usuario acessando para se cadastrar
            form = membroForms.MembroForm()
        else: #usuário acessando para alterar seu cadastro
            m = Membro.objects.get(id=id)
            form = membroForms.form_for_instance(m)()

    return render_to_response('megavenda/membro/
membroform.html',locals())
------------------------------------------

FILE forms.py (where I make my custom form)
------------------------------------------
#-*- coding: utf-8 -*-

from django import newforms as forms
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect
from django.newforms import widgets
from django.core import validators

from models import Membro


def form_for_instance(instancia):
    f = forms.models.form_for_instance(instance=instancia,
form=MembroForm)

    f.base_fields['email'].initial= instancia.email
    f.base_fields['nomeExibicao'].initial=instancia.nomeExibicao
    f.base_fields['senha'].initial=instancia.senha
    f.base_fields['senhaConfirm'].initial=instancia.senha

    return f

class MembroForm(forms.Form):

    email = forms.EmailField(label='E-mail', max_length=50)
    nomeExibicao = forms.CharField(label='Nome de
Exibição',max_length=30)
    senha = forms.CharField(label='Senha', min_length=3,
max_length=30, help_text='No mínimo 3 caracteres')
    senha.widget = widgets.PasswordInput()
    senhaConfirm = forms.CharField(label='Confirme a Senha',
min_length=3,max_length=30, help_text='A confirmação deve ser idêntica
à senha')
    senhaConfirm.widget = widgets.PasswordInput()


    def clean_email(self):
        """
        Valida se o email já não foi cadastrado
        """
        if self.clean_data.get ('email', None):
            try:
                membro =
Membro.objects.get(email__exact=self.clean_data['email'])
            except Membro.DoesNotExist:
                return self.clean_data ['email']
            raise forms.ValidationError(u'O e-mail "%s" já foi
cadastrado.' % self.clean_data['email'])

    def clean_senhaConfirm(self):
        """
        Valida se a senha informada nos dois campos é igual
        """
        if self.clean_data.get('senha', None) and
self.clean_data.get('senhaConfirm', None) and \
        self.clean_data['senha'] == self.clean_data['senhaConfirm']:
            return self.clean_data['senhaConfirm']
        raise forms.ValidationError(u'A senha informada nos dois
campos deve ser a mesma')
------------------------------------------


Any ideas??


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to