I have this code:
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)
import pdb
pdb.set_trace()
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):
def __init__(self):
self.fields = (
forms.TextField(field_name='username', is_required=True,
validator_list=[validators.isAlphaNumeric,self.userNotDuplicate],
maxlength=30),
forms.EmailField(field_name='email', maxlength=50,
validator_list=[self.mailNotDuplicate]),
)
def userNotDuplicate(self, field_data, all_data):
print field_data
if User.objects.filter(username=field_data).count()>0:
raise validators.ValidationError("Ya existe un usuario con
ese nombre")
def mailNotDuplicate(self, field_data, all_data):
print field_data
if User.objects.filter(email=field_data).count()>0:
raise validators.ValidationError("Ya existe un usuario con
ese email")
def complete(self, request, data):
#Guardar el usuario...
user = User.objects.create_user(data['username'],
data['email'], data['password'])
import pdb
pdb.set_trace()
user.first_name = data['first_name']
user.last_name = data['last_name']
return user
When I call this, in the validation (userNotDuplicate) the record is
not created. Before call eturn self.complete(... is not created.
But when I enter to complete() the record is created and the code fail
with
IntegrityError at /accounts/singup/
column username is not unique
And I see the record... I don't understand why or where the record
become created...
I can use get_or_created but that sound like a bad hack... any idea?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---