diff --git a/django_project/context_layer_management/admin/layer.py b/django_project/context_layer_management/admin/layer.py index 192f229..a498e9a 100644 --- a/django_project/context_layer_management/admin/layer.py +++ b/django_project/context_layer_management/admin/layer.py @@ -2,11 +2,15 @@ """Context Layer Management.""" from django.contrib import admin +from django.utils.safestring import mark_safe from context_layer_management.forms.layer import LayerForm, LayerUploadForm from context_layer_management.models.layer import Layer, LayerField from context_layer_management.models.layer_upload import LayerUpload from context_layer_management.tasks import import_data +from context_layer_management.utils.layer import layer_style_url + +EDITOR_URL = 'http://127.0.0.1:8888/' class LayerFieldInline(admin.TabularInline): @@ -31,7 +35,7 @@ class LayerAdmin(admin.ModelAdmin): """Layer admin.""" list_display = ( - 'unique_id', 'name', 'created_by', 'created_at', 'tile_url', 'metadata' + 'unique_id', 'name', 'created_by', 'created_at', 'tile_url', 'editor' ) form = LayerForm inlines = [LayerFieldInline] @@ -56,6 +60,16 @@ def field_names(self, obj: Layer): """Return fields.""" return obj.field_names + def editor(self, obj: Layer): + """Return fields.""" + return mark_safe( + f"Editor" + ) + + editor.allow_tags = True + class LayerUploadAdmin(admin.ModelAdmin): """Layer admin.""" diff --git a/django_project/context_layer_management/serializer/layer.py b/django_project/context_layer_management/serializer/layer.py index 4c00147..525675c 100644 --- a/django_project/context_layer_management/serializer/layer.py +++ b/django_project/context_layer_management/serializer/layer.py @@ -1,11 +1,10 @@ # coding=utf-8 """Context Layer Management.""" -from django.urls import reverse from rest_framework import serializers from context_layer_management.models.layer import Layer -from context_layer_management.models.style import Style +from context_layer_management.utils.layer import layer_style_url class LayerSerializer(serializers.ModelSerializer): @@ -16,17 +15,6 @@ class LayerSerializer(serializers.ModelSerializer): default_style = serializers.SerializerMethodField() styles = serializers.SerializerMethodField() - def layer_style_url(self, obj: Layer, style: Style) -> str: - """Return layer style url.""" - request = self.context.get('request', None) - return request.build_absolute_uri('/')[:-1] + reverse( - 'context-layer-management-style-view-set-detail', - kwargs={ - 'layer_id': obj.id, - 'id': style.id - } - ) - def get_tile_url(self, obj: Layer): """Return tile_url.""" request = self.context.get('request', None) @@ -39,7 +27,9 @@ def get_created_by(self, obj: Layer): def get_default_style(self, obj: Layer): """Return default style url.""" if obj.default_style: - return self.layer_style_url(obj, obj.default_style) + return layer_style_url( + obj, obj.default_style, self.context.get('request', None) + ) else: return None @@ -49,7 +39,9 @@ def get_styles(self, obj: Layer): { 'id': style.id, 'name': style.name, - 'style': self.layer_style_url(obj, style) + 'style': layer_style_url( + obj, style, self.context.get('request', None) + ) } for style in obj.styles.all() ] diff --git a/django_project/context_layer_management/serializer/style.py b/django_project/context_layer_management/serializer/style.py index 2355c9e..5ffce03 100644 --- a/django_project/context_layer_management/serializer/style.py +++ b/django_project/context_layer_management/serializer/style.py @@ -41,4 +41,4 @@ def to_representation(self, instance): class Meta: # noqa: D106 model = Style - fields = [] + fields = ['id'] diff --git a/django_project/context_layer_management/utils/layer.py b/django_project/context_layer_management/utils/layer.py new file mode 100644 index 0000000..1b9e0f8 --- /dev/null +++ b/django_project/context_layer_management/utils/layer.py @@ -0,0 +1,18 @@ +# coding=utf-8 +"""Context Layer Management.""" + +from django.urls import reverse + +from context_layer_management.models.layer import Layer +from context_layer_management.models.style import Style + + +def layer_style_url(obj: Layer, style: Style, request) -> str: + """Return layer style url.""" + return request.build_absolute_uri('/')[:-1] + reverse( + 'context-layer-management-style-view-set-detail', + kwargs={ + 'layer_id': obj.id, + 'id': style.id + } + )