#31 API basic implementation Cleanup
* cleans code * reworks many code fragments into smaller methods and split into super class
This commit is contained in:
@@ -5,25 +5,15 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 21.01.22
|
||||
|
||||
"""
|
||||
import json
|
||||
|
||||
from django.db.models import QuerySet
|
||||
from django.http import HttpRequest, JsonResponse
|
||||
|
||||
from api.views.v1.general import AbstractModelAPIViewV1
|
||||
from api.views.v1.views import AbstractModelAPIViewV1
|
||||
from intervention.models import Intervention
|
||||
|
||||
|
||||
class APIInterventionViewV1(AbstractModelAPIViewV1):
|
||||
model = Intervention
|
||||
|
||||
def get(self, request: HttpRequest, id):
|
||||
self.lookup["id"] = id
|
||||
self.lookup["users__in"] = [self.user]
|
||||
|
||||
data = self.fetch_and_serialize()
|
||||
return JsonResponse(data)
|
||||
|
||||
def compensations_to_json(self, qs: QuerySet):
|
||||
return list(
|
||||
qs.values(
|
||||
@@ -31,19 +21,9 @@ class APIInterventionViewV1(AbstractModelAPIViewV1):
|
||||
)
|
||||
)
|
||||
|
||||
def model_to_json(self, entry: Intervention):
|
||||
entry_json = {
|
||||
"identifier": entry.identifier,
|
||||
"title": entry.title,
|
||||
"responsible": self.responsible_to_json(entry.responsible),
|
||||
"legal": self.legal_to_json(entry.legal),
|
||||
"compensations": self.compensations_to_json(entry.compensations.all()),
|
||||
"payments": self.payments_to_json(entry.payments.all()),
|
||||
"deductions": self.deductions_to_json(entry.deductions.all()),
|
||||
"modified_on": self.modified_on_to_json(entry),
|
||||
"created_on": self.created_on_to_json(entry),
|
||||
}
|
||||
geom = entry.geometry.geom.geojson
|
||||
geo_json = json.loads(geom)
|
||||
geo_json["properties"] = entry_json
|
||||
return geo_json
|
||||
def extend_properties_data(self, entry):
|
||||
self.properties_data["responsible"] = self.responsible_to_json(entry.responsible)
|
||||
self.properties_data["legal"] = self.legal_to_json(entry.legal)
|
||||
self.properties_data["compensations"] = self.compensations_to_json(entry.compensations.all())
|
||||
self.properties_data["payments"] = self.payments_to_json(entry.payments.all())
|
||||
self.properties_data["deductions"] = self.deductions_to_json(entry.deductions.all())
|
||||
|
||||
Reference in New Issue
Block a user