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

63 lines
2.1 KiB
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
from django.contrib import admin
from django.conf.urls import patterns
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
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
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):
2014-05-08 16:59:35 +00:00
list_display = ('name', 'address_name', 'address_domain_link', 'account_link')
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('account_link', 'name',)
}),
(_("Address"), {
'classes': ('wide',),
'fields': (('address_name', 'address_domain'),)
}),
(_("Admin"), {
'classes': ('wide',),
'fields': ('admin_email', 'password1', 'password2'),
}),
)
fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('account_link', 'name',)
}),
(_("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')
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']
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)
return patterns('',
(r'^(\d+)/password/$',
self.admin_site.admin_view(useradmin.user_change_password))
) + super(ListAdmin, self).get_urls()
admin.site.register(List, ListAdmin)