-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/privacy-settings-1
- Loading branch information
Showing
181 changed files
with
2,945 additions
and
1,745 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,140 @@ | ||
from django.contrib import admin | ||
from .models import Corpus | ||
from django.contrib import admin, messages | ||
from .models import Corpus, CorpusConfiguration, Field | ||
|
||
def show_warning_message(request): | ||
''' | ||
Message to display when loading a form for a resource based on a python class | ||
''' | ||
|
||
messages.add_message( | ||
request, | ||
messages.WARNING, | ||
'Corpus configurations are based on python classes; any changes here will be reset on server startup' | ||
) | ||
|
||
class CorpusAdmin(admin.ModelAdmin): | ||
readonly_fields = ['name', 'description'] | ||
readonly_fields = ['name', 'configuration'] | ||
fields = ['name', 'groups', 'configuration'] | ||
|
||
class InlineFieldAdmin(admin.StackedInline): | ||
model = Field | ||
fields = ['display_name', 'description'] | ||
show_change_link = True | ||
extra = 0 | ||
|
||
class CorpusConfigurationAdmin(admin.ModelAdmin): | ||
readonly_fields = ['corpus'] | ||
|
||
inlines = [ | ||
InlineFieldAdmin | ||
] | ||
|
||
fieldsets = [ | ||
( | ||
None, | ||
{ | ||
'fields': [ | ||
'corpus', | ||
'title', | ||
'description', | ||
'description_page', | ||
'image', | ||
] | ||
} | ||
), ( | ||
'Content', | ||
{ | ||
'fields': [ | ||
'category', | ||
'languages', | ||
'min_date', | ||
'max_date', | ||
'document_context', | ||
] | ||
} | ||
), ( | ||
'Elasticsearch', | ||
{ | ||
'fields': [ | ||
'es_index', | ||
'es_alias', | ||
] | ||
} | ||
), ( | ||
'Scans', | ||
{ | ||
'fields': [ | ||
'scan_image_type', | ||
'allow_image_download', | ||
] | ||
} | ||
), ( | ||
'Word models', | ||
{ | ||
'fields': ['word_models_present'] | ||
} | ||
) | ||
] | ||
|
||
def get_form(self, request, obj=None, **kwargs): | ||
show_warning_message(request) | ||
return super().get_form(request, obj, **kwargs) | ||
|
||
|
||
class FieldAdmin(admin.ModelAdmin): | ||
readonly_fields = ['corpus_configuration'] | ||
|
||
fieldsets = [ | ||
( | ||
None, | ||
{ | ||
'fields': [ | ||
'name', | ||
'corpus_configuration', | ||
'display_name', | ||
'description', | ||
'hidden', | ||
'downloadable', | ||
] | ||
} | ||
), | ||
( | ||
'Indexing options', | ||
{ | ||
'fields': [ | ||
'es_mapping', | ||
'indexed', | ||
'required', | ||
] | ||
} | ||
), ( | ||
'Search interface', | ||
{ | ||
'fields': [ | ||
'search_filter', | ||
'results_overview', | ||
'searchable', | ||
'search_field_core', | ||
'sortable', | ||
'primary_sort', | ||
] | ||
} | ||
), ( | ||
'Visualisations', | ||
{ | ||
'fields': [ | ||
'visualizations', | ||
'visualization_sort', | ||
] | ||
} | ||
) | ||
] | ||
|
||
def get_form(self, request, obj=None, **kwargs): | ||
show_warning_message(request) | ||
return super().get_form(request, obj, **kwargs) | ||
|
||
|
||
admin.site.register(Corpus, CorpusAdmin) | ||
admin.site.register(CorpusConfiguration, CorpusConfigurationAdmin) | ||
admin.site.register(Field, FieldAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.