I do this:

(I copy this class from the cookbox)

class Manipulator(forms.Manipulator):
    default = {}
    done = False

    def getData(self, request):
        return request.POST

    def getForm(self, data, errors):
        return forms.FormWrapper(self, data, errors)

    def process(self, request):
        data = self.getData(request)
        if data:
            new_data = data.copy()
            errors = self.get_validation_errors(new_data)
            if not errors:
                self.do_html2python(new_data)

                self.done = True
                return self.complete(request, new_data)
        else:
            errors = {}
            new_data = self.default
        self.form = self.getForm(new_data, errors)
        return self.form

    def complete(self, request, data):
        pass

class SingUpForm(Manipulator):
    fields = (
        forms.TextField(field_name='username', is_required=True,
validator_list=['isAlphaNumeric'], maxlength=30),
        forms.TextField(field_name='first_name', maxlength=30),
        forms.TextField(field_name='last_name', maxlength=30),
        forms.EmailField(field_name='email', maxlength=50),
        forms.TextField(field_name='password', is_required=True,
maxlength=80),
        forms.TextField(field_name='phone', is_required=True,
maxlength=10),
        forms.TextField(field_name='celular', is_required=True,
maxlength=10),
        forms.SelectField(field_name='sexo', is_required=True,
choices=(('F', 'Femenino'), ('M', 'Masculino'))),
        #TODO: Filtrar por pais los deptos...
        forms.SelectField(field_name='depto', choices=
fromDictToList(State.objects.values('id', 'name')) ) ,
        forms.TextField(field_name='ciudad', is_required=True,
maxlength=50),
        forms.TextField(field_name='address', is_required=True,
maxlength=50),
        )

    def __init__(self):
        # You can also define your fields here, if you'd like.
        pass

    def complete(self, request, data):
        #Guardar el usuario...
        user = User.objects.create_user(data['username'],
data['email'], data['password'])

        user.first_name = data['first_name']
        user.last_name = data['last_name']

        user.save()

However, in post I'm getting:

'str' object is not callable in
d:\programacion\otros\python24\lib\site-packages\django\django\forms\__init__.py
in run_validator, line 341

The thing is is not clear for my how this work... maybe too much
exposure to asp.net ;)

If I understand, the manipulator is a object representation of the html
form, with optional validator class.

The process function copy the POST data and run validator then in
complete must be the concrete action (save the object or redirect)?


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to