2017-05-20 23:47:14 +00:00
|
|
|
from django.contrib import admin
|
2018-04-16 04:27:13 +00:00
|
|
|
from django import forms
|
|
|
|
from dal import autocomplete
|
2017-06-16 16:06:22 +00:00
|
|
|
from leaflet.admin import LeafletGeoAdmin
|
2017-05-20 23:47:14 +00:00
|
|
|
|
2018-10-12 22:56:27 +00:00
|
|
|
from .models import CaseStudy, CaseStudyDraft, SpatialRefSys, PointOfInterest
|
2018-04-16 04:27:13 +00:00
|
|
|
|
2017-06-16 16:06:22 +00:00
|
|
|
|
2018-04-14 02:40:42 +00:00
|
|
|
class CaseStudyDraftAdmin(admin.ModelAdmin):
|
|
|
|
model = CaseStudyDraft
|
2017-10-08 20:21:51 +00:00
|
|
|
|
2018-04-16 04:27:13 +00:00
|
|
|
|
|
|
|
class CaseStudyAdminForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = CaseStudy
|
|
|
|
widgets = {
|
|
|
|
'coordinate_reference_system': autocomplete.ModelSelect2(
|
|
|
|
url='srs-autocomplete'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
|
2017-10-31 15:00:44 +00:00
|
|
|
class CaseStudyAdmin(LeafletGeoAdmin):
|
2019-03-04 20:03:43 +00:00
|
|
|
list_display = ('id', 'date_created', 'entry_name', 'approved', 'author')
|
2018-03-27 04:14:01 +00:00
|
|
|
actions = ['approve', 'unapprove']
|
2018-04-16 04:27:13 +00:00
|
|
|
form = CaseStudyAdminForm
|
2017-10-08 20:21:51 +00:00
|
|
|
|
2018-03-27 04:14:01 +00:00
|
|
|
def approve(self, request, queryset):
|
|
|
|
updated = queryset.update(approved=True)
|
|
|
|
if updated == 1:
|
|
|
|
message_bit = "1 case study was"
|
|
|
|
else:
|
|
|
|
message_bit = "{0} case studies were".format(updated)
|
|
|
|
self.message_user(request, "{0} successfully approved".format(
|
|
|
|
message_bit
|
|
|
|
))
|
|
|
|
approve.short_description = "Approve selected case studies"
|
|
|
|
|
|
|
|
def unapprove(self, request, queryset):
|
|
|
|
updated = queryset.update(approved=False)
|
|
|
|
if updated == 1:
|
|
|
|
message_bit = "1 case study was"
|
|
|
|
else:
|
|
|
|
message_bit = "{0} case studies were".format(updated)
|
|
|
|
self.message_user(request, "{0} successfully un-approved".format(
|
|
|
|
message_bit
|
|
|
|
))
|
|
|
|
unapprove.short_description = "Un-approve selected case studies"
|
2017-10-08 20:21:51 +00:00
|
|
|
|
|
|
|
admin.site.register(CaseStudy, CaseStudyAdmin)
|
2018-04-16 04:27:13 +00:00
|
|
|
admin.site.register(SpatialRefSys)
|
2018-04-14 02:40:42 +00:00
|
|
|
admin.site.register(CaseStudyDraft, CaseStudyDraftAdmin)
|
2018-10-12 22:56:27 +00:00
|
|
|
admin.site.register(PointOfInterest)
|