Skip to content

Commit

Permalink
Hide editor url if layer is not ready (#10)
Browse files Browse the repository at this point in the history
* Hide editor url if layer is not ready

* Add method to layer to return maputnik url
  • Loading branch information
meomancer authored Jul 23, 2024
1 parent cf773ff commit 3a0c5e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
17 changes: 8 additions & 9 deletions django_project/cloud_native_gis/admin/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from cloud_native_gis.models.layer import Layer, LayerAttributes
from cloud_native_gis.models.layer_upload import LayerUpload
from cloud_native_gis.tasks import import_data
from cloud_native_gis.utils.layer import layer_api_url, maputnik_url


class LayerAttributeInline(admin.TabularInline):
Expand All @@ -29,11 +28,13 @@ def start_upload_data(modeladmin, request, queryset):
import_data.delay(layer.pk)


@admin.register(Layer)
class LayerAdmin(admin.ModelAdmin):
"""Layer admin."""

list_display = (
'unique_id', 'name', 'created_by', 'created_at', 'tile_url', 'editor'
'unique_id', 'name', 'created_by', 'created_at',
'is_ready', 'tile_url', 'editor'
)
form = LayerForm
inlines = [LayerAttributeInline]
Expand All @@ -60,15 +61,17 @@ def field_names(self, obj: Layer):

def editor(self, obj: Layer):
"""Return fields."""
maputnik_url = obj.maputnik_url(self.request)
if not maputnik_url:
return None
return mark_safe(
f"<a target='__blank__' href='{maputnik_url()}?"
f"api-url={layer_api_url(obj, self.request)}"
f"'>Editor</a>"
f"<a target='__blank__' href='{maputnik_url}'>Editor</a>"
)

editor.allow_tags = True


@admin.register(LayerUpload)
class LayerUploadAdmin(admin.ModelAdmin):
"""Layer admin."""

Expand All @@ -84,7 +87,3 @@ def get_form(self, request, *args, **kwargs):
form = super(LayerUploadAdmin, self).get_form(request, *args, **kwargs)
form.user = request.user
return form


admin.site.register(Layer, LayerAdmin)
admin.site.register(LayerUpload, LayerUploadAdmin)
8 changes: 8 additions & 0 deletions django_project/cloud_native_gis/models/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ def absolute_tile_url(self, request):
else:
return None

def maputnik_url(self, request):
"""Return absolute url for maputnik."""
from cloud_native_gis.utils.layer import layer_api_url, maputnik_url
if self.tile_url and request:
return f"{maputnik_url()}?api-url={layer_api_url(self, request)}"
else:
return None

def update_default_style(self, style: Style):
"""Update default style."""
self.default_style = style
Expand Down

0 comments on commit 3a0c5e4

Please sign in to comment.