#31 API basic implementation Token Authentication

* adds token checking to AbstractModelAPIView
* adds user accessibility filtering for intervention API v1
* extends fetch_and_serialize() method to take a dict for db filtering instead of a single field and value
* organizes urlnames into supporting formats like "api:v1:intervention"
This commit is contained in:
2022-01-21 16:15:16 +01:00
parent 881da38538
commit 3938db1893
6 changed files with 64 additions and 16 deletions

View File

@@ -13,15 +13,16 @@ from api.views.v1.general import AbstractModelAPIViewV1
from intervention.models import Intervention
class APIInterventionView(AbstractModelAPIViewV1):
class APIInterventionViewV1(AbstractModelAPIViewV1):
model = Intervention
fields_to_serialize = {
"identifier",
"title",
}
def get(self, request: HttpRequest, identifier):
data = self.fetch_and_serialize("identifier", identifier)
_filter = {
"identifier": identifier,
"users__in": [self.user],
"deleted__isnull": True,
}
data = self.fetch_and_serialize(_filter)
return JsonResponse(data)
def model_to_json(self, entry: Intervention):