Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 96 additions & 9 deletions TEKDB/TEKDB/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.gis.admin import OSMGeoAdmin
from django.utils.html import format_html
from django.utils.html import format_html, mark_safe
from django.utils.translation import gettext_lazy as _
from dal import autocomplete
from mimetypes import guess_type
Expand Down Expand Up @@ -404,6 +404,21 @@ class LocalityGISSelectionsInline(admin.TabularInline):
####################
### MODEL ADMINS ###
####################

#### Mixins ####


class SearchableFieldsGuideMixin(admin.ModelAdmin):
@admin.display(description="Keyword-searchable fields")
def searchable_fields_display(self, instance):
fields = instance.__class__.human_readable_list_of_searchable_fields()
items = mark_safe("".join(f"<li>{f}</li>" for f in fields))
return format_html(
"<ul style='margin:0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 20px;'>{}</ul>",
items,
)


#### PROXY MODELS ####
# class RecordAdminProxy(VersionAdmin, ModerationAdmin):
class RecordAdminProxy(VersionAdmin):
Expand Down Expand Up @@ -521,7 +536,7 @@ def change_view(self, request, object_id, form_url="", extra_context={}):


@admin.register(Citations)
class CitationsAdmin(RecordAdminProxy, RecordModelAdmin):
class CitationsAdmin(RecordAdminProxy, RecordModelAdmin, SearchableFieldsGuideMixin):
list_display = (
"referencetype",
"title_text",
Expand All @@ -532,8 +547,26 @@ class CitationsAdmin(RecordAdminProxy, RecordModelAdmin):
"enteredbyname",
"enteredbydate",
)
readonly_fields = (
"searchable_fields_display",
"enteredbydate",
"enteredbyname",
"enteredbytitle",
"enteredbytribe",
"modifiedbyname",
"modifiedbytitle",
"modifiedbytribe",
"modifiedbydate",
Comment thread
paigewilliams marked this conversation as resolved.
)

fieldsets = (
(None, {"classes": ("citation-ref-type",), "fields": ("referencetype",)}),
(
None,
{
"classes": ("citation-ref-type",),
"fields": ("referencetype",),
},
),
(
"Bibliographic Source",
{
Expand All @@ -551,7 +584,7 @@ class CitationsAdmin(RecordAdminProxy, RecordModelAdmin):
"placeofinterview",
("journal", "journalpages"),
"preparedfor",
# 'rawcitation',
"keywords",
"comments",
),
},
Expand All @@ -576,6 +609,7 @@ class CitationsAdmin(RecordAdminProxy, RecordModelAdmin):
)
},
),
("Guide", {"fields": ("searchable_fields_display",)}),
)

add_form_template = "%s/TEKDB/templates/admin/CitationsForm.html" % BASE_DIR
Expand Down Expand Up @@ -844,8 +878,9 @@ def has_add_permission(self, request):


@admin.register(Media)
class MediaAdmin(RecordAdminProxy, RecordModelAdmin):
class MediaAdmin(RecordAdminProxy, RecordModelAdmin, SearchableFieldsGuideMixin):
readonly_fields = (
"searchable_fields_display",
"medialink",
"enteredbyname",
"enteredbytribe",
Expand All @@ -866,6 +901,7 @@ class MediaAdmin(RecordAdminProxy, RecordModelAdmin):
"enteredbyname",
"enteredbydate",
)

fieldsets = (
(
None,
Expand All @@ -876,6 +912,7 @@ class MediaAdmin(RecordAdminProxy, RecordModelAdmin):
"medialink",
"mediadescription",
"mediabulkupload",
"keywords",
)
},
),
Expand All @@ -899,6 +936,7 @@ class MediaAdmin(RecordAdminProxy, RecordModelAdmin):
)
},
),
("Guide", {"fields": ("searchable_fields_display",)}),
)
from TEKDB.settings import BASE_DIR

Expand All @@ -920,7 +958,7 @@ class MediaAdmin(RecordAdminProxy, RecordModelAdmin):

# class PlacesAdmin(NestedRecordAdminProxy, OSMGeoAdmin, RecordModelAdmin):
@admin.register(Places)
class PlacesAdmin(NestedRecordAdminProxy, RecordModelAdmin):
class PlacesAdmin(NestedRecordAdminProxy, RecordModelAdmin, SearchableFieldsGuideMixin):
list_display = (
"indigenousplacename",
"englishplacename",
Expand All @@ -930,6 +968,18 @@ class PlacesAdmin(NestedRecordAdminProxy, RecordModelAdmin):
"enteredbyname",
"enteredbydate",
)
readonly_fields = (
"searchable_fields_display",
"enteredbyname",
"enteredbytitle",
"enteredbytribe",
"enteredbydate",
"modifiedbyname",
"modifiedbytitle",
"modifiedbytribe",
"modifiedbydate",
)

fieldsets = (
(
None,
Expand All @@ -940,6 +990,7 @@ class PlacesAdmin(NestedRecordAdminProxy, RecordModelAdmin):
("planningunitid", "primaryhabitat"),
"tribeid",
"geometry",
"keywords",
)
},
),
Expand All @@ -964,6 +1015,7 @@ class PlacesAdmin(NestedRecordAdminProxy, RecordModelAdmin):
)
},
),
("Guide", {"fields": ("searchable_fields_display",)}),
)

search_fields = (
Expand Down Expand Up @@ -996,7 +1048,9 @@ def changelist_view(self, request, extra_context=None):


@admin.register(Resources)
class ResourcesAdmin(NestedRecordAdminProxy, RecordModelAdmin):
class ResourcesAdmin(
NestedRecordAdminProxy, RecordModelAdmin, SearchableFieldsGuideMixin
):
list_display = (
"commonname",
"indigenousname",
Expand All @@ -1006,6 +1060,18 @@ class ResourcesAdmin(NestedRecordAdminProxy, RecordModelAdmin):
"enteredbyname",
"enteredbydate",
)
readonly_fields = (
"searchable_fields_display",
"enteredbyname",
"enteredbytitle",
"enteredbytribe",
"enteredbydate",
"modifiedbyname",
"modifiedbytitle",
"modifiedbytribe",
"modifiedbydate",
)

fieldsets = (
(
None,
Expand All @@ -1014,6 +1080,7 @@ class ResourcesAdmin(NestedRecordAdminProxy, RecordModelAdmin):
("commonname", "indigenousname"),
("genus", "species"),
"resourceclassificationgroup",
"keywords",
)
},
),
Expand All @@ -1037,6 +1104,7 @@ class ResourcesAdmin(NestedRecordAdminProxy, RecordModelAdmin):
)
},
),
("Guide", {"fields": ("searchable_fields_display",)}),
)
search_fields = (
"commonname",
Expand All @@ -1054,7 +1122,9 @@ class ResourcesAdmin(NestedRecordAdminProxy, RecordModelAdmin):


@admin.register(ResourcesActivityEvents)
class ResourcesActivityEventsAdmin(RecordAdminProxy, RecordModelAdmin):
class ResourcesActivityEventsAdmin(
RecordAdminProxy, RecordModelAdmin, SearchableFieldsGuideMixin
):
list_display = (
"placeresourceid",
"excerpt_text",
Expand All @@ -1064,8 +1134,23 @@ class ResourcesActivityEventsAdmin(RecordAdminProxy, RecordModelAdmin):
"enteredbyname",
"enteredbydate",
)
readonly_fields = (
"searchable_fields_display",
"enteredbyname",
"enteredbytitle",
"enteredbytribe",
"enteredbydate",
"modifiedbyname",
"modifiedbytitle",
"modifiedbytribe",
"modifiedbydate",
)

fieldsets = (
(None, {"fields": ("placeresourceid",)}),
(
None,
{"fields": ("placeresourceid",)},
),
(
"Activity",
{
Expand All @@ -1078,6 +1163,7 @@ class ResourcesActivityEventsAdmin(RecordAdminProxy, RecordModelAdmin):
"customaryuse",
"timing",
"timingdescription",
"keywords",
)
},
),
Expand All @@ -1101,6 +1187,7 @@ class ResourcesActivityEventsAdmin(RecordAdminProxy, RecordModelAdmin):
)
},
),
("Guide", {"fields": ("searchable_fields_display",)}),
)
search_fields = (
"placeresourceid__resourceid__commonname",
Expand Down
15 changes: 10 additions & 5 deletions TEKDB/TEKDB/fixtures/all_dummy_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2684,7 +2684,8 @@
"geometry": "SRID=3857;POLYGON ((-13827397.042595 5154553.4109967, -13827459.14768 5154512.8038255, -13827406.597223 5154369.4843975, -13827339.714824 5154331.2658833, -13827234.61391 5154347.9864833, -13827158.176882 5154414.868883, -13827151.01091 5154496.0832255, -13827275.221081 5154543.8563682, -13827397.042595 5154553.4109967))",
"Source": "ryan",
"DigitizedBy": "ryan",
"DigitizedDate": "2017-09-11T07:00:00Z"
"DigitizedDate": "2017-09-11T07:00:00Z",
"keywords": "shark, rock, habitat, puget sound, beach, intertidal, foobarbaz"
}
},
{
Expand Down Expand Up @@ -3155,7 +3156,8 @@
"species": "sp.",
"specific": false,
"resourceclassificationgroup": null,
"islocked": false
"islocked": false,
"keywords": "abalone, shellfish, marine, intertidal, invertebrate, foobarbaz"
}
},
{
Expand Down Expand Up @@ -8184,7 +8186,8 @@
"customaryuse": null,
"timing": null,
"timingdescription": null,
"islocked": false
"islocked": false,
"keywords": "harvesting, female, shellfish, beach, hand gathering, foobarbaz"
}
},
{
Expand Down Expand Up @@ -8243,7 +8246,8 @@
"preparedfor": null,
"comments": "Text on flora and fauna harvested by Native Americans in the marine environment",
"journal": null,
"journalpages": null
"journalpages": null,
"keywords": "marine harvesting, flora, fauna, text, foobarbaz"
}
},
{
Expand Down Expand Up @@ -8340,7 +8344,8 @@
"mediadescription": "Photo taken by Manaha Herman, 2015",
"medialink": "/usr/local/apps/TEKDB/TEKDB/media/gumboot_chiton.jpg",
"mediafile": "gumboot_chiton_fT5Kxtm.jpg",
"limitedaccess": true
"limitedaccess": true,
"keywords": "chiton, gumboot chiton, photo, foobarbaz"
}
},
{
Expand Down
18 changes: 18 additions & 0 deletions TEKDB/TEKDB/migrations/0028_alter_citations_preparedfor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.30 on 2026-05-12 22:43

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('TEKDB', '0027_alter_mediabulkupload_mediabulkname'),
]

operations = [
migrations.AlterField(
model_name='citations',
name='preparedfor',
field=models.CharField(blank=True, db_column='preparedfor', max_length=100, null=True, verbose_name='prepared for'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.30 on 2026-05-12 23:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('TEKDB', '0028_alter_citations_preparedfor'),
]

operations = [
migrations.AddField(
model_name='citations',
name='keywords',
field=models.TextField(blank=True, null=True, verbose_name='keywords'),
),
migrations.AddField(
model_name='media',
name='keywords',
field=models.TextField(blank=True, null=True, verbose_name='keywords'),
),
migrations.AddField(
model_name='places',
name='keywords',
field=models.TextField(blank=True, null=True, verbose_name='keywords'),
),
migrations.AddField(
model_name='resources',
name='keywords',
field=models.TextField(blank=True, null=True, verbose_name='keywords'),
),
migrations.AddField(
model_name='resourcesactivityevents',
name='keywords',
field=models.TextField(blank=True, null=True, verbose_name='keywords'),
),
]
Loading