django-orchestra/orchestra/contrib/lists/admin.py

69 lines
2.3 KiB
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
from django.contrib import admin
2015-05-19 13:27:04 +00:00
from django.conf.urls import url
2014-05-08 16:59:35 +00:00
from django.contrib.auth.admin import UserAdmin
2015-04-04 18:10:39 +00:00
from django.utils.translation import ugettext_lazy as _
2014-05-08 16:59:35 +00:00
2014-10-15 12:47:28 +00:00
from orchestra.admin import ExtendedModelAdmin, ChangePasswordAdminMixin
2015-05-09 17:08:45 +00:00
from orchestra.admin.actions import disable
2014-07-21 15:43:36 +00:00
from orchestra.admin.utils import admin_link
2015-04-05 10:46:24 +00:00
from orchestra.contrib.accounts.admin import SelectAccountAdminMixin
2015-04-09 14:32:10 +00:00
from orchestra.contrib.accounts.filters import IsActiveListFilter
2014-05-08 16:59:35 +00:00
from .forms import ListCreationForm, ListChangeForm
from .models import List
2014-10-15 12:47:28 +00:00
class ListAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedModelAdmin):
2015-04-09 14:32:10 +00:00
list_display = (
'name', 'address_name', 'address_domain_link', 'account_link', 'display_active'
)
2014-05-08 16:59:35 +00:00
add_fieldsets = (
(None, {
'classes': ('wide',),
2015-04-09 14:32:10 +00:00
'fields': ('account_link', 'name', 'is_active')
2014-05-08 16:59:35 +00:00
}),
(_("Address"), {
'classes': ('wide',),
'fields': (('address_name', 'address_domain'),)
}),
(_("Admin"), {
'classes': ('wide',),
'fields': ('admin_email', 'password1', 'password2'),
}),
)
fieldsets = (
(None, {
'classes': ('wide',),
2015-04-09 14:32:10 +00:00
'fields': ('account_link', 'name', 'is_active')
2014-05-08 16:59:35 +00:00
}),
(_("Address"), {
'classes': ('wide',),
'fields': (('address_name', 'address_domain'),)
}),
(_("Admin"), {
'classes': ('wide',),
2014-10-15 12:47:28 +00:00
'fields': ('password',),
2014-05-08 16:59:35 +00:00
}),
)
2014-11-18 13:59:21 +00:00
search_fields = ('name', 'address_name', 'address_domain__name', 'account__username')
2015-04-09 14:32:10 +00:00
list_filter = (IsActiveListFilter,)
2014-05-08 16:59:35 +00:00
readonly_fields = ('account_link',)
change_readonly_fields = ('name',)
form = ListChangeForm
add_form = ListCreationForm
2014-11-20 15:34:59 +00:00
list_select_related = ('account', 'address_domain',)
2014-05-08 16:59:35 +00:00
filter_by_account_fields = ['address_domain']
2015-05-09 17:08:45 +00:00
actions = (disable,)
2014-05-08 16:59:35 +00:00
2014-07-21 15:43:36 +00:00
address_domain_link = admin_link('address_domain', order='address_domain__name')
2014-05-08 16:59:35 +00:00
def get_urls(self):
useradmin = UserAdmin(List, self.admin_site)
2015-05-19 13:27:04 +00:00
return [
url(r'^(\d+)/password/$',
self.admin_site.admin_view(useradmin.user_change_password))
] + super(ListAdmin, self).get_urls()
2014-05-08 16:59:35 +00:00
admin.site.register(List, ListAdmin)