Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with pinax.apps.account #1

Open
aehlke opened this issue Feb 18, 2011 · 5 comments
Open

Doesn't work with pinax.apps.account #1

aehlke opened this issue Feb 18, 2011 · 5 comments

Comments

@aehlke
Copy link
Contributor

aehlke commented Feb 18, 2011

I'm using the .9x master dev version of Pinax and was able to get lazysignup working with pinax's account app with the following form, which I pass to the convert view:

from account.forms import SignupForm as PinaxSignupForm

class PinaxLazyConvertForm(PinaxSignupForm):
    '''
    `PinaxSignupForm` is a subclass of forms.Form.
    django-lazysignup expects this form to behave like a ModelForm.
    So it will pass `instance` to __init__, which we will save to use 
    later when we create the user when the form is saved.
    '''
    def __init__(self, *args, **kwargs):
        self.instance = None
        if 'instance' in kwargs:
            # PinaxSignupForm breaks if we pass it this
            self.instance = kwargs.pop('instance')
        super(LazyConvertForm, self).__init__(*args, **kwargs)

    def create_user(self, username=None, commit=True):
        '''Gets called by PinaxSignupForm.save'''
        user = self.instance or User()
        if username is None:
            raise NotImplementedError("SignupForm.create_user does not handle "
                "username=None case. You must override this method.")
        user.username = username
        user.email = self.cleaned_data["email"].strip().lower()
        password = self.cleaned_data.get("password1")
        if password:
            user.set_password(password)
        else:
            user.set_unusable_password()
        if commit:
            user.save()
        return user

    def get_credentials(self):
        return {
            'username': self.cleaned_data['username'],
            'password': self.cleaned_data['password1']
        }
@aehlke
Copy link
Contributor Author

aehlke commented Feb 18, 2011

You could probably add this to utils or something. Or just leave it here for reference ;)

@aehlke
Copy link
Contributor Author

aehlke commented Feb 19, 2011

Oops, the line in init should be this instead:

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

@danfairs
Copy link
Owner

Thanks for the report. I'm not sure this belongs in lazysignup itself - I certainly don't want to grow a dependency on the accounts app! But it might be a useful note for the docs. I'll leave the ticket open for now, and review this for inclusion next time I make changes.

@aehlke
Copy link
Contributor Author

aehlke commented Feb 21, 2011

You're right, I'm not sure where it's best to put it. Doesn't belong in pinax either. It's not entirely unlikely that someone would want to use this package w/ pinax though, so some note of it would be nice.

@danfairs
Copy link
Owner

If more than documentation was required, I'd probably just drop a pinax.py in there, containing the integration code.

I imagine it'll get done when I do a Pinax project :)

Of course if you wanted to fork the project and add it with docs and tests, I'd be happy to merge that. The tests already use the mock package, so you should be able to mock out any parts of the Pinax framework required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants