diff --git a/qgis-app/api/serializers.py b/qgis-app/api/serializers.py index 1cc151f9..8dc52992 100644 --- a/qgis-app/api/serializers.py +++ b/qgis-app/api/serializers.py @@ -72,6 +72,20 @@ def get_resource_subtype(self, obj): class ModelSerializer(ResourceBaseSerializer): class Meta(ResourceBaseSerializer.Meta): model = Model + fields = [ + "resource_type", + "resource_subtype", + "uuid", + "name", + "creator", + "upload_date", + "download_count", + "description", + "dependencies", + "file", + "thumbnail", + "thumbnail_full" + ] def get_resource_subtype(self, obj): return None diff --git a/qgis-app/models/forms.py b/qgis-app/models/forms.py index df69770e..8dea0d68 100644 --- a/qgis-app/models/forms.py +++ b/qgis-app/models/forms.py @@ -13,7 +13,8 @@ class Meta: "thumbnail_image", "name", "description", - "tags" + "tags", + "dependencies" ] diff --git a/qgis-app/models/migrations/0009_model_dependencies.py b/qgis-app/models/migrations/0009_model_dependencies.py new file mode 100644 index 00000000..dbc7b8e5 --- /dev/null +++ b/qgis-app/models/migrations/0009_model_dependencies.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.16 on 2024-09-13 05:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('models', '0008_model_tags'), + ] + + operations = [ + migrations.AddField( + model_name='model', + name='dependencies', + field=models.TextField(blank=True, help_text='Comma-separated list for the plugin the model needs', null=True, verbose_name='Plugin dependencies'), + ), + ] diff --git a/qgis-app/models/models.py b/qgis-app/models/models.py index 4aa2809f..5479cb7a 100644 --- a/qgis-app/models/models.py +++ b/qgis-app/models/models.py @@ -34,6 +34,15 @@ class Model(Resource): null=False, ) + # plugin dependencies + dependencies = models.TextField( + _("Plugin dependencies"), + help_text=_("Comma-separated list for the plugin the model needs"), + blank=True, + null=True, + ) + + def extension(self): name, extension = os.path.splitext(self.file.name) return extension diff --git a/qgis-app/models/tests/test_views.py b/qgis-app/models/tests/test_views.py index ca375fb8..924911a0 100644 --- a/qgis-app/models/tests/test_views.py +++ b/qgis-app/models/tests/test_views.py @@ -65,6 +65,7 @@ def test_form_with_valid_data(self): data = { "name": "flooded building extractor", "description": "Test upload with valid data", + "dependencies": "QuickOSM" } file_data = {"thumbnail_image": uploaded_thumbnail, "file": uploaded_model} form = UploadForm(data, file_data) @@ -96,6 +97,7 @@ def test_form_invalid_filesize(self): data = { "name": "flooded buildings extractor", "description": "Test upload invalid model filesize", + "dependencies": "QuickOSM" } file_data = {"thumbnail_image": uploaded_thumbnail, "file": uploaded_model} form = UploadForm(data, file_data) @@ -119,6 +121,7 @@ def test_print_email_notification_in_console(self): creator=self.creator, name="flooded buildings extractor", description="A Model for testing purpose", + dependencies="QuickOSM", thumbnail_image=self.thumbnail, file=self.file, ) @@ -157,6 +160,7 @@ def test_upload_acceptable_model3_size_file(self): data = { "name": "flooded buildings extractor", "description": "Test upload an acceptable model size", + "dependencies": "QuickOSM", "thumbnail_image": uploaded_thumbnail, "file": uploaded_model, "tags": "model,project,test" @@ -188,6 +192,7 @@ def test_upload_acceptable_zip_size_file(self): data = { "name": "flooded buildings extractor", "description": "Test upload .zip model", + "dependencies": "QuickOSM", "thumbnail_image": uploaded_thumbnail, "file": uploaded_model, } @@ -213,6 +218,7 @@ def test_upload_invalid_size_file(self): data = { "name": "flooded buildings extractor", "description": "Test upload a model > 1Mb filesize", + "dependencies": "QuickOSM", "thumbnail_image": uploaded_thumbnail, "file": uploaded_model, } diff --git a/qgis-app/templates/base/includes/detail_object.html b/qgis-app/templates/base/includes/detail_object.html index 1ad9e4ab..dd05b85e 100644 --- a/qgis-app/templates/base/includes/detail_object.html +++ b/qgis-app/templates/base/includes/detail_object.html @@ -5,6 +5,10 @@