-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a boolean field (searchable) to the manifest model so we can supp…
…ress/remove some from the index.
- Loading branch information
Showing
5 changed files
with
330 additions
and
149 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Django admin module for manifests""" | ||
|
||
from django.contrib import admin | ||
from django.http import HttpResponseRedirect | ||
from django.http.request import HttpRequest | ||
|
@@ -14,25 +15,43 @@ | |
from .views import AddToCollectionsView, MetadataImportView | ||
from ..kollections.models import Collection | ||
|
||
|
||
class ManifestResource(resources.ModelResource): | ||
"""Django admin manifest resource.""" | ||
|
||
collection_id = fields.Field( | ||
column_name='collections', | ||
attribute='collections', | ||
widget=ManyToManyWidget(Collection, field='label') | ||
column_name="collections", | ||
attribute="collections", | ||
widget=ManyToManyWidget(Collection, field="label"), | ||
) | ||
image_server_link = fields.Field( | ||
column_name='image_server', | ||
attribute='image_server', | ||
widget=ForeignKeyWidget(ImageServer, 'image_server') | ||
column_name="image_server", | ||
attribute="image_server", | ||
widget=ForeignKeyWidget(ImageServer, "image_server"), | ||
) | ||
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring | ||
|
||
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring | ||
model = Manifest | ||
import_id_fields = ('id',) | ||
import_id_fields = ("id",) | ||
fields = ( | ||
'id', 'pid', 'label', 'summary', 'author', | ||
'published_city', 'published_date', 'publisher', 'image_server_link' | ||
'pdf', 'metadata', 'attribution', 'logo', 'logo_url', 'license', 'viewingdirection', 'collection_id' | ||
"id", | ||
"pid", | ||
"label", | ||
"summary", | ||
"author", | ||
"searchable", | ||
"published_city", | ||
"published_date", | ||
"publisher", | ||
"image_server_link", | ||
"pdf", | ||
"metadata", | ||
"attribution", | ||
"logo", | ||
"logo_url", | ||
"license", | ||
"viewingdirection", | ||
"collection_id", | ||
) | ||
|
||
|
||
|
@@ -47,6 +66,7 @@ class RelatedLinksInline(admin.TabularInline): | |
extra = 1 | ||
min_num = 0 | ||
|
||
|
||
class SummernoteMixin(SummernoteModelAdmin): | ||
class Media: | ||
# NOTE: have to include these js and css dependencies for summernote when not using iframe | ||
|
@@ -55,62 +75,89 @@ class Media: | |
"//cdn.jsdelivr.net/npm/[email protected]/jquery.ui.widget.min.js", | ||
) | ||
css = { | ||
"all": ["//cdn.jsdelivr.net/npm/[email protected]/dist/summernote-lite.min.css"], | ||
"all": [ | ||
"//cdn.jsdelivr.net/npm/[email protected]/dist/summernote-lite.min.css" | ||
], | ||
} | ||
|
||
|
||
class ManifestAdmin(ImportExportModelAdmin, SummernoteMixin, admin.ModelAdmin): | ||
"""Django admin configuration for manifests""" | ||
|
||
resource_class = ManifestResource | ||
exclude = ('id',) | ||
filter_horizontal = ('collections',) | ||
list_display = ('id', 'pid', 'label', 'created_at', 'author', 'published_date', 'published_city', 'publisher') | ||
search_fields = ('id', 'pid', 'label', 'author', 'published_date') | ||
summernote_fields = ('summary',) | ||
exclude = ("id",) | ||
filter_horizontal = ("collections",) | ||
list_display = ( | ||
"id", | ||
"pid", | ||
"label", | ||
"created_at", | ||
"author", | ||
"published_date", | ||
"published_city", | ||
"publisher", | ||
) | ||
search_fields = ("id", "pid", "label", "author", "published_date") | ||
summernote_fields = ("summary",) | ||
form = ManifestAdminForm | ||
actions = ['add_to_collections_action'] | ||
actions = ["add_to_collections_action"] | ||
inlines = [RelatedLinksInline] | ||
change_list_template = 'admin/change_list_override.html' | ||
change_list_template = "admin/change_list_override.html" | ||
|
||
def add_to_collections_action(self, request, queryset): | ||
"""Action choose manifests to add to collections""" | ||
selected = queryset.values_list('pk', flat=True) | ||
selected_ids = ','.join(str(pk) for pk in selected) | ||
return HttpResponseRedirect(f'add_to_collections/?ids={selected_ids}') | ||
add_to_collections_action.short_description = 'Add selected manifests to collection(s)' | ||
selected = queryset.values_list("pk", flat=True) | ||
selected_ids = ",".join(str(pk) for pk in selected) | ||
return HttpResponseRedirect(f"add_to_collections/?ids={selected_ids}") | ||
|
||
add_to_collections_action.short_description = ( | ||
"Add selected manifests to collection(s)" | ||
) | ||
|
||
def get_urls(self): | ||
urls = super().get_urls() | ||
my_urls = [ | ||
path( | ||
'add_to_collections/', | ||
"add_to_collections/", | ||
self.admin_site.admin_view(AddToCollectionsView.as_view()), | ||
{'model_admin': self, }, | ||
{ | ||
"model_admin": self, | ||
}, | ||
name="AddManifestsToCollections", | ||
), | ||
path( | ||
'manifest_metadata_import/', | ||
"manifest_metadata_import/", | ||
self.admin_site.admin_view(MetadataImportView.as_view()), | ||
{'model_admin': self, }, | ||
{ | ||
"model_admin": self, | ||
}, | ||
name="MultiManifestMetadataImport", | ||
) | ||
), | ||
] | ||
return my_urls + urls | ||
|
||
|
||
class NoteAdmin(admin.ModelAdmin): | ||
"""Django admin configuration for a note.""" | ||
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring | ||
|
||
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring | ||
model = Note | ||
|
||
|
||
class ImageServerResource(resources.ModelResource): | ||
"""Django admin ImageServer resource.""" | ||
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring | ||
|
||
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring | ||
model = ImageServer | ||
fields = ('id', 'server_base', 'storage_service', 'storage_path') | ||
fields = ("id", "server_base", "storage_service", "storage_path") | ||
|
||
|
||
class ImageServerAdmin(ImportExportModelAdmin, admin.ModelAdmin): | ||
"""Django admin settings for ImageServer.""" | ||
|
||
resource_class = ImageServerResource | ||
list_display = ('server_base',) | ||
list_display = ("server_base",) | ||
|
||
|
||
admin.site.register(Manifest, ManifestAdmin) | ||
admin.site.register(Note, NoteAdmin) | ||
|
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 3.2.23 on 2025-01-13 14:01 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('manifests', '0058_alter_relatedlink'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='manifest', | ||
name='searchable', | ||
field=models.BooleanField(default=True), | ||
), | ||
migrations.AlterField( | ||
model_name='imageserver', | ||
name='storage_service', | ||
field=models.CharField(choices=[('sftp', 'SFTP'), ('s3', 'S3'), ('remote', 'Remote'), ('local', 'Local')], default='sftp', max_length=10), | ||
), | ||
] |
Oops, something went wrong.