Skip to content

Commit f3477c2

Browse files
authored
Merge pull request #249 from hydroserver2/338-testing
338 testing
2 parents ecac7b7 + 636ecba commit f3477c2

32 files changed

+1976
-268
lines changed

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ SSL_REQUIRED = # True/False: Controls whether Django will connect to the d
2929

3030
# Storage Settings
3131

32-
MEDIA_BUCKET_NAME = # The name of the AWS or GCP bucket photos will be stored in.
32+
MEDIA_BUCKET_NAME = # The name of the AWS or GCP bucket file attachments will be stored in.
3333
STATIC_BUCKET_NAME = # The name of the AWS or GCP bucket static files will be stored in.
3434
APP_CLIENT_URL = # The base URL media and static files will be served from, if not the PROXY_BASE_URL.
35-
AWS_CLOUDFRONT_KEY = # The AWS CloudFront key used to generate signed photo URLs.
36-
AWS_CLOUDFRONT_KEY_ID = # The ID of the AWS CloudFront key used to generate signed photo URLs.
35+
AWS_CLOUDFRONT_KEY = # The AWS CloudFront key used to generate signed file attachment URLs.
36+
AWS_CLOUDFRONT_KEY_ID = # The ID of the AWS CloudFront key used to generate signed file attachment URLs.
3737
GS_PROJECT_ID = # The ID of the GCP project HydroServer is deployed to.

sta/admin.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
Location,
1111
Unit,
1212
ProcessingLevel,
13-
Photo,
14-
Tag,
13+
ThingFileAttachment,
14+
ThingTag,
15+
DatastreamFileAttachment,
16+
DatastreamTag,
1517
ResultQualifier,
1618
Observation,
1719
SiteType,
@@ -23,6 +25,7 @@
2325
DatastreamAggregation,
2426
DatastreamStatus,
2527
SampledMedium,
28+
FileAttachmentType,
2629
)
2730
from sta.management.utils import generate_test_timeseries
2831
from hydroserver.admin import VocabularyAdmin
@@ -40,11 +43,11 @@ class LocationAdmin(admin.ModelAdmin):
4043
list_display = ("id", "name", "thing__name", "thing__workspace__name")
4144

4245

43-
class PhotoAdmin(admin.ModelAdmin):
46+
class ThingFileAttachmentAdmin(admin.ModelAdmin):
4447
list_display = ("id", "name", "thing__name", "thing__workspace__name")
4548

4649

47-
class TagAdmin(admin.ModelAdmin):
50+
class ThingTagAdmin(admin.ModelAdmin):
4851
list_display = ("id", "key", "value", "thing__name", "thing__workspace__name")
4952

5053

@@ -168,6 +171,14 @@ def delete_queryset(self, request, queryset):
168171
delete_observations.short_description = "Delete datastream observations"
169172

170173

174+
class DatastreamFileAttachmentAdmin(admin.ModelAdmin):
175+
list_display = ("id", "name", "datastream__name")
176+
177+
178+
class DatastreamTagAdmin(admin.ModelAdmin):
179+
list_display = ("id", "key", "value", "datastream__name")
180+
181+
171182
class ResultQualifierAdmin(admin.ModelAdmin):
172183
list_display = ("id", "code", "workspace__name")
173184

@@ -379,15 +390,41 @@ def load_default_data(self, request):
379390
)
380391

381392

393+
class FileAttachmentTypeAdmin(admin.ModelAdmin, VocabularyAdmin):
394+
list_display = ("id", "name")
395+
change_list_template = "admin/sta/fileattachmenttype/change_list.html"
396+
397+
def get_urls(self):
398+
urls = super().get_urls()
399+
400+
return [
401+
path(
402+
"load-default-file-attachment-type-data/",
403+
self.admin_site.admin_view(self.load_default_data),
404+
name="file_attachment_type_load_default_data",
405+
),
406+
] + urls
407+
408+
def load_default_data(self, request):
409+
return self.load_fixtures(
410+
request,
411+
"admin:sta_fileattachmenttype_changelist",
412+
["sta/fixtures/default_file_attachment_types.yaml"],
413+
)
414+
415+
382416
admin.site.register(Thing, ThingAdmin)
383417
admin.site.register(Location, LocationAdmin)
384-
admin.site.register(Photo, PhotoAdmin)
385-
admin.site.register(Tag, TagAdmin)
418+
admin.site.register(ThingFileAttachment, ThingFileAttachmentAdmin)
419+
admin.site.register(ThingTag, ThingTagAdmin)
386420
admin.site.register(Sensor, SensorAdmin)
387421
admin.site.register(ObservedProperty, ObservedPropertyAdmin)
388422
admin.site.register(Unit, UnitAdmin)
389423
admin.site.register(ProcessingLevel, ProcessingLevelAdmin)
390424
admin.site.register(Datastream, DatastreamAdmin)
425+
admin.site.register(DatastreamFileAttachment, DatastreamFileAttachmentAdmin)
426+
admin.site.register(DatastreamTag, DatastreamTagAdmin)
427+
admin.site.register(FileAttachmentType, FileAttachmentTypeAdmin)
391428
admin.site.register(ResultQualifier, ResultQualifierAdmin)
392429
admin.site.register(SiteType, SiteTypeAdmin)
393430
admin.site.register(SamplingFeatureType, SamplingFeatureTypeAdmin)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- model: sta.fileattachmenttype
3+
pk: 1
4+
fields:
5+
name: Photo

sta/migrations/0001_initial.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@ class Migration(migrations.Migration):
563563
("name", models.CharField(max_length=255)),
564564
(
565565
"photo",
566-
models.FileField(upload_to=sta.models.thing.photo_storage_path),
566+
models.FileField(
567+
upload_to=sta.models.thing.thing_file_attachment_storage_path
568+
),
567569
),
568570
(
569571
"thing",
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Generated by Django 5.2.5 on 2025-10-27 17:28
2+
3+
import django.db.models.deletion
4+
import iam.models.utils
5+
import sta.models.datastream
6+
import sta.models.thing
7+
from django.db import migrations, models
8+
9+
10+
class Migration(migrations.Migration):
11+
12+
dependencies = [
13+
("sta", "0003_observation_result_qualifiers_and_more"),
14+
]
15+
16+
operations = [
17+
migrations.RenameField(
18+
model_name='location',
19+
old_name='state',
20+
new_name='admin_area_1',
21+
),
22+
migrations.RenameField(
23+
model_name='location',
24+
old_name='county',
25+
new_name='admin_area_2',
26+
),
27+
migrations.RenameField(
28+
model_name="photo",
29+
old_name="photo",
30+
new_name="file_attachment",
31+
),
32+
migrations.AddField(
33+
model_name="photo",
34+
name="file_attachment_type",
35+
field=models.CharField(default="Photo", max_length=200),
36+
preserve_default=False,
37+
),
38+
migrations.AlterField(
39+
model_name="photo",
40+
name="thing",
41+
field=models.ForeignKey(
42+
on_delete=django.db.models.deletion.DO_NOTHING,
43+
related_name="thing_file_attachments",
44+
to="sta.thing",
45+
),
46+
),
47+
migrations.AlterField(
48+
model_name="tag",
49+
name="thing",
50+
field=models.ForeignKey(
51+
on_delete=django.db.models.deletion.DO_NOTHING,
52+
related_name="thing_tags",
53+
to="sta.thing",
54+
),
55+
),
56+
migrations.RenameModel(
57+
old_name="Tag",
58+
new_name="ThingTag",
59+
),
60+
migrations.RenameModel(
61+
old_name="Photo",
62+
new_name="ThingFileAttachment",
63+
),
64+
migrations.CreateModel(
65+
name="FileAttachmentType",
66+
fields=[
67+
(
68+
"id",
69+
models.BigAutoField(
70+
auto_created=True,
71+
primary_key=True,
72+
serialize=False,
73+
verbose_name="ID",
74+
),
75+
),
76+
("name", models.CharField(max_length=200, unique=True)),
77+
],
78+
),
79+
migrations.CreateModel(
80+
name="DatastreamFileAttachment",
81+
fields=[
82+
(
83+
"id",
84+
models.BigAutoField(
85+
auto_created=True,
86+
primary_key=True,
87+
serialize=False,
88+
verbose_name="ID",
89+
),
90+
),
91+
("name", models.CharField(max_length=255)),
92+
(
93+
"file_attachment",
94+
models.FileField(
95+
upload_to=sta.models.datastream.datastream_file_attachment_storage_path
96+
),
97+
),
98+
("file_attachment_type", models.CharField(max_length=200)),
99+
(
100+
"datastream",
101+
models.ForeignKey(
102+
on_delete=django.db.models.deletion.DO_NOTHING,
103+
related_name="datastream_file_attachments",
104+
to="sta.datastream",
105+
),
106+
),
107+
],
108+
options={
109+
"unique_together": {("datastream", "name")},
110+
},
111+
bases=(models.Model, iam.models.utils.PermissionChecker),
112+
),
113+
migrations.CreateModel(
114+
name="DatastreamTag",
115+
fields=[
116+
(
117+
"id",
118+
models.BigAutoField(
119+
auto_created=True,
120+
primary_key=True,
121+
serialize=False,
122+
verbose_name="ID",
123+
),
124+
),
125+
("key", models.CharField(max_length=255)),
126+
("value", models.CharField(max_length=255)),
127+
(
128+
"datastream",
129+
models.ForeignKey(
130+
on_delete=django.db.models.deletion.DO_NOTHING,
131+
related_name="datastream_tags",
132+
to="sta.datastream",
133+
),
134+
),
135+
],
136+
bases=(models.Model, iam.models.utils.PermissionChecker),
137+
),
138+
]

sta/models/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
from .thing import Thing, Tag, Photo, SiteType, SamplingFeatureType
1+
from .thing import (
2+
Thing,
3+
ThingTag,
4+
ThingFileAttachment,
5+
SiteType,
6+
SamplingFeatureType,
7+
FileAttachmentType,
8+
)
29
from .location import Location
310
from .observed_property import ObservedProperty, VariableType
411
from .processing_level import ProcessingLevel
@@ -7,6 +14,8 @@
714
from .unit import Unit, UnitType
815
from .datastream import (
916
Datastream,
17+
DatastreamTag,
18+
DatastreamFileAttachment,
1019
DatastreamAggregation,
1120
DatastreamStatus,
1221
SampledMedium,

0 commit comments

Comments
 (0)