Ticket #3409: password-input.diff

File password-input.diff, 1.8 KB (added by scott@…, 8 years ago)

Diff for PasswordInput widgets and forms tests

  • django/newforms/widgets.py

     
    8181class PasswordInput(Input):
    8282    input_type = 'password'
    8383
     84    def __init__(self, attrs=None, render_value=True):
     85        self.attrs = attrs or {}
     86        self.render_value = render_value
     87
     88    def render(self, name, value, attrs=None):
     89        if not self.render_value: value=None
     90        return super(PasswordInput, self).render(name, value, attrs)
     91
    8492class HiddenInput(Input):
    8593    input_type = 'hidden'
    8694    is_hidden = True
  • tests/regressiontests/forms/tests.py

     
    7272>>> w.render('email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'})
    7373u'<input type="password" class="fun" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" name="email" />'
    7474
     75You can specify if the widget should render its value or not:
     76>>> w = PasswordInput(render_value=True)
     77>>> w.render('email', 'secret')
     78u'<input type="password" name="email" value="secret" />'
     79>>> w = PasswordInput(render_value=False)
     80>>> w.render('email', '')
     81u'<input type="password" name="email" />'
     82>>> w.render('email', None)
     83u'<input type="password" name="email" />'
     84>>> w.render('email', 'secret')
     85u'<input type="password" name="email" />'
     86>>> w = PasswordInput(attrs={'class': 'fun'}, render_value=False)
     87>>> w.render('email', 'secret')
     88u'<input type="password" class="fun" name="email" />'
     89
    7590# HiddenInput Widget ############################################################
    7691
    7792>>> w = HiddenInput()
Back to Top