Skip to content

Commit 9c4ea80

Browse files
committed
feat: enhance Chemistry Sample Info admin view with additional fields and configurations
- Keep existing field order/labels aligned with legacy model - Set ThingAdmin.identity to thing for stable linking - Add HasOne("thing") relationship link in Chemistry Sample Info list/detail
1 parent ad21379 commit 9c4ea80

2 files changed

Lines changed: 54 additions & 22 deletions

File tree

admin/views/chemistry_sampleinfo.py

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
FK Change (2026-01):
2828
- thing_id: Integer FK to Thing.id
2929
"""
30+
import uuid
31+
32+
from starlette.requests import Request
33+
from starlette_admin.fields import HasOne
3034

3135
from admin.views.base import OcotilloModelView
3236

@@ -38,46 +42,81 @@ class ChemistrySampleInfoAdmin(OcotilloModelView):
3842

3943
# ========== Basic Configuration ==========
4044

41-
name = "Chemistry Sample Info"
42-
label = "Chemistry Sample Info"
45+
name = "NMA Chemistry Sample Info"
46+
label = "NMA Chemistry Sample Info"
4347
icon = "fa fa-flask"
4448

4549
# Integer PK
4650
pk_attr = "id"
4751
pk_type = int
4852

53+
def can_create(self, request: Request) -> bool:
54+
return False
55+
56+
def can_edit(self, request: Request) -> bool:
57+
return False
58+
59+
def can_delete(self, request: Request) -> bool:
60+
return False
61+
4962
# ========== List View ==========
5063

51-
sortable_fields = [
64+
list_fields = [
5265
"id",
5366
"nma_sample_pt_id",
54-
"nma_object_id",
67+
"nma_wclab_id",
5568
"nma_sample_point_id",
69+
"nma_object_id",
70+
"nma_location_id",
71+
"thing_id",
72+
HasOne("thing", identity="thing"),
73+
"collection_date",
74+
"collection_method",
75+
"collected_by",
76+
"analyses_agency",
77+
"sample_type",
78+
"sample_material_not_h2o",
79+
"water_type",
80+
"study_sample",
81+
"data_source",
82+
"data_quality",
83+
"public_release",
84+
"added_day_to_date",
85+
"added_month_day_to_date",
86+
"sample_notes",
87+
]
88+
89+
sortable_fields = [
90+
"id",
91+
"nma_sample_pt_id",
5692
"nma_wclab_id",
93+
"nma_sample_point_id",
94+
"nma_object_id",
5795
"collection_date",
5896
"sample_type",
5997
"data_source",
6098
"data_quality",
6199
"public_release",
100+
62101
]
63102

64103
fields_default_sort = [("collection_date", True)]
65104

66105
searchable_fields = [
67-
"nma_sample_point_id",
68106
"nma_sample_pt_id",
69107
"nma_wclab_id",
108+
"nma_sample_point_id",
109+
"collection_date",
70110
"collected_by",
71111
"analyses_agency",
72-
"sample_notes",
73-
"collection_date",
74112
"sample_type",
75113
"sample_material_not_h2o",
76114
"water_type",
77115
"study_sample",
78116
"data_source",
79117
"data_quality",
80118
"public_release",
119+
"sample_notes",
81120
]
82121

83122
page_size = 50
@@ -86,13 +125,14 @@ class ChemistrySampleInfoAdmin(OcotilloModelView):
86125
# ========== Form View ==========
87126

88127
fields = [
89-
"id",
128+
"id"
90129
"nma_sample_pt_id",
130+
"nma_wclab_id",
91131
"nma_sample_point_id",
92132
"nma_object_id",
93-
"nma_wclab_id",
94133
"nma_location_id",
95134
"thing_id",
135+
HasOne("thing", identity="thing"),
96136
"collection_date",
97137
"collection_method",
98138
"collected_by",
@@ -109,30 +149,21 @@ class ChemistrySampleInfoAdmin(OcotilloModelView):
109149
"sample_notes",
110150
]
111151

112-
exclude_fields_from_create = [
113-
"id",
114-
"nma_object_id",
115-
]
116-
117-
exclude_fields_from_edit = [
118-
"id",
119-
"nma_object_id",
120-
]
121152

122153
field_labels = {
123154
"id": "ID",
124155
"nma_sample_pt_id": "NMA SamplePtID (Legacy)",
125-
"nma_sample_point_id": "NMA SamplePointID (Legacy)",
126-
"nma_object_id": "NMA OBJECTID (Legacy)",
127156
"nma_wclab_id": "NMA WCLab_ID (Legacy)",
128-
"nma_location_id": "NMA LocationId (Legacy)",
157+
"sample_point_id": "NMA SamplePointID (Legacy)",
158+
"nma_object_id": "NMA OBJECTID (Legacy)",
159+
"location_id": "NMA LocationId (Legacy)",
129160
"thing_id": "Thing ID",
130161
"collection_date": "Collection Date",
131162
"collection_method": "Collection Method",
132163
"collected_by": "Collected By",
133164
"analyses_agency": "Analyses Agency",
134165
"sample_type": "Sample Type",
135-
"sample_material_not_h2o": "Sample Material (Not H2O)",
166+
"sample_material_not_h2o": "Sample Material Not H2O",
136167
"water_type": "Water Type",
137168
"study_sample": "Study Sample",
138169
"data_source": "Data Source",

admin/views/thing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ThingAdmin(OcotilloModelView):
3636

3737
# ========== Basic Configuration ==========
3838

39+
identity = "thing"
3940
name = "Things"
4041
label = "Things (Wells/Springs)"
4142
icon = "fa fa-tint"

0 commit comments

Comments
 (0)