Python django.forms.PasswordInput() Examples

The following are 24 code examples for showing how to use django.forms.PasswordInput(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.forms , or try the search function .

Example 1
Project: janeway   Author: BirkbeckCTP   File: forms.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        active = kwargs.pop('active', None)
        request = kwargs.pop('request', None)
        super(AdminUserForm, self).__init__(*args, **kwargs)

        if not kwargs.get('instance', None):
            self.fields['is_active'].initial = True

        if active == 'add':
            self.fields['password_1'] = forms.CharField(widget=forms.PasswordInput, label="Password")
            self.fields['password_2'] = forms.CharField(widget=forms.PasswordInput, label="Repeat password")

        if request and not request.user.is_admin:
            self.fields.pop('is_staff', None)
            self.fields.pop('is_admin', None)

        if request and not request.user.is_superuser:
            self.fields.pop('is_superuser') 
Example 2
Project: ontask_b   Author: abelardopardo   File: forms.py    License: MIT License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        self.connection = kwargs.pop('connection')
        if not self.connection:
            self.connection = models.SQLConnection.objects.get(
                pk=kwargs.get('instance').payload['connection_id'])

        super().__init__(*args, **kwargs)

        if not self.connection.db_password:
            self.fields['db_password'] = forms.CharField(
                max_length=models.CHAR_FIELD_MID_SIZE,
                label=_('Password'),
                widget=forms.PasswordInput,
                required=True,
                help_text=_('Authentication for the database connection'))

        if not self.connection.db_table:
            self.fields['db_table'] = forms.CharField(
                max_length=models.CHAR_FIELD_MID_SIZE,
                label=_('Table name'),
                required=True,
                help_text=_('Table to load'))
            self.set_fields_from_dict(['db_table']) 
Example 3
Project: connect   Author: nlhkabu   File: forms.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        self.user = kwargs.pop('user', None)
        super(UpdateEmailForm, self).__init__(*args, **kwargs)

        self.fields['email'] = forms.EmailField(
            initial=self.user.email,
            widget=forms.EmailInput(attrs={
                'placeholder': _('Email')
            }),
            error_messages={
                'required': _('Please enter your new email address.'),
                'invalid': _('Please enter a valid email address.')
            })

        self.fields['password'] = forms.CharField(
            widget=forms.PasswordInput(attrs={
                'placeholder': _('Password')
            }),
            error_messages={
                'required': _('Please enter your password.'),
            }) 
Example 4
Project: connect   Author: nlhkabu   File: forms.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        self.user = kwargs.pop('user', None)
        super(UpdatePasswordForm, self).__init__(*args, **kwargs)

        self.fields['new_password'] = forms.CharField(
            widget=forms.PasswordInput(attrs={
                'placeholder': _('New Password')
            }),
            error_messages={
                'required': _('Please enter your new password.')
            })

        self.fields['current_password'] = forms.CharField(
            widget=forms.PasswordInput(attrs={
                'placeholder': _('Current Password')
            }),
            error_messages={
                'required': _('Please enter your current password.')
            }) 
Example 5
Project: diting   Author: getway   File: forms.py    License: GNU General Public License v2.0 6 votes vote down vote up
def save(self, category="default"):
        if not self.is_bound:
            raise ValueError("Form is not bound")

        db_settings = Setting.objects.all()
        if self.is_valid():
            with transaction.atomic():
                for name, value in self.cleaned_data.items():
                    field = self.fields[name]
                    if isinstance(field.widget, forms.PasswordInput) and not value:
                        continue
                    if value == to_form_value(getattr(db_settings, name).value):
                        continue

                    defaults = {
                        'name': name,
                        'category': category,
                        'value': to_model_value(value)
                    }
                    Setting.objects.update_or_create(defaults=defaults, name=name)
        else:
            raise ValueError(self.errors) 
Example 6
Project: peering-manager   Author: respawner   File: fields.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, password_source="password", render_value=False, *args, **kwargs):
        widget = kwargs.pop("widget", forms.PasswordInput(render_value=render_value))
        label = kwargs.pop("label", "Password")
        super().__init__(widget=widget, label=label, *args, **kwargs)
        self.widget.attrs["password-source"] = password_source 
Example 7
Project: django-aws-template   Author: dkarchmer   File: forms.py    License: MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(AllauthLoginForm, self).__init__(*args, **kwargs)
        self.fields['password'].widget = forms.PasswordInput()

        self.helper = FormHelper()
        self.helper.form_method = 'post'
        self.helper.add_input(Submit('submit', 'Sign In', css_class='btn btn-lg btn-success btn-block')) 
Example 8
Project: prospector   Author: chaoss   File: fields.py    License: GNU General Public License v3.0 5 votes vote down vote up
def formfield(self, form_class=forms.CharField, **kwargs):
        kwargs['widget'] = forms.PasswordInput

        return super().formfield(form_class=form_class, **kwargs) 
Example 9
Project: wagtail   Author: wagtail   File: test_edit_handlers.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_get_form_for_model_with_widget_overides_by_class(self):
        EventPageForm = get_form_for_model(
            EventPage, form_class=WagtailAdminPageForm,
            widgets={'date_from': forms.PasswordInput})
        form = EventPageForm()

        self.assertEqual(type(form.fields['date_from']), forms.DateField)
        self.assertEqual(type(form.fields['date_from'].widget), forms.PasswordInput) 
Example 10
Project: wagtail   Author: wagtail   File: test_edit_handlers.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_get_form_for_model_with_widget_overides_by_instance(self):
        EventPageForm = get_form_for_model(
            EventPage, form_class=WagtailAdminPageForm,
            widgets={'date_from': forms.PasswordInput()})
        form = EventPageForm()

        self.assertEqual(type(form.fields['date_from']), forms.DateField)
        self.assertEqual(type(form.fields['date_from'].widget), forms.PasswordInput) 
Example 11
Project: hubblemon   Author: naver   File: cubrid_query.py    License: Apache License 2.0 5 votes vote down vote up
def auth_fields(param):
	id = forms.CharField(label = 'id', required = False)
	pw = forms.CharField(label = 'pw', widget = forms.PasswordInput(), required = False)
	db = forms.CharField(label = 'db', required = False)
	port = forms.CharField(label = 'port', required = False)
	return [id, pw, db, port] 
Example 12
Project: hubblemon   Author: naver   File: memcached_query.py    License: Apache License 2.0 5 votes vote down vote up
def auth_fields(param):
	id = forms.CharField(label = 'id', required = False)
	pw = forms.CharField(label = 'pw', widget = forms.PasswordInput(), required = False)
	return [id, pw] 
Example 13
Project: hubblemon   Author: naver   File: mysql_query.py    License: Apache License 2.0 5 votes vote down vote up
def auth_fields(param):
	id = forms.CharField(label = 'id', required = False)
	pw = forms.CharField(label = 'pw', widget = forms.PasswordInput(), required = False)
	db = forms.CharField(label = 'db', required = False)
	return [id, pw, db] 
Example 14
Project: hubblemon   Author: naver   File: redis_query.py    License: Apache License 2.0 5 votes vote down vote up
def auth_fields(param):
	id = forms.CharField(label = 'id', required = False)
	pw = forms.CharField(label = 'pw', widget = forms.PasswordInput(), required = False)
	return [id, pw] 
Example 15
Project: hubblemon   Author: naver   File: arcus_query.py    License: Apache License 2.0 5 votes vote down vote up
def auth_fields(param):
	id = forms.CharField(label = 'id', required = False)
	pw = forms.CharField(label = 'pw', widget = forms.PasswordInput(), required = False)
	return [id, pw] 
Example 16
Project: connect   Author: nlhkabu   File: forms.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        self.user = kwargs.pop('user', None)
        super(CloseAccountForm, self).__init__(*args, **kwargs)

        self.fields['password'] = forms.CharField(
            widget=forms.PasswordInput(attrs={
                'placeholder': _('Password')
            }),
            error_messages={
                'required': _('Please enter your password.')
            }) 
Example 17
Project: callisto-core   Author: project-callisto   File: forms.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def passphrase_field(label):
    return forms.CharField(
        max_length=64,
        label=label,
        widget=forms.PasswordInput(
            attrs={"autocomplete": "off", "class": "form-control"}
        ),
    ) 
Example 18
Project: Inboxen   Author: Inboxen   File: fields.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        kwargs.setdefault("max_length", 4096)
        kwargs.setdefault("min_length", 12)
        kwargs.setdefault("widget", forms.PasswordInput)

        super(PasswordCheckField, self).__init__(*args, **kwargs) 
Example 19
Project: djongo   Author: nesdis   File: test_passwordinput.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_render_value_true(self):
        """
        The render_value argument lets you specify whether the widget should
        render its value. For security reasons, this is off by default.
        """
        widget = PasswordInput(render_value=True)
        self.check_html(widget, 'password', '', html='<input type="password" name="password">')
        self.check_html(widget, 'password', None, html='<input type="password" name="password">')
        self.check_html(
            widget, 'password', 'test@example.com',
            html='<input type="password" name="password" value="test@example.com">',
        ) 
Example 20
Project: djongo   Author: nesdis   File: test_passwordinput.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_render_value_true(self):
        """
        The render_value argument lets you specify whether the widget should
        render its value. For security reasons, this is off by default.
        """
        widget = PasswordInput(render_value=True)
        self.check_html(widget, 'password', '', html='<input type="password" name="password">')
        self.check_html(widget, 'password', None, html='<input type="password" name="password">')
        self.check_html(
            widget, 'password', 'test@example.com',
            html='<input type="password" name="password" value="test@example.com">',
        ) 
Example 21
Project: django-beginners-guide   Author: sibtc   File: test_templatetags.py    License: MIT License 5 votes vote down vote up
def test_field_widget_type(self):
        form = ExampleForm()
        self.assertEquals('TextInput', field_type(form['name']))
        self.assertEquals('PasswordInput', field_type(form['password'])) 
Example 22
Project: esdc-ce   Author: erigones   File: forms.py    License: Apache License 2.0 5 votes vote down vote up
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'},
        ) 
Example 23
def is_password(field):
    return isinstance(field.field.widget, forms.PasswordInput) 
Example 24
Project: djangocms-forms   Author: mishbahr   File: forms.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def prepare_password(self, field):
        field_attrs = field.build_field_attrs()
        widget_attrs = field.build_widget_attrs()

        field_attrs.update({
            'widget': forms.PasswordInput(attrs=widget_attrs),
        })
        return forms.CharField(**field_attrs)