Python django.forms 模块,PasswordInput() 实例源码

我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用django.forms.PasswordInput()

项目:blogghar    作者:v1k45    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(CustomLoginForm, self).__init__(*args, **kwargs)
        self.fields['password'].widget = forms.PasswordInput()
        self.helper = FormHelper(self)
        self.helper.col_class = False
        self.helper.form_tag = False
        self.helper.form_show_labels = True

        for field in self.fields:
            self.fields[field].widget.attrs['placeholder'] = None
            del self.fields[field].widget.attrs['placeholder']

        self.helper.layout = Layout(
            'login', 'password', 'remember',
            StrictButton(
                'Sign In', type='submit', style='margin-top: 10px',
                css_class="waves-effect btn-large blue waves-light btn right"),
        )
项目:prestashop-sync    作者:dragoon    | 项目源码 | 文件源码
def render(self, name, value, attrs=None):
        if not attrs.has_key('class'):
            attrs['class'] = name
        attrs_text = attrs.copy()
        attrs_pass = attrs.copy()

        # render name only for visible element
        name_pass, name_text = name, ''

        # disable autocomplete for text
        attrs_text['autocomplete'] = 'off'

        # set either text or password fields to hidden
        temp_attrs = attrs_text
        if not self.attrs.has_key('default') or self.attrs['default'] == TogglePasswordInput.TEXT:
            temp_attrs = attrs_pass
            name_text, name_pass = name_pass, name_text
        # remove id so we don't get two field with same ids
        del temp_attrs['id']
        temp_attrs['style'] = 'display:none;'

        output = forms.TextInput().render(name_text, value, attrs_text)
        output += forms.PasswordInput.render(self, name_pass, value, attrs_pass)
        output += '<a title="'+_('show/hide password')+'" data-target-class="'+attrs['class']+'" class="toggle-password" href="#"></a>'
        return mark_safe(output)
项目:django-iitg-auth    作者:narenchoudhary    | 项目源码 | 文件源码
def test_form_init(self, mock_get_user_model):
        mock_get_user_model.return_value = User
        initial_data = {'username': 'username', 'password': 'password',
                        'login_server': '202.141.80.10'}
        form = WebmailLoginForm(data=initial_data)
        self.assertIsInstance(form.fields['username'], forms.CharField)
        self.assertIsInstance(form.fields['password'], forms.CharField)
        self.assertIsInstance(form.fields['password'].widget, forms.PasswordInput)
        self.assertEqual(form.data.get('username'),
                         initial_data.get('username'))
        self.assertEqual(form.data.get('password'),
                         initial_data.get('password'))
        self.assertEqual(form.data.get('login_server'),
                         initial_data.get('login_server'))
        self.assertEqual(form.port, poplib.POP3_SSL_PORT)
        self.assertEqual(form.username_field.verbose_name, User.USERNAME_FIELD)
项目:django-livesettings3    作者:kunaldeo    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
            kwargs['required'] = False
            kwargs['widget'] = forms.PasswordInput(render_value=self.render_value)
            forms.CharField.__init__(self, *args, **kwargs)
项目:callisto-core    作者:project-callisto    | 项目源码 | 文件源码
def passphrase_field(label):
    return forms.CharField(
        max_length=64,
        label=label,
        widget=forms.PasswordInput(attrs={
            'autocomplete': 'off',
            'class': 'form-control',
        }),
    )
项目:django-twilio-tfa    作者:rtindru    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        render_value = kwargs.pop('render_value',
                                  app_settings.PASSWORD_INPUT_RENDER_VALUE)
        kwargs['widget'] = forms.PasswordInput(render_value=render_value,
                                               attrs={'placeholder':
                                                      _(kwargs.get("label"))})
        super(PasswordField, self).__init__(*args, **kwargs)
项目:esdc-ce    作者:erigones    | 项目源码 | 文件源码
def __init__(self, request, *args, **kwargs):
        super(LoginForm, self).__init__(*args, **kwargs)
        self.request = request
        self.fields['username'].label = _('username or email')
        self.fields['username'].widget = EmailInput(
            attrs={'class': 'input-transparent', 'placeholder': _('Username or Email'), 'required': 'required'},
        )
        self.fields['password'].widget = forms.PasswordInput(
            render_value=False,
            attrs={'class': 'input-transparent', 'placeholder': _('Password'), 'required': 'required'},
        )
项目:moore    作者:UTNkar    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(RegistrationForm, self).__init__(*args, **kwargs)
        self.fields['first_name'].required = True
        self.fields['last_name'].required = True
        self.fields['password1'].widget = forms.PasswordInput(
            attrs={'class': 'form-control'}
        )
        self.fields['password2'].widget = forms.PasswordInput(
            attrs={'class': 'form-control'}
        )
项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(CMSToolbarLoginForm, self).__init__(*args, **kwargs)
        kwargs['prefix'] = kwargs.get('prefix', 'cms')
        self.fields['username'].widget = forms.TextInput(
            attrs = { 'required': 'required' })
        self.fields['password'].widget = forms.PasswordInput(
            attrs = { 'required': 'required' })
项目:mes    作者:osess    | 项目源码 | 文件源码
def test_filter_by_widget(self):
        form = TestForm()
        form.helper = FormHelper(form)
        form.helper.layout = self.advanced_layout
        self.assertEqual(form.helper.filter_by_widget(forms.PasswordInput).slice, [
            [[0, 1, 0, 0], 'password1'],
            [[0, 4, 0], 'password2'],
        ])
项目:mes    作者:osess    | 项目源码 | 文件源码
def test_exclude_by_widget(self):
        form = TestForm()
        form.helper = FormHelper(form)
        form.helper.layout = self.advanced_layout
        self.assertEqual(form.helper.exclude_by_widget(forms.PasswordInput).slice, [
            [[0, 0, 0, 0], 'email'],
            [[0, 3, 0], 'first_name'],
            [[1], 'last_name'],
        ])
项目:mes    作者:osess    | 项目源码 | 文件源码
def test_exclude_by_widget_and_wrap(self):
        form = TestForm()
        form.helper = FormHelper(form)
        form.helper.layout = self.advanced_layout
        form.helper.exclude_by_widget(forms.PasswordInput).wrap(Field, css_class='hero')
        # Check wrapped fields
        self.assertTrue(isinstance(form.helper.layout[0][0][0][0], Field))
        self.assertTrue(isinstance(form.helper.layout[0][3][0], Field))
        self.assertTrue(isinstance(form.helper.layout[1], Field))
        # Check others stay the same
        self.assertTrue(isinstance(form.helper.layout[0][3][1], HTML))
        self.assertTrue(isinstance(form.helper.layout[0][1][0][0], string_types))
        self.assertTrue(isinstance(form.helper.layout[0][4][0], string_types))
项目:mes    作者:osess    | 项目源码 | 文件源码
def test_filter_by_widget_without_form(self):
        form = TestForm()
        form.helper = FormHelper()
        form.helper.layout = self.advanced_layout
        self.assertRaises(FormHelpersException, lambda: form.helper.filter_by_widget(forms.PasswordInput))
项目:mes    作者:osess    | 项目源码 | 文件源码
def is_password(field):
    return isinstance(field.field.widget, forms.PasswordInput)
项目:Provo-Housing-Database    作者:marcopete5    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        render_value = kwargs.pop('render_value',
                                  app_settings.PASSWORD_INPUT_RENDER_VALUE)
        kwargs['widget'] = forms.PasswordInput(render_value=render_value,
                                               attrs={'placeholder':
                                                      _(kwargs.get("label"))})
        super(PasswordField, self).__init__(*args, **kwargs)
项目:Strassengezwitscher    作者:Strassengezwitscher    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(BootstrapPasswordChangeForm, self).__init__(*args, **kwargs)
        self.fields['old_password'].widget = forms.PasswordInput(attrs={'class': 'form-control'})
        self.fields['new_password1'].widget = forms.PasswordInput(attrs={'class': 'form-control'})
        self.fields['new_password2'].widget = forms.PasswordInput(attrs={'class': 'form-control'})
        self.success = False
项目:pretix-passbook    作者:pretix    | 项目源码 | 文件源码
def register_global_settings(sender, **kwargs):
    return OrderedDict([
        ('passbook_team_id', forms.CharField(
            label=_('Passbook team ID'),
            required=False,
        )),
        ('passbook_pass_type_id', forms.CharField(
            label=_('Passbook type'),
            required=False,
        )),
        ('passbook_organizer_name', forms.CharField(
            label=_('Passbook organizer name'),
            required=False,
        )),
        ('passbook_certificate_file', CertificateFileField(
            label=_('Passbook certificate file'),
            required=False,
        )),
        ('passbook_wwdr_certificate_file', CertificateFileField(
            label=_('Passbook CA Certificate'),
            help_text=_('You can download the current CA certificate from apple at '
                        'https://developer.apple.com/certificationauthority/AppleWWDRCA.cer'),
            required=False,
        )),
        ('passbook_key', forms.CharField(
            label=_('Passbook secret key'),
            required=False,
            widget=forms.Textarea,
            validators=[validate_rsa_privkey]
        )),
        ('passbook_key_password', forms.CharField(
            label=_('Passbook key password'),
            widget=forms.PasswordInput(render_value=True),
            required=False,
            help_text=_('Optional, only necessary if the key entered above requires a password to use.')
        )),
        ('passbook_gmaps_api_key', forms.CharField(
            label=_('Google Maps API key'),
            widget=forms.PasswordInput(render_value=True),
            required=False,
            help_text=_('Optional, only necessary to find coordinates automatically.')
        )),
    ])