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
26 changes: 26 additions & 0 deletions opendrift_leeway_webgui/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ class LeewaySimulationSerializer(serializers.ModelSerializer):
#: Show username instead of id
username = serializers.ReadOnlyField(source="user.username")

#: Expose the model's error property (last line of traceback)
error = serializers.ReadOnlyField()

#: True once simulation_finished is set
completed = serializers.SerializerMethodField()

def get_completed(self, obj):
"""
:param obj: The simulation instance
:type obj: ~opendrift_leeway_webgui.leeway.models.LeewaySimulation
:rtype: bool
"""
return obj.simulation_finished is not None

class Meta:
"""
Define model and the corresponding fields
Expand All @@ -24,15 +38,27 @@ class Meta:
#: Exclude user field because the username is shown instead
exclude = ["user"]

#: Set example values for drf-spectacular Swagger documentation
extra_kwargs = {
"duration": {"default": 12, "help_text": "Length of simulation in hours."},
"radius": {
"default": 1000,
"help_text": "Radius in meters for distributing particles around start coordinates.",
},
}

#: Define fields which are shown when retrieving simulations,
#: but cannot be set when creating new ones
read_only_fields = [
"uuid",
"img",
"netcdf",
"geojson",
"traceback",
"simulation_started",
"simulation_finished",
"error",
"completed",
]

def create(self, validated_data):
Expand Down
3 changes: 3 additions & 0 deletions opendrift_leeway_webgui/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class LeewaySimulationViewSet(
#: The serializer to use for simulations
serializer_class = LeewaySimulationSerializer

#: Use UUID as the lookup field instead of the integer primary key
lookup_field = "uuid"

def get_queryset(self):
"""
Only return the simulations of the current user
Expand Down
4 changes: 1 addition & 3 deletions opendrift_leeway_webgui/core/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault(
"DJANGO_SETTINGS_MODULE", "opendrift_leeway_webgui.core.settings"
)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "opendrift_leeway_webgui.core.settings")

# Read config from config file
config = configparser.ConfigParser(interpolation=None)
Expand Down
12 changes: 7 additions & 5 deletions opendrift_leeway_webgui/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
x.strip() for x in os.environ.get("LEEWAY_ALLOWED_HOSTS", "").split(",") if x
]

CSRF_TRUSTED_ORIGINS = [
f"https://{host}" for host in ALLOWED_HOSTS
]
CSRF_TRUSTED_ORIGINS = [f"https://{host}" for host in ALLOWED_HOSTS]

#: Enabled applications (see :setting:`django:INSTALLED_APPS`)
INSTALLED_APPS = [
Expand Down Expand Up @@ -374,5 +372,9 @@
#: (see :setting:`django:EMAIL_USE_SSL`)
EMAIL_USE_SSL = bool(strtobool(os.environ.get("LEEWAY_EMAIL_USE_SSL", "False")))

COPERNICUSMARINE_SERVICE_USERNAME = os.environ.get("LEEWAY_COPERNICUSMARINE_SERVICE_USERNAME")
COPERNICUSMARINE_SERVICE_PASSWORD = os.environ.get("LEEWAY_COPERNICUSMARINE_SERVICE_PASSWORD")
COPERNICUSMARINE_SERVICE_USERNAME = os.environ.get(
"LEEWAY_COPERNICUSMARINE_SERVICE_USERNAME"
)
COPERNICUSMARINE_SERVICE_PASSWORD = os.environ.get(
"LEEWAY_COPERNICUSMARINE_SERVICE_PASSWORD"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.2.7 on 2026-02-20 17:35

from django.db import migrations, models

import opendrift_leeway_webgui.leeway.models


class Migration(migrations.Migration):

dependencies = [("leeway", "0008_leewaysimulation_traceback")]

operations = [
migrations.AddField(
model_name="leewaysimulation",
name="geojson",
field=models.FileField(
null=True,
storage=opendrift_leeway_webgui.leeway.models.simulation_storage,
upload_to="",
verbose_name="GeoJSON of simulated trajectories",
),
)
]
5 changes: 5 additions & 0 deletions opendrift_leeway_webgui/leeway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class LeewaySimulation(models.Model):
netcdf = models.FileField(
null=True, storage=simulation_storage, verbose_name=_("NetCDF file")
)
geojson = models.FileField(
null=True,
storage=simulation_storage,
verbose_name=_("GeoJSON of simulated trajectories"),
)
traceback = models.TextField(blank=True, verbose_name=_("traceback"))

@property
Expand Down
Loading
Loading