regluit/admin.py

303 lines
9.3 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
2014-10-27 20:57:35 +00:00
from regluit.marc.models import MARCRecord
2015-08-04 16:02:06 +00:00
from regluit.api.models import AllowedRepo
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
2016-03-24 18:43:05 +00:00
from regluit.survey.admin import LandingAdmin, Landing
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
2013-11-07 04:25:52 +00:00
class AcqAdmin(ModelAdmin):
2014-12-22 22:49:05 +00:00
readonly_fields = ('work', 'user', 'lib_acq', 'watermarked')
2013-11-07 04:25:52 +00:00
search_fields = ['user__username']
date_hierarchy = 'created'
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', 'deadline')
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'
2014-07-01 18:14:54 +00:00
fields = ('title', 'description', 'language', 'featured')
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',)
2015-08-28 19:42:30 +00:00
subject_authorities = (('','keywords'),('lcsh', 'LC subjects'), ('lcc', 'LC classifications'), ('bisacsh', 'BISAC heading'), )
class SubjectAdminForm(forms.ModelForm):
authority = forms.ChoiceField(choices=subject_authorities, required=False )
class Meta(object):
model = models.Subject
fields = 'name', 'authority', 'is_visible'
class SubjectAdmin(ModelAdmin):
search_fields = ('name',)
date_hierarchy = 'created'
ordering = ('name',)
2015-08-28 19:42:30 +00:00
form = SubjectAdminForm
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']
2015-07-28 13:41:55 +00:00
class RelationAdmin(ModelAdmin):
list_display = ('code', 'name')
search_fields = ['name']
2013-03-26 14:56:49 +00:00
class EbookAdmin(ModelAdmin):
2015-03-24 17:13:31 +00:00
search_fields = ('edition__title','^url') # search by provider using leading url
list_display = ('__unicode__','created', 'user','edition')
date_hierarchy = 'created'
ordering = ('edition__title',)
2015-03-24 17:13:31 +00:00
exclude = ('edition','user', 'filesize')
class WishlistAdmin(ModelAdmin):
date_hierarchy = 'created'
class UserProfileAdmin(ModelAdmin):
search_fields = ('user__username',)
date_hierarchy = 'created'
exclude = ('user',)
2014-12-22 18:49:56 +00:00
class GiftAdmin(ModelAdmin):
2014-12-22 22:49:05 +00:00
list_display = ('to', 'acq_admin_link', 'giver', )
2014-12-22 18:49:56 +00:00
search_fields = ('giver__username', 'to')
2014-12-22 22:49:05 +00:00
readonly_fields = ('giver', 'acq',)
def acq_admin_link(self, gift):
return "<a href='/admin/core/acq/%s/'>%s</a>" % (gift.acq.id, gift.acq)
acq_admin_link.allow_tags = True
2014-12-22 18:49:56 +00:00
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,
)
2014-10-27 20:57:35 +00:00
user = AutoCompleteSelectField(
OwnerLookup,
widget=AutoCompleteSelectWidget(OwnerLookup),
required=True,
)
2013-07-08 15:14:25 +00:00
class Meta(object):
2014-10-27 20:57:35 +00:00
model = MARCRecord
2013-07-08 15:14:25 +00:00
class MARCRecordAdmin(ModelAdmin):
2014-10-27 20:57:35 +00:00
list_display = ('edition', 'user')
date_hierarchy = 'created'
2013-07-08 15:14:25 +00:00
form = MARCRecordAdminForm
2011-11-30 23:26:41 +00:00
2015-08-04 16:02:06 +00:00
class AllowedRepoAdmin(ModelAdmin):
list_display = ('org', 'repo_name')
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)
2013-11-07 04:25:52 +00:00
admin_site.register(models.Acq, AcqAdmin)
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)
2014-12-22 18:49:56 +00:00
admin_site.register(models.Gift, GiftAdmin)
2014-10-27 20:57:35 +00:00
admin_site.register(MARCRecord, MARCRecordAdmin)
2015-08-04 16:02:06 +00:00
admin_site.register(AllowedRepo, AllowedRepoAdmin)
2015-07-28 13:41:55 +00:00
admin_site.register(models.Relation, RelationAdmin)
# 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)
2016-03-24 18:43:05 +00:00
admin_site.register(Landing, LandingAdmin)