示例#1
0
    def __init__(self, instance, *args, **kwargs):
        """Overrides forms.ModelForm.__init__()
        Unlike forms.ModelForm, instance is required
        """
        self.attrs = kwargs.pop('attrs', {})
        self.use_react = kwargs.pop('use_react', False)
        self.instance = instance
        self._save_fields_lookup = kwargs.pop('save_fields_lookup', {})

        super(AbstractModelInstanceUpdateForm,
              self).__init__(instance=instance, *args, **kwargs)
        self._set_save_fields(*args)

        if args or kwargs:
            # make all non-save fields optional
            for name, field in self.fields.items():
                if name not in self._save_fields_lookup:
                    field.required = False
                else:
                    pass
        else:
            # leave the fields the way they are for rendering a form initially
            pass
        set_input_attrs(self)
        set_input_placeholder_labels(self)
示例#2
0
 def __init__(self, *args, **kwargs):
     super(UserRegistrationForm, self).__init__(*args, **kwargs)
     self.cascaded_errors = []
     del self.fields['username']
     self.fields['password2'].label = 'Confirm Password'
     self.label_suffix = ''
     set_input_attrs(self)
     set_input_placeholder_labels(self)
示例#3
0
 def __init__(self, *args, **kwargs):
     super(UserRegistrationForm, self).__init__(*args, **kwargs)
     self.cascaded_errors = []
     if 'username' in self.fields:
         del self.fields['username']
     self.fields['password2'].label = 'Confirm Password'
     self.label_suffix = ''
     set_input_attrs(self)
     set_input_placeholder_labels(self)
示例#4
0
def reset_password(request,
                   data=None,
                   redirect_url_name='account_password_reset_success',
                   template='account/reset_password.html',
                   renderer=_r):
    """
    View that checks the hash in a password reset link and presents a
    form for entering a new password.
    Based off of django.contrib.auth.views.password_reset_confirm
    Need to customize error display
    """
    if data is None:
        data = wrap_data(request)

    uidb36 = request.GET.get('u', None)
    token = request.GET.get('t', None)
    token_generator = default_token_generator
    success = False
    response = None
    if uidb36 and token:
        UserModel = get_user_model()
        try:
            uid_int = base36_to_int(uidb36)
            user = UserModel.objects.get(id=uid_int)
        except (ValueError, UserModel.DoesNotExist):
            user = None

        if user is not None and token_generator.check_token(user, token):
            validlink = True
            if request.method == 'POST':
                form = UpdatePasswordForm(user, request.POST)
                if form.is_valid():
                    user = form.save()
                    if htk_setting(
                            'HTK_ACCOUNTS_CHANGE_PASSWORD_UPDATE_SESSION_AUTH_HASH'
                    ):
                        from django.contrib.auth import update_session_auth_hash
                        update_session_auth_hash(request, user)
                    success = True
            else:
                form = UpdatePasswordForm(None)
            if 'input_attrs' in data:
                set_input_attrs(form, attrs=data['input_attrs'])
        else:
            validlink = False
            form = None
        data['form'] = form
        data['validlink'] = validlink
    else:
        data['validlink'] = False
    if success:
        response = redirect(reverse(redirect_url_name))
    else:
        response = renderer(request, template, data=data)
    return response
示例#5
0
文件: views.py 项目: pkkup/django-htk
def reset_password(
    request,
    data=None,
    redirect_url_name='account_password_reset_success',
    template='account/reset_password.html',
    renderer=_r
):
    """
    View that checks the hash in a password reset link and presents a
    form for entering a new password.
    Based off of django.contrib.auth.views.password_reset_confirm
    Need to customize error display
    """
    if data is None:
        data = wrap_data(request)

    uidb36 = request.GET.get('u', None)
    token = request.GET.get('t', None)
    token_generator = default_token_generator
    success = False
    response = None
    if uidb36 and token:
        UserModel = get_user_model()
        try:
            uid_int = base36_to_int(uidb36)
            user = UserModel.objects.get(id=uid_int)
        except (ValueError, UserModel.DoesNotExist):
            user = None

        if user is not None and token_generator.check_token(user, token):
            validlink = True
            if request.method == 'POST':
                form = UpdatePasswordForm(user, request.POST)
                if form.is_valid():
                    user = form.save()
                    if htk_setting('HTK_ACCOUNTS_CHANGE_PASSWORD_UPDATE_SESSION_AUTH_HASH'):
                        from django.contrib.auth import update_session_auth_hash
                        update_session_auth_hash(request, user)
                    success = True
            else:
                form = UpdatePasswordForm(None)
            if 'input_attrs' in data:
                set_input_attrs(form, attrs=data['input_attrs'])
        else:
            validlink = False
            form = None
        data['form'] = form
        data['validlink'] = validlink
    else:
        data['validlink'] = False
    if success:
        response = redirect(reverse(redirect_url_name))
    else:
        response = renderer(request, template, data=data)
    return response
示例#6
0
 def __init__(self, request=None, *args, **kwargs):
     """
     If request is passed in, the form will validate that cookies are
     enabled. Note that the request (a HttpRequest object) must have set a
     cookie with the key TEST_COOKIE_NAME and value TEST_COOKIE_VALUE before
     running this validation.
     """
     self.request = request
     self.user_cache = None
     super(UsernameEmailAuthenticationForm, self).__init__(*args, **kwargs)
     set_input_attrs(self)
     set_input_placeholder_labels(self)
示例#7
0
def resend_confirmation(request,
                        data=None,
                        template='account/resend_confirmation.html',
                        email_template=None,
                        email_subject=None,
                        email_sender=None,
                        renderer=_r):
    if data is None:
        data = wrap_data(request)

    data.update(csrf(request))
    if request.method == 'POST':
        resend_confirmation_form = ResendConfirmationForm(request.POST)
        if resend_confirmation_form.is_valid():
            email = resend_confirmation_form.cleaned_data.get('email')
            user_emails = UserEmail.objects.filter(email=email)
            num_confirmed_user_emails = user_emails.filter(
                is_confirmed=True).count()
            if num_confirmed_user_emails == 1:
                data['already_active'] = True
            elif num_confirmed_user_emails > 1:
                raise NonUniqueEmail(email)
            else:
                unconfirmed_user_emails = user_emails.filter(
                    is_confirmed=False)
                for unconfirmed in unconfirmed_user_emails:
                    unconfirmed.send_activation_email(
                        domain=request.get_host(),
                        template=email_template,
                        subject=email_subject,
                        sender=email_sender,
                        resend=True)
                data['success'] = True
        else:
            for error in resend_confirmation_form.non_field_errors():
                data['errors'].append(error)
    else:
        email = request.GET.get('email')
        initial_data = {
            'email': email,
        }
        resend_confirmation_form = ResendConfirmationForm(initial=initial_data)
    if 'input_attrs' in data:
        set_input_attrs(resend_confirmation_form, attrs=data['input_attrs'])
    data['resend_confirmation_form'] = resend_confirmation_form
    response = renderer(request, template, data=data)
    return response
示例#8
0
文件: views.py 项目: pkkup/django-htk
def resend_confirmation(
    request,
    data=None,
    template='account/resend_confirmation.html',
    email_template=None,
    email_subject=None,
    email_sender=None,
    renderer=_r
):
    if data is None:
        data = wrap_data(request)

    data.update(csrf(request))
    if request.method == 'POST':
        resend_confirmation_form = ResendConfirmationForm(request.POST)
        if resend_confirmation_form.is_valid():
            email = resend_confirmation_form.cleaned_data.get('email')
            user_emails = UserEmail.objects.filter(email=email)
            num_confirmed_user_emails = user_emails.filter(is_confirmed=True).count()
            if num_confirmed_user_emails == 1:
                data['already_active'] = True
            elif num_confirmed_user_emails > 1:
                raise NonUniqueEmail(email)
            else:
                unconfirmed_user_emails = user_emails.filter(is_confirmed=False)
                for unconfirmed in unconfirmed_user_emails:
                    unconfirmed.send_activation_email(domain=request.get_host(), template=email_template, subject=email_subject, sender=email_sender, resend=True)
                data['success'] = True
        else:
            for error in resend_confirmation_form.non_field_errors():
                data['errors'].append(error)
    else:
        email = request.GET.get('email')
        initial_data = {
            'email' : email,
        }
        resend_confirmation_form = ResendConfirmationForm(initial=initial_data)
    if 'input_attrs' in data:
        set_input_attrs(resend_confirmation_form, attrs=data['input_attrs'])
    data['resend_confirmation_form'] = resend_confirmation_form
    response = renderer(request, template, data=data)
    return response
示例#9
0
 def __init__(self, instance, *args, **kwargs):
     """Overrides forms.ModelForm.__init__()
     Unlike forms.ModelForm, instance is required
     """
     self.instance = instance
     super(AbstractModelInstanceUpdateForm, self).__init__(instance=instance, *args, **kwargs)
     self._set_save_fields(*args)
     save_fields_dict = dict(zip(self.save_fields, [True] * len(self.save_fields)))
     if args or kwargs:
         # make all non-save fields optional
         for name, field in self.fields.items():
             if name not in save_fields_dict:
                 field.required = False
             else:
                 pass
     else:
         # leave the fields the way they are for rendering a form initially
         pass
     set_input_attrs(self)
     set_input_placeholder_labels(self)
示例#10
0
    def __init__(self, instance, *args, **kwargs):
        """Overrides forms.ModelForm.__init__()
        Unlike forms.ModelForm, instance is required
        """
        self.attrs = kwargs.pop('attrs', {})
        self.use_react = kwargs.pop('use_react', False)
        self.instance = instance
        self._save_fields_lookup = kwargs.pop('save_fields_lookup', {})

        super(AbstractModelInstanceUpdateForm, self).__init__(instance=instance, *args, **kwargs)
        self._set_save_fields(*args)

        if args or kwargs:
            # make all non-save fields optional
            for name, field in self.fields.items():
                if name not in self._save_fields_lookup:
                    field.required = False
                else:
                    pass
        else:
            # leave the fields the way they are for rendering a form initially
            pass
        set_input_attrs(self)
        set_input_placeholder_labels(self)
示例#11
0
 def __init__(self, *args, **kwargs):
     super(OrganizationCustomersImportForm, self).__init__(*args, **kwargs)
     self.label_suffix = ''
     set_input_attrs(self)
     set_input_placeholder_labels(self)
示例#12
0
 def __init__(self, user=None, *args, **kwargs):
     super(AddEmailForm, self).__init__(*args, **kwargs)
     self.user = user
     set_input_attrs(self)
     set_input_placeholder_labels(self)
示例#13
0
 def __init__(self, *args, **kwargs):
     super(ChangePasswordForm, self).__init__(*args, **kwargs)
     self.fields['new_password2'].label = 'Confirm new password'
     set_input_attrs(self)
     set_input_placeholder_labels(self)
示例#14
0
 def __init__(self, *args, **kwargs):
     super(SocialRegistrationEmailForm, self).__init__(*args, **kwargs)
     self.label_suffix = ''
     set_input_attrs(self)
     set_input_placeholder_labels(self)
     self.cascaded_errors = []
示例#15
0
 def __init__(self, *args, **kwargs):
     super(UpdatePasswordForm, self).__init__(*args, **kwargs)
     self.label_suffix = ''
     set_input_placeholder_labels(self)
     set_input_attrs(self)
示例#16
0
 def __init__(self, *args, **kwargs):
     super(PasswordResetFormHtmlEmail, self).__init__(*args, **kwargs)
     self.label_suffix = ''
     set_input_attrs(self)
     set_input_placeholder_labels(self)
示例#17
0
 def __init__(self, *args, **kwargs):
     super(ResendConfirmationForm, self).__init__(*args, **kwargs)
     set_input_attrs(self)
     set_input_placeholder_labels(self)
示例#18
0
 def __init__(self, *args, **kwargs):
     super(NameEmailUserRegistrationForm, self).__init__(*args, **kwargs)
     del self.fields['password2']
     set_input_attrs(self)
     set_input_placeholder_labels(self)
示例#19
0
 def __init__(self, *args, **kwargs):
     super(PrelaunchSignupForm, self).__init__(*args, **kwargs)
     set_input_attrs(self)
     set_input_placeholder_labels(self)
示例#20
0
 def __init__(self, user=None, *args, **kwargs):
     super(AddEmailForm, self).__init__(*args, **kwargs)
     self.user = user
     set_input_attrs(self)
     set_input_placeholder_labels(self)
示例#21
0
 def __init__(self, *args, **kwargs):
     super(ChangePasswordForm, self).__init__(*args, **kwargs)
     self.fields['new_password2'].label = 'Confirm new password'
     set_input_attrs(self)
     set_input_placeholder_labels(self)
示例#22
0
 def __init__(self, *args, **kwargs):
     super(CreditCardForm, self).__init__(*args, **kwargs)
     self.label_suffix = ""
     set_input_placeholder_labels(self)
     set_input_attrs(self)