Skip to content

Commit

Permalink
Add dependencies field for models
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpirix committed Nov 15, 2024
1 parent cc17e6a commit 4daaffa
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
14 changes: 14 additions & 0 deletions qgis-app/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion qgis-app/models/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Meta:
"thumbnail_image",
"name",
"description",
"tags"
"tags",
"dependencies"
]


Expand Down
18 changes: 18 additions & 0 deletions qgis-app/models/migrations/0009_model_dependencies.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
9 changes: 9 additions & 0 deletions qgis-app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions qgis-app/models/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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,
)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand Down
13 changes: 13 additions & 0 deletions qgis-app/templates/base/includes/detail_object.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@
{{ object_detail.description|md_to_html }}
</div>
</div>
{% if object_detail.dependencies %}
<div class="column is-6">
<div class="field">
<label class="label">
<span class="icon"><i class="fas fa-link"></i></span>
{% trans "Dependencies" %}:
</label>
<div class="control">
{{ object_detail.dependencies|default:"-" }}
</div>
</div>
</div>
{% endif %}
<div class="column is-6">
<div class="field">
<label class="label">
Expand Down

0 comments on commit 4daaffa

Please sign in to comment.