#31 API basic implementation Compensation

* adds compensation fetching for API v1
* refactors filter into predefined lookup dict of super class (needs to be customized on subclasses)
This commit is contained in:
2022-01-21 17:32:31 +01:00
parent 11de423d05
commit fd4729aa03
5 changed files with 102 additions and 10 deletions
+8 -6
View File
@@ -18,12 +18,10 @@ class APIInterventionViewV1(AbstractModelAPIViewV1):
model = Intervention
def get(self, request: HttpRequest, id):
_filter = {
"id": id,
"users__in": [self.user],
"deleted__isnull": True,
}
data = self.fetch_and_serialize(_filter)
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):
@@ -34,6 +32,8 @@ class APIInterventionViewV1(AbstractModelAPIViewV1):
)
def model_to_json(self, entry: Intervention):
modified_on = entry.modified or entry.created
modified_on = modified_on.timestamp
entry_json = {
"identifier": entry.identifier,
"title": entry.title,
@@ -42,6 +42,8 @@ class APIInterventionViewV1(AbstractModelAPIViewV1):
"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": modified_on,
"created_on": entry.created.timestamp,
}
geom = entry.geometry.geom.geojson
geo_json = json.loads(geom)