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
|
2011-11-19 16:58:59 +00:00
|
|
|
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
|
2011-11-19 16:58:59 +00:00
|
|
|
|
2016-03-24 18:43:05 +00:00
|
|
|
from regluit.survey.admin import LandingAdmin, Landing
|
|
|
|
|
2011-11-19 16:58:59 +00:00
|
|
|
class RegluitAdmin(AdminSite):
|
2011-11-19 23:27:15 +00:00
|
|
|
login_template = 'registration/login.html'
|
2011-11-19 16:58:59 +00:00
|
|
|
|
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
|
|
|
|
|
2011-11-19 16:58:59 +00:00
|
|
|
class ClaimAdmin(ModelAdmin):
|
2013-05-06 19:41:45 +00:00
|
|
|
list_display = ('work', 'rights_holder', 'status')
|
2011-11-19 16:58:59 +00:00
|
|
|
date_hierarchy = 'created'
|
2013-05-03 22:05:43 +00:00
|
|
|
form = ClaimAdminForm
|
2013-05-03 23:21:10 +00:00
|
|
|
|
|
|
|
class RightsHolderAdminForm(forms.ModelForm):
|
|
|
|
owner = AutoCompleteSelectField(
|
|
|
|
OwnerLookup,
|
|
|
|
widget=AutoCompleteSelectWidget(OwnerLookup),
|
|
|
|
required=True,
|
|
|
|
)
|
|
|
|
class Meta(object):
|
|
|
|
model = models.RightsHolder
|
2011-11-19 16:58:59 +00:00
|
|
|
|
|
|
|
class RightsHolderAdmin(ModelAdmin):
|
|
|
|
date_hierarchy = 'created'
|
2013-05-03 23:21:10 +00:00
|
|
|
form = RightsHolderAdminForm
|
2011-11-19 16:58:59 +00:00
|
|
|
|
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'
|
|
|
|
|
2011-11-19 16:58:59 +00:00
|
|
|
class PremiumAdmin(ModelAdmin):
|
2013-05-06 19:53:49 +00:00
|
|
|
list_display = ('campaign', 'amount', 'description')
|
2011-11-19 16:58:59 +00:00
|
|
|
date_hierarchy = 'created'
|
|
|
|
|
|
|
|
class CampaignAdmin(ModelAdmin):
|
2013-05-06 19:41:45 +00:00
|
|
|
list_display = ('work', 'created', 'status')
|
2011-11-19 16:58:59 +00:00
|
|
|
date_hierarchy = 'created'
|
2014-02-06 00:33:55 +00:00
|
|
|
exclude = ('edition', 'work', 'managers', 'publisher', 'activated', 'deadline')
|
2013-05-06 19:41:45 +00:00
|
|
|
search_fields = ['work']
|
2011-11-19 16:58:59 +00:00
|
|
|
|
|
|
|
class WorkAdmin(ModelAdmin):
|
2013-05-06 19:41:45 +00:00
|
|
|
search_fields = ['title']
|
2011-11-19 16:58:59 +00:00
|
|
|
ordering = ('title',)
|
|
|
|
list_display = ('title', 'created')
|
|
|
|
date_hierarchy = 'created'
|
2014-07-01 18:14:54 +00:00
|
|
|
fields = ('title', 'description', 'language', 'featured')
|
2011-11-19 16:58:59 +00:00
|
|
|
|
|
|
|
class AuthorAdmin(ModelAdmin):
|
2013-05-03 22:28:10 +00:00
|
|
|
search_fields = ('name',)
|
2011-11-19 16:58:59 +00:00
|
|
|
date_hierarchy = 'created'
|
2011-11-19 20:10:10 +00:00
|
|
|
ordering = ('name',)
|
2013-05-03 22:28:10 +00:00
|
|
|
exclude = ('editions',)
|
2011-11-19 16:58:59 +00:00
|
|
|
|
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'
|
|
|
|
|
|
|
|
|
2011-11-19 16:58:59 +00:00
|
|
|
class SubjectAdmin(ModelAdmin):
|
2013-05-03 23:21:10 +00:00
|
|
|
search_fields = ('name',)
|
2011-11-19 16:58:59 +00:00
|
|
|
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
|
|
|
|
|
2011-11-19 16:58:59 +00:00
|
|
|
class EditionAdmin(ModelAdmin):
|
2013-03-26 03:41:19 +00:00
|
|
|
list_display = ('title', 'publisher_name', 'created')
|
2011-11-19 16:58:59 +00:00
|
|
|
date_hierarchy = 'created'
|
|
|
|
ordering = ('title',)
|
2013-05-03 22:39:27 +00:00
|
|
|
form = EditionAdminForm
|
2011-11-19 16:58:59 +00:00
|
|
|
|
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
|
|
|
|
|
2013-03-26 03:41:19 +00:00
|
|
|
class PublisherAdmin(ModelAdmin):
|
|
|
|
list_display = ('name', 'url', 'logo_url', 'description')
|
|
|
|
ordering = ('name',)
|
2013-03-26 14:56:49 +00:00
|
|
|
form = PublisherAdminForm
|
2013-03-26 18:12:58 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2011-11-19 16:58:59 +00:00
|
|
|
class EbookAdmin(ModelAdmin):
|
2015-03-24 17:13:31 +00:00
|
|
|
search_fields = ('edition__title','^url') # search by provider using leading url
|
2013-04-20 14:34:44 +00:00
|
|
|
list_display = ('__unicode__','created', 'user','edition')
|
2011-11-19 16:58:59 +00:00
|
|
|
date_hierarchy = 'created'
|
|
|
|
ordering = ('edition__title',)
|
2015-03-24 17:13:31 +00:00
|
|
|
exclude = ('edition','user', 'filesize')
|
2011-11-19 16:58:59 +00:00
|
|
|
|
|
|
|
class WishlistAdmin(ModelAdmin):
|
|
|
|
date_hierarchy = 'created'
|
|
|
|
|
|
|
|
class UserProfileAdmin(ModelAdmin):
|
2013-05-03 23:21:10 +00:00
|
|
|
search_fields = ('user__username',)
|
2011-11-19 16:58:59 +00:00
|
|
|
date_hierarchy = 'created'
|
2013-05-03 23:21:10 +00:00
|
|
|
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
|
|
|
|
2012-03-30 19:27:35 +00:00
|
|
|
class CeleryTaskAdmin(ModelAdmin):
|
|
|
|
pass
|
2011-11-19 16:58:59 +00:00
|
|
|
|
2011-11-30 23:26:41 +00:00
|
|
|
class TransactionAdmin(ModelAdmin):
|
2013-05-06 19:53:49 +00:00
|
|
|
list_display = ('campaign', 'user', 'amount', 'status', 'error')
|
2011-11-30 23:26:41 +00:00
|
|
|
date_hierarchy = 'date_created'
|
2012-01-03 18:37:20 +00:00
|
|
|
|
|
|
|
class PaymentResponseAdmin(ModelAdmin):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class ReceiverAdmin(ModelAdmin):
|
2012-04-19 00:44:42 +00:00
|
|
|
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
|
2013-04-08 23:46:59 +00:00
|
|
|
|
|
|
|
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')
|
|
|
|
|
2011-11-19 16:58:59 +00:00
|
|
|
admin_site = RegluitAdmin("Admin")
|
|
|
|
|
2013-03-26 14:56:49 +00:00
|
|
|
admin_site.register(User, UserAdmin)
|
2013-10-02 16:02:08 +00:00
|
|
|
admin_site.register(Library, LibraryAdmin)
|
2013-10-08 19:37:22 +00:00
|
|
|
admin_site.register(Block, BlockAdmin)
|
2013-10-10 06:41:50 +00:00
|
|
|
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)
|
2011-11-19 16:58:59 +00:00
|
|
|
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)
|
2013-03-26 03:41:19 +00:00
|
|
|
admin_site.register(models.Publisher, PublisherAdmin)
|
2013-03-26 18:12:58 +00:00
|
|
|
admin_site.register(models.PublisherName, PublisherNameAdmin)
|
2011-11-19 16:58:59 +00:00
|
|
|
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)
|
2012-03-30 19:27:35 +00:00
|
|
|
admin_site.register(models.CeleryTask, CeleryTaskAdmin)
|
2013-04-08 23:46:59 +00:00
|
|
|
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)
|
2012-03-30 19:27:35 +00:00
|
|
|
|
|
|
|
# payments
|
|
|
|
|
2011-11-30 23:26:41 +00:00
|
|
|
admin_site.register(payment.models.Transaction, TransactionAdmin)
|
2012-01-03 18:37:20 +00:00
|
|
|
admin_site.register(payment.models.PaymentResponse, PaymentResponseAdmin)
|
|
|
|
admin_site.register(payment.models.Receiver, ReceiverAdmin)
|
2012-03-30 19:27:35 +00:00
|
|
|
|
|
|
|
# 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)
|
2012-04-19 00:44:42 +00:00
|
|
|
|
|
|
|
# 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)
|