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

Hide editor url if layer is not ready #10

Merged
merged 2 commits into from
Jul 23, 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
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
Loading