diff --git a/cfp/forms.py b/cfp/forms.py index ce36d02..946265f 100644 --- a/cfp/forms.py +++ b/cfp/forms.py @@ -2,6 +2,8 @@ from django import forms from django.forms.models import modelform_factory from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User +from django.contrib.auth.forms import UsernameField +from django.utils.translation import ugettext as _ from django_select2.forms import ModelSelect2MultipleWidget @@ -31,3 +33,22 @@ class UsersWidget(ModelSelect2MultipleWidget): ConferenceForm = modelform_factory(Conference, fields=['name', 'home', 'venue', 'city', 'contact_email', 'staff',], widgets={'staff': UsersWidget(),}) + + +class CreateUserForm(forms.ModelForm): + class Meta: + model = User + fields = ("username", "email") + field_classes = {'username': UsernameField} + + def clean_email(self): + email = self.cleaned_data.get('email') + if email and User.objects.filter(email=email).exists(): + raise forms.ValidationError(_('A user with that email already exists.')) + + def save(self, commit=True): + user = super().save(commit=False) + user.set_unusable_password() + if commit: + user.save() + return user diff --git a/cfp/templates/cfp/staff/conference.html b/cfp/templates/cfp/staff/conference.html index a336cb9..852c44c 100644 --- a/cfp/templates/cfp/staff/conference.html +++ b/cfp/templates/cfp/staff/conference.html @@ -10,6 +10,7 @@
diff --git a/cfp/templates/cfp/staff/create_user.html b/cfp/templates/cfp/staff/create_user.html new file mode 100644 index 0000000..7e433cc --- /dev/null +++ b/cfp/templates/cfp/staff/create_user.html @@ -0,0 +1,17 @@ +{% extends 'cfp/staff/base.html' %} +{% load i18n crispy_forms_tags %} + +{% block conferencetab %} class="active"{% endblock %} + +{% block content %} + +