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

Missing an admin_invite_user view #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions account/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AccountAppConf(AppConf):

OPEN_SIGNUP = True
LOGIN_URL = "account_login"
INVITE_USER_URL = "account_invite_user"
SIGNUP_REDIRECT_URL = "/"
LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"
Expand Down
8 changes: 7 additions & 1 deletion account/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from django.contrib.auth.models import User

from account.conf import settings
from account.models import EmailAddress
from account.models import EmailAddress, SignupCode


alnum_re = re.compile(r"^\w+$")
Expand Down Expand Up @@ -213,3 +213,9 @@ def clean_email(self):
if not qs.exists() or not settings.ACCOUNT_EMAIL_UNIQUE:
return value
raise forms.ValidationError(_("A user is registered with this email address."))


class SignupCodeForm(forms.ModelForm):
class Meta:
model = SignupCode
fields = ('code', 'max_uses', 'email', 'notes',)
3 changes: 2 additions & 1 deletion account/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from account.views import SignupView, LoginView, LogoutView, DeleteView
from account.views import ConfirmEmailView
from account.views import ChangePasswordView, PasswordResetView, PasswordResetTokenView
from account.views import SettingsView
from account.views import SettingsView, InviteUserView


urlpatterns = patterns("",
Expand All @@ -18,4 +18,5 @@
url(r"^password/reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$", PasswordResetTokenView.as_view(), name="account_password_reset_token"),
url(r"^settings/$", SettingsView.as_view(), name="account_settings"),
url(r"^delete/$", DeleteView.as_view(), name="account_delete"),
url(r"^invite_user/$", InviteUserView.as_view(), name="account_invite_user"),
)
29 changes: 27 additions & 2 deletions account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.views.generic.base import TemplateResponseMixin, View
from django.views.generic.edit import FormView
from django.views.generic.edit import FormView, CreateView

from django.contrib import auth, messages
from django.contrib.auth.models import User
Expand All @@ -19,7 +19,7 @@
from account.conf import settings
from account.forms import SignupForm, LoginUsernameForm
from account.forms import ChangePasswordForm, PasswordResetForm, PasswordResetTokenForm
from account.forms import SettingsForm
from account.forms import SettingsForm, SignupCodeForm
from account.hooks import hookset
from account.mixins import LoginRequiredMixin
from account.models import SignupCode, EmailAddress, EmailConfirmation, Account, AccountDeletion
Expand Down Expand Up @@ -724,3 +724,28 @@ def get_context_data(self, **kwargs):
ctx.update(kwargs)
ctx["ACCOUNT_DELETION_EXPUNGE_HOURS"] = settings.ACCOUNT_DELETION_EXPUNGE_HOURS
return ctx


class InviteUserView(LoginRequiredMixin, CreateView):

template_name = "account/invite_user.html"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The template isn't included in the commit.

form_class = SignupCodeForm

redirect_field_name = "next"
messages = {
"password_changed": {
"level": messages.SUCCESS,
"text": _("Password successfully changed.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value for text doesn't make sense.

}
}

def form_valid(self, form):
signup_code = form.save()
signup_code.send()
messages.success(self.request, _("Invitation sent to user '%s'") % signup_code.email)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use something like _("Invitation sent to user '%(user)s'.") % {'user': signup_code.email} instead.

return super(InviteUserView, self).form_valid(form)

def get_success_url(self, fallback_url=None, **kwargs):
if fallback_url is None:
fallback_url = settings.ACCOUNT_INVITE_USER_URL
return default_redirect(self.request, fallback_url, **kwargs)