regluit/admin.py

260 lines
7.6 KiB
Python
Raw Normal View History

2013-06-03 16:31:39 +00:00
"""
external library imports
"""
import pickle
"""
2013-07-08 15:14:25 +00:00
django imports
"""
2013-03-26 14:56:49 +00:00
from django import forms
from django.contrib.admin import ModelAdmin
from django.contrib.admin.sites import AdminSite
2013-06-03 16:31:39 +00:00
from django.contrib.auth.models import User
from djcelery.admin import (
TaskState,
WorkerState,
TaskMonitor,
WorkerMonitor,
IntervalSchedule,
CrontabSchedule,
PeriodicTask,
PeriodicTaskAdmin
)
from notification.admin import NoticeTypeAdmin, NoticeSettingAdmin, NoticeAdmin
from notification.models import (
NoticeType,
NoticeSetting,
Notice,
ObservedItem,
NoticeQueueBatch
)
2013-03-26 14:56:49 +00:00
from selectable.forms import AutoCompleteSelectWidget,AutoCompleteSelectField
2013-06-03 16:31:39 +00:00
"""
regluit imports
"""
2011-11-30 23:26:41 +00:00
from regluit import payment
2013-06-03 16:31:39 +00:00
from regluit.core import models
2013-07-08 15:14:25 +00:00
from regluit.core.lookups import (
PublisherNameLookup,
WorkLookup,
OwnerLookup,
EditionLookup
)
2013-10-11 02:31:31 +00:00
from regluit.libraryauth.models import Library, Block, CardPattern, EmailPattern
from regluit.libraryauth.admin import LibraryAdmin, BlockAdmin, CardPatternAdmin, EmailPatternAdmin
class RegluitAdmin(AdminSite):
2011-11-19 23:27:15 +00:00
login_template = 'registration/login.html'
2011-11-19 17:07:44 +00:00
class UserAdmin(ModelAdmin):
2013-05-06 19:41:45 +00:00
search_fields = ['username', 'email']
list_display = ('username', 'email')
2011-11-19 17:07:44 +00:00
2013-05-03 22:05:43 +00:00
class ClaimAdminForm(forms.ModelForm):
work = AutoCompleteSelectField(
WorkLookup,
widget=AutoCompleteSelectWidget(WorkLookup),
required=True,
)
user = AutoCompleteSelectField(
OwnerLookup,
widget=AutoCompleteSelectWidget(OwnerLookup),
required=True,
)
class Meta(object):
model = models.Claim
class ClaimAdmin(ModelAdmin):
2013-05-06 19:41:45 +00:00
list_display = ('work', 'rights_holder', 'status')
date_hierarchy = 'created'
2013-05-03 22:05:43 +00:00
form = ClaimAdminForm
class RightsHolderAdminForm(forms.ModelForm):
owner = AutoCompleteSelectField(
OwnerLookup,
widget=AutoCompleteSelectWidget(OwnerLookup),
required=True,
)
class Meta(object):
model = models.RightsHolder
class RightsHolderAdmin(ModelAdmin):
date_hierarchy = 'created'
form = RightsHolderAdminForm
class PremiumAdmin(ModelAdmin):
list_display = ('campaign', 'amount', 'description')
date_hierarchy = 'created'
class CampaignAdmin(ModelAdmin):
2013-05-06 19:41:45 +00:00
list_display = ('work', 'created', 'status')
date_hierarchy = 'created'
exclude = ('edition', 'work', 'managers', 'publisher', 'activated')
2013-05-06 19:41:45 +00:00
search_fields = ['work']
class WorkAdmin(ModelAdmin):
2013-05-06 19:41:45 +00:00
search_fields = ['title']
ordering = ('title',)
list_display = ('title', 'created')
date_hierarchy = 'created'
2013-05-28 14:06:21 +00:00
fields = ('title', 'description', 'language')
class AuthorAdmin(ModelAdmin):
2013-05-03 22:28:10 +00:00
search_fields = ('name',)
date_hierarchy = 'created'
ordering = ('name',)
2013-05-03 22:28:10 +00:00
exclude = ('editions',)
class SubjectAdmin(ModelAdmin):
search_fields = ('name',)
date_hierarchy = 'created'
ordering = ('name',)
exclude = ('works',)
2013-05-03 22:39:27 +00:00
class EditionAdminForm(forms.ModelForm):
work = AutoCompleteSelectField(
WorkLookup,
label='Work',
widget=AutoCompleteSelectWidget(WorkLookup),
required=True,
)
publisher_name = AutoCompleteSelectField(
PublisherNameLookup,
label='Name',
widget=AutoCompleteSelectWidget(PublisherNameLookup),
required=True,
)
class Meta(object):
model = models.Edition
class EditionAdmin(ModelAdmin):
list_display = ('title', 'publisher_name', 'created')
date_hierarchy = 'created'
ordering = ('title',)
2013-05-03 22:39:27 +00:00
form = EditionAdminForm
2013-03-26 14:56:49 +00:00
class PublisherAdminForm(forms.ModelForm):
name = AutoCompleteSelectField(
PublisherNameLookup,
label='Name',
widget=AutoCompleteSelectWidget(PublisherNameLookup),
required=True,
)
class Meta(object):
model = models.Publisher
class PublisherAdmin(ModelAdmin):
list_display = ('name', 'url', 'logo_url', 'description')
ordering = ('name',)
2013-03-26 14:56:49 +00:00
form = PublisherAdminForm
class PublisherNameAdmin(ModelAdmin):
list_display = ('name', 'publisher')
ordering = ('name',)
search_fields = ['name']
2013-03-26 14:56:49 +00:00
class EbookAdmin(ModelAdmin):
search_fields = ('edition__title',)
list_display = ('__unicode__','created', 'user','edition')
date_hierarchy = 'created'
ordering = ('edition__title',)
exclude = ('edition','user')
class WishlistAdmin(ModelAdmin):
date_hierarchy = 'created'
class UserProfileAdmin(ModelAdmin):
search_fields = ('user__username',)
date_hierarchy = 'created'
exclude = ('user',)
class CeleryTaskAdmin(ModelAdmin):
pass
2011-11-30 23:26:41 +00:00
class TransactionAdmin(ModelAdmin):
list_display = ('campaign', 'user', 'amount', 'status', 'error')
2011-11-30 23:26:41 +00:00
date_hierarchy = 'date_created'
class PaymentResponseAdmin(ModelAdmin):
pass
class ReceiverAdmin(ModelAdmin):
ordering = ('email',)
def notice_queue_batch_data(obj):
return pickle.loads(str(obj.pickled_data).decode("base64"))
notice_queue_batch_data.short_description = 'unpickled_data'
class NoticeQueueBatchAdmin(ModelAdmin):
# show the pickled data in a form humans can parse more easily
list_display = (notice_queue_batch_data,)
pass
class PressAdmin(ModelAdmin):
list_display = ('title', 'source', 'date')
ordering = ('-date',)
2013-07-08 15:14:25 +00:00
class MARCRecordAdminForm(forms.ModelForm):
edition = AutoCompleteSelectField(
EditionLookup,
widget=AutoCompleteSelectWidget(EditionLookup),
required=True,
)
class Meta(object):
model = models.MARCRecord
class MARCRecordAdmin(ModelAdmin):
2013-07-08 19:54:36 +00:00
list_display = ('edition',)
2013-07-08 15:14:25 +00:00
form = MARCRecordAdminForm
2011-11-30 23:26:41 +00:00
admin_site = RegluitAdmin("Admin")
2013-03-26 14:56:49 +00:00
admin_site.register(User, UserAdmin)
admin_site.register(Library, LibraryAdmin)
admin_site.register(Block, BlockAdmin)
admin_site.register(CardPattern, CardPatternAdmin)
2013-10-11 02:31:31 +00:00
admin_site.register(EmailPattern, EmailPatternAdmin)
admin_site.register(models.Work, WorkAdmin)
admin_site.register(models.Claim, ClaimAdmin)
admin_site.register(models.RightsHolder, RightsHolderAdmin)
admin_site.register(models.Premium, PremiumAdmin)
admin_site.register(models.Campaign, CampaignAdmin)
admin_site.register(models.Author, AuthorAdmin)
admin_site.register(models.Publisher, PublisherAdmin)
admin_site.register(models.PublisherName, PublisherNameAdmin)
admin_site.register(models.Subject, SubjectAdmin)
admin_site.register(models.Edition, EditionAdmin)
admin_site.register(models.Ebook, EbookAdmin)
admin_site.register(models.Wishlist, WishlistAdmin)
admin_site.register(models.UserProfile, UserProfileAdmin)
admin_site.register(models.CeleryTask, CeleryTaskAdmin)
admin_site.register(models.Press, PressAdmin)
2013-07-08 15:14:25 +00:00
admin_site.register(models.MARCRecord, MARCRecordAdmin)
# payments
2011-11-30 23:26:41 +00:00
admin_site.register(payment.models.Transaction, TransactionAdmin)
admin_site.register(payment.models.PaymentResponse, PaymentResponseAdmin)
admin_site.register(payment.models.Receiver, ReceiverAdmin)
# add the djcelery admin interface
# https://raw.github.com/ask/django-celery/2.4/djcelery/admin.py
admin_site.register(TaskState, TaskMonitor)
admin_site.register(WorkerState, WorkerMonitor)
admin_site.register(IntervalSchedule)
admin_site.register(CrontabSchedule)
admin_site.register(PeriodicTask, PeriodicTaskAdmin)
# add the django-notification admin panel
# https://github.com/jtauber/django-notification/blob/master/notification/admin.py
admin_site.register(NoticeQueueBatch, NoticeQueueBatchAdmin)
admin_site.register(NoticeType, NoticeTypeAdmin)
admin_site.register(NoticeSetting, NoticeSettingAdmin)
admin_site.register(Notice, NoticeAdmin)
admin_site.register(ObservedItem)