Skip to content

Commit

Permalink
Clean django code
Browse files Browse the repository at this point in the history
  • Loading branch information
fpsampayo committed Mar 26, 2024
1 parent ec39c9a commit 2582ab4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
*
* __author__ = '[email protected]'
* __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";


/**
Expand Down Expand Up @@ -70,10 +70,10 @@ export default function RelatedTableFields(
<SelectWithSearch
value={data.latitude}
onChangeFn={evt => {
onSetData({...data, latitude: evt})
onSetData({ ...data, latitude: evt })
}}
options={relatedFields.filter(rf => rf.type === 'number').map(rf => rf.name)}
className='FilterInput'/>
className='FilterInput' />
</div>
</div>
<div className='BasicFormSection'>
Expand All @@ -82,10 +82,10 @@ export default function RelatedTableFields(
<SelectWithSearch
value={data.longitude}
onChangeFn={evt => {
onSetData({...data, longitude: evt})
onSetData({ ...data, longitude: evt })
}}
options={relatedFields.filter(rf => rf.type === 'number').map(rf => rf.name)}
className='FilterInput'/>
className='FilterInput' />
</div>
</div>
<div className='BasicFormSection'>
Expand All @@ -94,18 +94,18 @@ export default function RelatedTableFields(
<SelectWithSearch
value={data.datetime}
onChangeFn={evt => {
onSetData({...data, datetime: evt})
onSetData({ ...data, datetime: evt })
}}
options={relatedFields.filter(rf => rf.type === 'date').map(rf => rf.name)}
className='FilterInput'/>
className='FilterInput' />
</div>
</div>

<WhereInputModal
value={data.query ? data.query : ''}
fields={relatedFields}
setValue={evt => {
onSetData({...data, query: evt})
onSetData({ ...data, query: evt })
}}
title={"Filter the Data"}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* __author__ = '[email protected]'
* __date__ = '13/06/2023'
* __copyright__ = ('Copyright 2023, Unicef')
* __author__ = '[email protected]'
* __date__ = '20/03/2024'
* __copyright__ = ('Copyright 2024, Unicef')
*/

import { fetchingData } from "../../../../Requests";
Expand Down
19 changes: 0 additions & 19 deletions django_project/geosight/data/api/context_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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"
)
5 changes: 0 additions & 5 deletions django_project/geosight/data/forms/context_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 0 additions & 10 deletions django_project/geosight/data/serializer/context_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions django_project/geosight/data/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -238,10 +238,6 @@
r'^list',
ContextLayerListAPI.as_view(), name='context-layer-list-api'
),
url(
r'^(?P<pk>\d+)/geojson',
ContextLayerDetailGeojsonAPI.as_view(), name='context-layer-detail-geojson-api'
),
url(
r'^(?P<pk>\d+)',
ContextLayerDetailAPI.as_view(), name='context-layer-detail-api'
Expand Down

0 comments on commit 2582ab4

Please sign in to comment.