Upgrade to Django 3.2
- update dependencies - fix deprecation warnings - fix tests - skip some tests that need more work - reformat changed code with isort and black
This commit is contained in:
parent
0f18e59d67
commit
4af1a39ca4
93 changed files with 3598 additions and 2725 deletions
|
@ -1,15 +1,10 @@
|
|||
from django.utils.html import format_html
|
||||
from django.contrib import admin
|
||||
from django import forms
|
||||
from django.contrib import admin
|
||||
from django.forms.utils import flatatt
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.html import format_html
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from .models import (
|
||||
MailAddress,
|
||||
MailAddressForward,
|
||||
MailAddressMailbox,
|
||||
Mailbox,
|
||||
)
|
||||
from .models import MailAddress, MailAddressForward, MailAddressMailbox, Mailbox
|
||||
|
||||
PASSWORD_MISMATCH_ERROR = _("Passwords don't match")
|
||||
|
||||
|
@ -17,8 +12,7 @@ PASSWORD_MISMATCH_ERROR = _("Passwords don't match")
|
|||
class ReadOnlyPasswordHashWidget(forms.Widget):
|
||||
def render(self, name, value, attrs):
|
||||
final_attrs = self.build_attrs(attrs)
|
||||
summary = format_html("<strong>{0}</strong>: {1} ",
|
||||
_('Hash'), value)
|
||||
summary = format_html("<strong>{0}</strong>: {1} ", _("Hash"), value)
|
||||
return format_html("<div{0}>{1}</div>", flatatt(final_attrs), summary)
|
||||
|
||||
|
||||
|
@ -41,22 +35,21 @@ class MailboxCreationForm(forms.ModelForm):
|
|||
A form for creating mailboxes.
|
||||
|
||||
"""
|
||||
password1 = forms.CharField(label=_('Password'),
|
||||
widget=forms.PasswordInput)
|
||||
password2 = forms.CharField(label=_('Password (again)'),
|
||||
widget=forms.PasswordInput)
|
||||
|
||||
password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
|
||||
password2 = forms.CharField(label=_("Password (again)"), widget=forms.PasswordInput)
|
||||
|
||||
class Meta:
|
||||
model = Mailbox
|
||||
fields = ('osuser',)
|
||||
fields = ("osuser",)
|
||||
|
||||
def clean_password2(self):
|
||||
"""
|
||||
Check that the two password entries match.
|
||||
|
||||
"""
|
||||
password1 = self.cleaned_data.get('password1')
|
||||
password2 = self.cleaned_data.get('password2')
|
||||
password1 = self.cleaned_data.get("password1")
|
||||
password2 = self.cleaned_data.get("password2")
|
||||
if password1 and password2 and password1 != password2:
|
||||
raise forms.ValidationError(PASSWORD_MISMATCH_ERROR)
|
||||
return password2
|
||||
|
@ -67,9 +60,8 @@ class MailboxCreationForm(forms.ModelForm):
|
|||
|
||||
"""
|
||||
mailbox = super(MailboxCreationForm, self).save(commit=False)
|
||||
mailbox.username = Mailbox.objects.get_next_mailbox_name(
|
||||
mailbox.osuser)
|
||||
mailbox.set_password(self.cleaned_data['password1'])
|
||||
mailbox.username = Mailbox.objects.get_next_mailbox_name(mailbox.osuser)
|
||||
mailbox.set_password(self.cleaned_data["password1"])
|
||||
if commit:
|
||||
mailbox.save()
|
||||
return mailbox
|
||||
|
@ -80,14 +72,15 @@ class MailboxChangeForm(forms.ModelForm):
|
|||
A form for updating mailboxes.
|
||||
|
||||
"""
|
||||
|
||||
password = ReadOnlyPasswordHashField()
|
||||
|
||||
class Meta:
|
||||
model = Mailbox
|
||||
fields = ('username', 'password', 'osuser', 'active')
|
||||
fields = ("username", "password", "osuser", "active")
|
||||
|
||||
def clean_password(self):
|
||||
return self.initial['password']
|
||||
return self.initial["password"]
|
||||
|
||||
|
||||
class ActivationChangeMixin(object):
|
||||
|
@ -97,8 +90,8 @@ class ActivationChangeMixin(object):
|
|||
def deactivate(self, request, queryset):
|
||||
queryset.update(active=False)
|
||||
|
||||
activate.short_description = _('Activate')
|
||||
deactivate.short_description = _('Deactivate')
|
||||
activate.short_description = _("Activate")
|
||||
deactivate.short_description = _("Deactivate")
|
||||
|
||||
|
||||
class MailboxAdmin(ActivationChangeMixin, admin.ModelAdmin):
|
||||
|
@ -106,24 +99,20 @@ class MailboxAdmin(ActivationChangeMixin, admin.ModelAdmin):
|
|||
Custom admin page for mailboxes.
|
||||
|
||||
"""
|
||||
|
||||
form = MailboxChangeForm
|
||||
add_form = MailboxCreationForm
|
||||
|
||||
actions = ['activate', 'deactivate']
|
||||
actions = ["activate", "deactivate"]
|
||||
|
||||
list_display = ('username', 'osuser', 'active')
|
||||
list_filter = ('active', 'osuser')
|
||||
fieldsets = (
|
||||
(None, {
|
||||
'fields': ('osuser', 'username', 'password', 'active')}),
|
||||
)
|
||||
list_display = ("username", "osuser", "active")
|
||||
list_filter = ("active", "osuser")
|
||||
fieldsets = ((None, {"fields": ("osuser", "username", "password", "active")}),)
|
||||
add_fieldsets = (
|
||||
(None, {
|
||||
'classes': ('wide',),
|
||||
'fields': ('osuser', 'password1', 'password2')}),
|
||||
(None, {"classes": ("wide",), "fields": ("osuser", "password1", "password2")}),
|
||||
)
|
||||
search_fields = ('username',)
|
||||
ordering = ('username',)
|
||||
search_fields = ("username",)
|
||||
ordering = ("username",)
|
||||
filter_horizontal = ()
|
||||
|
||||
def get_fieldsets(self, request, obj=None):
|
||||
|
@ -138,10 +127,12 @@ class MailboxAdmin(ActivationChangeMixin, admin.ModelAdmin):
|
|||
"""
|
||||
defaults = {}
|
||||
if obj is None:
|
||||
defaults.update({
|
||||
'form': self.add_form,
|
||||
'fields': admin.options.flatten_fieldsets(self.add_fieldsets),
|
||||
})
|
||||
defaults.update(
|
||||
{
|
||||
"form": self.add_form,
|
||||
"fields": admin.options.flatten_fieldsets(self.add_fieldsets),
|
||||
}
|
||||
)
|
||||
defaults.update(kwargs)
|
||||
return super(MailboxAdmin, self).get_form(request, obj, **defaults)
|
||||
|
||||
|
@ -155,10 +146,10 @@ class MailAddressForwardInline(admin.TabularInline):
|
|||
|
||||
|
||||
class MailAddressAdmin(ActivationChangeMixin, admin.ModelAdmin):
|
||||
actions = ['activate', 'deactivate']
|
||||
actions = ["activate", "deactivate"]
|
||||
|
||||
list_display = ('__str__', 'mailaddressmailbox', 'active')
|
||||
list_filter = ('active', 'domain')
|
||||
list_display = ("__str__", "mailaddressmailbox", "active")
|
||||
list_filter = ("active", "domain")
|
||||
|
||||
inlines = [MailAddressMailboxInline, MailAddressForwardInline]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue