From 2582ab4381ef601d6bcf84a39e029ae32cff26a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20P=C3=A9rez=20Sampayo?= Date: Tue, 26 Mar 2024 13:37:53 +0100 Subject: [PATCH] Clean django code --- .../ContextLayer/Form/RelatedTableFields.jsx | 26 +++++++++---------- .../MapLibre/LayerType/RelatedTable.js | 6 ++--- .../geosight/data/api/context_layers.py | 19 -------------- .../geosight/data/forms/context_layer.py | 5 ---- .../geosight/data/serializer/context_layer.py | 10 ------- django_project/geosight/data/urls.py | 6 +---- 6 files changed, 17 insertions(+), 55 deletions(-) diff --git a/django_project/frontend/src/pages/Admin/ContextLayer/Form/RelatedTableFields.jsx b/django_project/frontend/src/pages/Admin/ContextLayer/Form/RelatedTableFields.jsx index 4b2de1798..63a90a304 100644 --- a/django_project/frontend/src/pages/Admin/ContextLayer/Form/RelatedTableFields.jsx +++ b/django_project/frontend/src/pages/Admin/ContextLayer/Form/RelatedTableFields.jsx @@ -10,17 +10,17 @@ * * __author__ = 'francisco.perez@geomati.co' * __date__ = '20/03/2024' - * __copyright__ = ('Copyright 2023, Unicef') + * __copyright__ = ('Copyright 2024, Unicef') */ -import React, {Fragment, useEffect, useState} from 'react'; +import React, { Fragment, useEffect, useState } from 'react'; -import {SelectWithSearch} from "../../../../components/Input/SelectWithSearch"; +import { SelectWithSearch } from "../../../../components/Input/SelectWithSearch"; import WhereInputModal from "../../../../components/SqlQueryGenerator/WhereInputModal"; -import {getRelatedTableFields} from "../../../../utils/relatedTable"; -import {fetchingData} from "../../../../Requests"; -import {dictDeepCopy} from "../../../../utils/main"; +import { getRelatedTableFields } from "../../../../utils/relatedTable"; +import { fetchingData } from "../../../../Requests"; +import { dictDeepCopy } from "../../../../utils/main"; /** @@ -70,10 +70,10 @@ export default function RelatedTableFields( { - onSetData({...data, latitude: evt}) + onSetData({ ...data, latitude: evt }) }} options={relatedFields.filter(rf => rf.type === 'number').map(rf => rf.name)} - className='FilterInput'/> + className='FilterInput' />
@@ -82,10 +82,10 @@ export default function RelatedTableFields( { - onSetData({...data, longitude: evt}) + onSetData({ ...data, longitude: evt }) }} options={relatedFields.filter(rf => rf.type === 'number').map(rf => rf.name)} - className='FilterInput'/> + className='FilterInput' />
@@ -94,10 +94,10 @@ export default function RelatedTableFields( { - onSetData({...data, datetime: evt}) + onSetData({ ...data, datetime: evt }) }} options={relatedFields.filter(rf => rf.type === 'date').map(rf => rf.name)} - className='FilterInput'/> + className='FilterInput' />
@@ -105,7 +105,7 @@ export default function RelatedTableFields( value={data.query ? data.query : ''} fields={relatedFields} setValue={evt => { - onSetData({...data, query: evt}) + onSetData({ ...data, query: evt }) }} title={"Filter the Data"} /> diff --git a/django_project/frontend/src/pages/Dashboard/MapLibre/LayerType/RelatedTable.js b/django_project/frontend/src/pages/Dashboard/MapLibre/LayerType/RelatedTable.js index 10a186422..30453c12f 100644 --- a/django_project/frontend/src/pages/Dashboard/MapLibre/LayerType/RelatedTable.js +++ b/django_project/frontend/src/pages/Dashboard/MapLibre/LayerType/RelatedTable.js @@ -8,9 +8,9 @@ * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * __author__ = 'irwan@kartoza.com' - * __date__ = '13/06/2023' - * __copyright__ = ('Copyright 2023, Unicef') + * __author__ = 'francisco.perez@geomatico.es' + * __date__ = '20/03/2024' + * __copyright__ = ('Copyright 2024, Unicef') */ import { fetchingData } from "../../../../Requests"; diff --git a/django_project/geosight/data/api/context_layers.py b/django_project/geosight/data/api/context_layers.py index ed70273d3..d36011c56 100644 --- a/django_project/geosight/data/api/context_layers.py +++ b/django_project/geosight/data/api/context_layers.py @@ -22,7 +22,6 @@ from rest_framework.response import Response from rest_framework.views import APIView -from geosight.data.models import RelatedTableRow from geosight.data.models.context_layer import ContextLayer from geosight.data.serializer.context_layer import ContextLayerSerializer, ContextLayerRelatedTableGeojsonSerializer from geosight.permission.access import ( @@ -74,21 +73,3 @@ def delete(self, request, pk): delete_permission_resource(layer, request.user) layer.delete() return Response('Deleted') - - -class ContextLayerDetailGeojsonAPI(APIView): - """API for detail of context layer.""" - - permission_classes = (IsAuthenticated,) - - def get(self, request, pk): - layer = get_object_or_404(ContextLayer, pk=pk) - read_permission_resource(layer, request.user) - if layer.layer_type == 'Related Table': - return Response( - layer.geojson() - ) - else: - raise Http404( - "Only available for Related Table Context Layer" - ) diff --git a/django_project/geosight/data/forms/context_layer.py b/django_project/geosight/data/forms/context_layer.py index 86a0b7530..2ae64d416 100644 --- a/django_project/geosight/data/forms/context_layer.py +++ b/django_project/geosight/data/forms/context_layer.py @@ -25,11 +25,6 @@ class ContextLayerForm(forms.ModelForm): """ContextLayer form.""" - id = forms.IntegerField( - required=False, - widget=forms.HiddenInput() - ) - group = forms.ChoiceField( label='Category', widget=forms.Select( diff --git a/django_project/geosight/data/serializer/context_layer.py b/django_project/geosight/data/serializer/context_layer.py index a8f857b0c..351d89a5d 100644 --- a/django_project/geosight/data/serializer/context_layer.py +++ b/django_project/geosight/data/serializer/context_layer.py @@ -88,13 +88,3 @@ class ContextLayerFieldSerializer(serializers.ModelSerializer): class Meta: # noqa: D106 model = ContextLayerField fields = '__all__' - - -class ContextLayerRelatedTableGeojsonSerializer(ContextLayerSerializer): - geojson = serializers.SerializerMethodField() - - def get_geojson(self, obj: ContextLayer): - if obj.layer_type == 'Related Table': - data = RelatedTableRow.objects.filter(table=obj.related_table).values('data') - print(data) - return data \ No newline at end of file diff --git a/django_project/geosight/data/urls.py b/django_project/geosight/data/urls.py index ee698fb3f..1481f2988 100644 --- a/django_project/geosight/data/urls.py +++ b/django_project/geosight/data/urls.py @@ -22,7 +22,7 @@ BasemapListAPI, BasemapDetailAPI ) from geosight.data.api.context_layers import ( - ContextLayerListAPI, ContextLayerDetailAPI, ContextLayerDetailGeojsonAPI + ContextLayerListAPI, ContextLayerDetailAPI ) from geosight.data.api.dashboard import ( DashboardData, DashboardDuplicate, DashboardDetail, DashboardListAPI @@ -238,10 +238,6 @@ r'^list', ContextLayerListAPI.as_view(), name='context-layer-list-api' ), - url( - r'^(?P\d+)/geojson', - ContextLayerDetailGeojsonAPI.as_view(), name='context-layer-detail-geojson-api' - ), url( r'^(?P\d+)', ContextLayerDetailAPI.as_view(), name='context-layer-detail-api'