Commit 2ad9d3b3 authored by Michal Čihař's avatar Michal Čihař

Require user email in the admin interface

Fixes #1086
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent f066ffe1
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
from django import forms
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.admin import UserAdmin from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.models import User from django.contrib.auth.models import User
from weblate.accounts.models import Profile, VerifiedEmail, AutoGroup from weblate.accounts.models import Profile, VerifiedEmail, AutoGroup
...@@ -53,12 +55,35 @@ class AutoGroupAdmin(admin.ModelAdmin): ...@@ -53,12 +55,35 @@ class AutoGroupAdmin(admin.ModelAdmin):
admin.site.register(AutoGroup, AutoGroupAdmin) admin.site.register(AutoGroup, AutoGroupAdmin)
class WeblateUserChangeForm(UserChangeForm):
def __init__(self, *args, **kwargs):
super(WeblateUserChangeForm, self).__init__(*args, **kwargs)
self.fields['email'].required = True
class WeblateUserCreationForm(UserCreationForm):
class Meta(object):
fields = ('username', 'email')
def __init__(self, *args, **kwargs):
super(WeblateUserCreationForm, self).__init__(*args, **kwargs)
self.fields['email'].required = True
class WeblateUserAdmin(UserAdmin): class WeblateUserAdmin(UserAdmin):
''' '''
Custom UserAdmin to add listing of group membership and whether user is Custom UserAdmin to add listing of group membership and whether user is
active. active.
''' '''
list_display = UserAdmin.list_display + ('is_active', 'user_groups', 'id') list_display = UserAdmin.list_display + ('is_active', 'user_groups', 'id')
form = WeblateUserChangeForm
add_form = WeblateUserCreationForm
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('username', 'email', 'password1', 'password2'),
}),
)
def user_groups(self, obj): def user_groups(self, obj):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment