password field: add a flag to disable strength indicator (#8111)

This commit is contained in:
Thomas NOËL 2015-08-26 16:39:53 +02:00
parent 2b4ff0ced6
commit cf43ef783c
2 changed files with 8 additions and 2 deletions

View File

@ -1657,10 +1657,12 @@ class PasswordField(WidgetField):
count_special = 0
confirmation = True
confirmation_title = None
strength_indicator = True
formats = ['sha1']
extra_attributes = ['formats', 'min_length', 'max_length',
'count_uppercase', 'count_lowercase', 'count_digit',
'count_special', 'confirmation', 'confirmation_title']
'count_special', 'confirmation', 'confirmation_title',
'strength_indicator']
widget_class = PasswordEntryWidget
@ -1692,6 +1694,9 @@ class PasswordField(WidgetField):
form.add(IntWidget, 'count_special',
title=_('Minimum number of special characters'),
value=self.count_special)
form.add(CheckboxWidget, 'strength_indicator',
title=_('Add a password strength indicator'),
value=self.strength_indicator)
form.add(CheckboxWidget, 'confirmation',
title=_('Add a confirmation input'),
value=self.confirmation)

View File

@ -1856,6 +1856,7 @@ class PasswordEntryWidget(CompositeWidget):
self.count_special = kwargs.get('count_special', 0)
self.confirmation = kwargs.get('confirmation', True)
confirmation_title = kwargs.get('confirmation_title') or _('Confirmation')
self.strength_indicator = kwargs.get('strength_indicator', True)
self.formats = kwargs.get('formats', ['sha1'])
if not self.attrs.get('readonly'):
@ -1880,7 +1881,7 @@ class PasswordEntryWidget(CompositeWidget):
fake_value, self.name, encoded_value)))
def render_content(self):
if self.attrs.get('readonly'):
if self.attrs.get('readonly') or not self.strength_indicator:
return CompositeWidget.render_content(self)
get_response().add_javascript(['jquery.js', 'jquery.passstrength.js'])
r = TemplateIO(html=True)