Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support uploading model runs from the web client #490

Merged
merged 20 commits into from
Sep 13, 2024
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
51 changes: 50 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ apache-airflow-client = "^2.9.0"
beautifulsoup4 = "^4.12.3"
django-allauth = {extras = ["socialaccount"], version = "^0.63.2"}
django-login-required-middleware = "^0.9.0"
django-s3-file-field = {version = "^1.0.1", extras = ["s3"]}

[tool.poetry.group.dev.dependencies]
django-stubs = "^4.2.7"
Expand All @@ -68,6 +69,7 @@ tox = "^4.14.2"
django-minio-storage = "^0.5.7"
werkzeug = "^3.0.2"
django-debug-toolbar = "^4.3.0"
django-s3-file-field = {version = "^1.0.1", extras = ["minio"]}

[tool.poetry.group.dev]
optional = true
Expand Down
13 changes: 13 additions & 0 deletions rdwatch/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
AnimationModelRunExport,
AnimationSiteExport,
ModelRun,
ModelRunUpload,
Performer,
Region,
SatelliteFetching,
Expand Down Expand Up @@ -151,3 +152,15 @@ class AnimationModelRunExportAdmin(admin.ModelAdmin):
'celery_id',
'arguments',
)


@admin.register(ModelRunUpload)
class ModelRunUploadAdmin(admin.ModelAdmin):
list_display = (
'id',
'title',
'performer',
'region',
'zipfile',
'task_id',
)
59 changes: 59 additions & 0 deletions rdwatch/core/migrations/0036_modelrunupload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Generated by Django 5.0.8 on 2024-08-14 21:17

import uuid

import s3_file_field.fields

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
('core', '0035_alter_annotationexport_export_file_and_more'),
]

operations = [
migrations.CreateModel(
name='ModelRunUpload',
fields=[
(
'id',
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
('title', models.CharField(max_length=1000)),
(
'private',
models.BooleanField(
default=False,
help_text='Whether this model run should be private',
),
),
(
'region',
models.CharField(
blank=True,
help_text='Override for the region this model run belongs to',
max_length=1000,
),
),
(
'performer',
models.CharField(
blank=True,
help_text='Shortcode override for the team that produced this evaluation',
max_length=1000,
),
),
('zipfile', s3_file_field.fields.S3FileField()),
(
'task_id',
models.CharField(help_text='Celery task ID', max_length=256),
),
],
),
]
2 changes: 2 additions & 0 deletions rdwatch/core/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
AnnotationExport,
)
from .model_run import ModelRun
from .model_run_upload import ModelRunUpload
from .performer import Performer
from .region import Region
from .satellite_fetching import SatelliteFetching
Expand All @@ -16,6 +17,7 @@
'AnnotationExport',
'lookups',
'ModelRun',
'ModelRunUpload',
'Performer',
'Region',
'SiteEvaluation',
Expand Down
38 changes: 38 additions & 0 deletions rdwatch/core/models/model_run_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from uuid import uuid4

from s3_file_field import S3FileField

from django.db import models
from django.db.models.signals import pre_delete
from django.dispatch import receiver


class ModelRunUpload(models.Model):
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)

title = models.CharField(max_length=1000)
private = models.BooleanField(
default=False, help_text='Whether this model run should be private'
)
region = models.CharField(
max_length=1000,
blank=True,
help_text='Override for the region this model run belongs to',
)
performer = models.CharField(
max_length=1000,
blank=True,
help_text='Shortcode override for the team that produced this evaluation',
)
zipfile = S3FileField()

task_id = models.CharField(max_length=256, help_text='Celery task ID')

def __str__(self) -> str:
return f'<ModelRunUpload {self.id}>'


@receiver(pre_delete, sender=ModelRunUpload)
def delete_zipfile(sender, instance, **kwargs):
if instance.zipfile:
instance.zipfile.delete(save=False)
Loading
Loading