forked from geosolutions-it/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 125
feat: extension model and form validation #2176
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1856105
feat: extension model and form validation
nrjadkry c34562b
fix: signals and post_save method added for extension name handling
nrjadkry 9c20234
update: required files handling
nrjadkry c856097
feat: extensions and pluginsConfig endpoint
nrjadkry b6ef418
feat: cache implemented on the extensions endpoints
nrjadkry 96ffd67
remove print statement
nrjadkry be2c6f2
tests form extension model and apis
nrjadkry fe58e6d
update url path for extension api
nrjadkry c588fb0
fix: uses MAPSTORE_EXTENSIONS_FOLDER_PATH for storing extensions
nrjadkry b9369df
remove: EXTENSIONS_STATIC_DIR in delete signals
nrjadkry 0ba87b7
fix: tests
nrjadkry e11ab64
update EXTENSIONS_FOLDER_PATH in context processor
nrjadkry 62033f4
fix: extension path obtained from STATIC_ROOT
nrjadkry aafac52
review client path
allyoucanmap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,48 @@ | ||
| import os | ||
| from django import forms | ||
| from django.contrib import admin | ||
| from geonode_mapstore_client.models import SearchService | ||
| from geonode_mapstore_client.models import SearchService, Extension | ||
|
|
||
|
|
||
| @admin.register(SearchService) | ||
| class SearchServiceAdmin(admin.ModelAdmin): | ||
| pass | ||
|
|
||
|
|
||
| class ExtensionAdminForm(forms.ModelForm): | ||
| class Meta: | ||
| model = Extension | ||
| fields = '__all__' | ||
|
|
||
| def clean_uploaded_file(self): | ||
| """ | ||
| It checks the uploaded file's name for uniqueness before the model is saved. | ||
| """ | ||
| uploaded_file = self.cleaned_data.get('uploaded_file') | ||
|
|
||
| if uploaded_file: | ||
| extension_name = os.path.splitext(os.path.basename(uploaded_file.name))[0] | ||
|
|
||
| queryset = Extension.objects.filter(name=extension_name) | ||
|
|
||
| # If we are updating an existing instance, we can exclude it from the check | ||
| if self.instance.pk: | ||
| queryset = queryset.exclude(pk=self.instance.pk) | ||
|
|
||
| # If the queryset finds any conflicting extension, raise a validation error | ||
| if queryset.exists(): | ||
| raise forms.ValidationError( | ||
| f"An extension with the name '{extension_name}' already exists. Please upload a file with a different name." | ||
| ) | ||
|
|
||
| return uploaded_file | ||
|
|
||
|
|
||
| @admin.register(Extension) | ||
| class ExtensionAdmin(admin.ModelAdmin): | ||
|
|
||
| form = ExtensionAdminForm | ||
| list_display = ('name', 'active', 'is_map_extension', 'updated_at') | ||
| list_filter = ('active', 'is_map_extension') | ||
| search_fields = ('name',) | ||
| readonly_fields = ('name', 'created_at', 'updated_at') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Generated by Django 4.2.23 on 2025-10-03 12:14 | ||
|
|
||
| from django.db import migrations, models | ||
| import geonode_mapstore_client.models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("geonode_mapstore_client", "0004_auto_20231114_1705"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="Extension", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.AutoField( | ||
| auto_created=True, | ||
| primary_key=True, | ||
| serialize=False, | ||
| verbose_name="ID", | ||
| ), | ||
| ), | ||
| ( | ||
| "name", | ||
| models.CharField( | ||
| blank=True, | ||
| help_text="Name of the extension, derived from the zip file name. Must be unique.", | ||
| max_length=255, | ||
| unique=True, | ||
| ), | ||
| ), | ||
| ( | ||
| "uploaded_file", | ||
| models.FileField( | ||
| help_text="Upload the MapStore extension as a zip folder.", | ||
| upload_to=geonode_mapstore_client.models.extension_upload_path, | ||
| validators=[geonode_mapstore_client.models.validate_zip_file], | ||
| ), | ||
| ), | ||
| ( | ||
| "active", | ||
| models.BooleanField( | ||
| default=True, | ||
| help_text="Whether the extension is active and should be included in the index.", | ||
| ), | ||
| ), | ||
| ( | ||
| "is_map_extension", | ||
| models.BooleanField( | ||
| default=False, | ||
| help_text="Check if this extension is a map-specific plugin for Map Viewers.", | ||
| ), | ||
| ), | ||
| ("created_at", models.DateTimeField(auto_now_add=True)), | ||
| ("updated_at", models.DateTimeField(auto_now=True)), | ||
| ], | ||
| options={ | ||
| "verbose_name": "MapStore Extension", | ||
| "verbose_name_plural": "MapStore Extensions", | ||
| "ordering": ("name",), | ||
| }, | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.