Hi All,
I am having the following error while using the dual password field :
class DualPasswordWidget(forms.Widget):

        ^

SyntaxError: invalid syntax

my views.py is

# Create your views here.
from django.shortcuts import render_to_response, get_object_or_404
from datetime import datetime
from django import forms
from models import Person
from django.forms.extras.widgets import SelectDateWidget
from django.utils.translation import ugettext_lazy as _

class NewUserForm(forms.Form):
    username = forms.CharField(label=_('username'))
    password = DualPasswordField(label=_(u"password"))
    email   = forms.EmailField(label=_('email')

class DualPasswordWidget(forms.Widget):
    pass0_field = '%s_pass0'
    pass1_field = '%s_pass1'

    def __init__(self, *args, **kwargs):
        super(DualPasswordWidget, self).__init__(*args, **kwargs)

    def render(self, name, value, *args, **kwargs):
        out = ( forms.PasswordInput().render(self.pass0_field % name,
None),
                forms.PasswordInput().render(self.pass1_field % name,
None) )
        return '<br />'.join(out)

    def value_from_datadict(self, data, files, name):
        pass0 = data.get(self.pass0_field % name, None)
        pass1 = data.get(self.pass1_field % name, None)
        if pass0 and pass1:
            return (pass0, pass1)
        return None

class DualPasswordField(forms.Field):
    """
    Field used to prevent password typos by asking the same password
twice
    and checking if it's the same
    """
    widget = DualPasswordWidget()
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('help_text', _('Insert your password
twice.'))
        super(DualPasswordField, self).__init__(*args, **kwargs)

    def clean(self, value):
        super(DualPasswordField, self).clean(value)
        if value:
            pass0, pass1 = value
            if pass0 == pass1:
                return pass0
            raise forms.ValidationError(_('Password Miss-match.'))
def contact_view(request):
    eForm = NewUserForm()
    return render_to_response('contact_form.html',
{ 'eForm':eForm.as_table()})

Please help me correcting this and can anyone tell me how to make the
password field have minimum of 6 characters mandatory to be entered by
user while registering.

Thanks

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

Reply via email to