-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.py
182 lines (133 loc) · 5.98 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
from django.contrib.gis.db import models
from .models import *
from django.utils.html import format_html
from django.contrib.admin import EmptyFieldListFilter
from django.contrib.gis import admin
from django.utils.translation import gettext_lazy as _
from saintsophia.utils import get_fields, DEFAULT_FIELDS, DEFAULT_EXCLUDE
from leaflet.admin import LeafletGeoAdmin
from django.conf import settings
# from admin_auto_filters.filters import AutocompleteFilter
# from rangefilter.filters import NumericRangeFilter
# from django.contrib.admin import EmptyFieldListFilter
DEFAULT_LONGITUDE = 30.514299
DEFAULT_LATITUDE = 50.452890
DEFAULT_ZOOM = 20
MAX_ZOOM = 24
MIN_ZOOM = 20
@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
list_display = ['text', 'text_ukr']
search_fields = ['text', 'text_ukr']
@admin.register(Language)
class LanguageAdmin(admin.ModelAdmin):
list_display = ['text', 'text_ukr']
search_fields = ['text', 'text_ukr']
@admin.register(ImageType)
class ImageTypeAdmin(admin.ModelAdmin):
list_display = ['text']
search_fields = ['text']
@admin.register(InscriptionType)
class InscriptionTypeAdmin(admin.ModelAdmin):
list_display = ['text', 'text_ukr']
search_fields = ['text', 'text_ukr']
@admin.register(ExtraAlphabeticalSign)
class ExtraAlphabeticalSignAdmin(admin.ModelAdmin):
list_display = ['text', 'text_ukr']
search_fields = ['text', 'text_ukr']
@admin.register(GraffitiCondition)
class GraffitiConditionAdmin(admin.ModelAdmin):
list_display = ['text', 'text_ukr']
search_fields = ['text', 'text_ukr']
@admin.register(GraffitiAlignment)
class GraffitiAlignmentAdmin(admin.ModelAdmin):
list_display = ['text', 'text_ukr']
search_fields = ['text', 'text_ukr']
@admin.register(Genre)
class GenreAdmin(admin.ModelAdmin):
list_display = ['text', 'text_ukr']
search_fields = ['text', 'text_ukr']
@admin.register(DatingCriterium)
class DatingCriteriumAdmin(admin.ModelAdmin):
list_display = ['text', 'text_ukr']
search_fields = ['text', 'text_ukr']
@admin.register(WritingSystem)
class WritingSystemAdmin(admin.ModelAdmin):
list_display = ['text', 'text_ukr']
search_fields = ['text', 'text_ukr']
@admin.register(Medium)
class MediumAdmin(admin.ModelAdmin):
list_display = ['text', 'text_ukr']
search_fields = ['text', 'text_ukr']
@admin.register(Material)
class MaterialAdmin(admin.ModelAdmin):
list_display = ['text', 'text_ukr']
search_fields = ['text', 'text_ukr']
@admin.register(Section)
class SectionAdmin(admin.ModelAdmin):
list_display = ['text', 'text_ukr']
search_fields = ['text', 'text_ukr']
@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
list_display = ['firstname', 'lastname']
search_fields = ['firstname', 'lastname', 'firstname_ukr', 'lastname_ukr']
@admin.register(HistoricalPerson)
class HistoricalPerson(admin.ModelAdmin):
list_display = ['name', 'name_ukr']
search_fields = ['name', 'name_ukr']
@admin.register(BibliographyItem)
class BibliographyItemAdmin(admin.ModelAdmin):
list_display = ['title', 'authors', 'year']
search_fields = ['title', 'authors', 'year']
@admin.register(Documentation)
class DocumentationAdmin(admin.ModelAdmin):
list_display = ['short_title']
search_fields = ['short_title', 'observation']
@admin.register(Panel)
class PanelAdmin(LeafletGeoAdmin, admin.ModelAdmin):
display_raw = True
fields = [*get_fields(Panel, exclude=['id'])]
readonly_fields = [*DEFAULT_FIELDS]
filter_horizontal = ['tags']
list_display = ['title', 'room', 'data_available']
search_fields = ['title', 'room']
filter_horizontal = ['tags']
list_filter = [ ('spatial_position', EmptyFieldListFilter), ('spatial_direction', EmptyFieldListFilter), ("data_available")]
settings_overrides = {
'DEFAULT_CENTER': (DEFAULT_LATITUDE, DEFAULT_LONGITUDE),
'DEFAULT_ZOOM': DEFAULT_ZOOM,
'MAX_ZOOM': MAX_ZOOM,
'MIN_ZOOM': MIN_ZOOM,
'TILES' : [('GROUND FLOOR', 'https://data.dh.gu.se/tiles/saint_sophia_ground_floor/{z}/{x}/{y}.png', {'attribution': '© GRIDH', 'maxNativeZoom':24, 'maxZoom': 25})],
'OVERLAYS': [('SECOND FLOOR', 'https://data.dh.gu.se/tiles/saint_sophia_second_floor/{z}/{x}/{y}.png', {'attribution': '© GRIDH', 'maxNativeZoom':24, 'maxZoom': 25})]
}
change_form_template = 'apps/inscriptions/panel_change_form.html'
@admin.register(Inscription)
class InscriptionAdmin(admin.ModelAdmin,):
filter_horizontal = ['tags', 'genre', 'author', 'condition', 'alignment', 'extra_alphabetical_sign', 'bibliography', 'mentioned_person', 'dating_criteria']
list_display = ['panel', 'id', 'language', 'title']
search_fields = ['id', 'language__text', 'panel__title']
autocomplete_fields = ['panel', 'inscriber']
change_form_template = 'apps/inscriptions/inscription_change_form.html'
@admin.register(Image)
class ImageAdmin(admin.ModelAdmin,):
fields = ['image_preview', *get_fields(Image, exclude=['id'])]
readonly_fields = ['iiif_file', 'uuid', 'image_preview', *DEFAULT_FIELDS]
autocomplete_fields = ['panel', 'inscription']
list_display = ['panel', 'inscription', 'type_of_image']
search_fields = ['panel__title', 'type_of_image__text', 'iiif_file']
list_per_page = 10
def image_preview(self, obj):
return format_html(f'<img src="{settings.IIIF_URL}{obj.iiif_file}/full/full/0/default.jpg" height="300" />')
def thumbnail_preview(self, obj):
return format_html(f'<img src="{settings.IIIF_URL}{obj.iiif_file}/full/full/0/default.jpg" height="100" />')
@admin.register(ObjectRTI)
class ObjectRTIAdmin(admin.ModelAdmin):
autocomplete_fields = ['panel']
list_display = ['panel']
search_fields = ['panel__title', 'url']
@admin.register(ObjectMesh3D)
class ObjectMesh3DAdmin(admin.ModelAdmin):
autocomplete_fields = ['panel']
list_display = ['panel']
search_fields = ['panel__title', 'url']