Fixed capture link generator when passed a dict
This commit is contained in:
parent
9ff0aa331b
commit
353450dd56
1 changed files with 19 additions and 6 deletions
|
|
@ -47,20 +47,27 @@ class CaptureSchema(Schema):
|
||||||
|
|
||||||
@pre_dump
|
@pre_dump
|
||||||
def generate_links(self, data, **_):
|
def generate_links(self, data, **_):
|
||||||
data.links = {
|
if isinstance(data, dict):
|
||||||
|
capture_id = data.get("id")
|
||||||
|
capture_name = data.get("name")
|
||||||
|
else:
|
||||||
|
capture_id = data.id
|
||||||
|
capture_name = data.name
|
||||||
|
|
||||||
|
links = {
|
||||||
"self": {
|
"self": {
|
||||||
"href": url_for(CaptureView.endpoint, id_=data.id, _external=True),
|
"href": url_for(CaptureView.endpoint, id_=capture_id, _external=True),
|
||||||
"mimetype": "application/json",
|
"mimetype": "application/json",
|
||||||
**description_from_view(CaptureView),
|
**description_from_view(CaptureView),
|
||||||
},
|
},
|
||||||
"tags": {
|
"tags": {
|
||||||
"href": url_for(CaptureTags.endpoint, id_=data.id, _external=True),
|
"href": url_for(CaptureTags.endpoint, id_=capture_id, _external=True),
|
||||||
"mimetype": "application/json",
|
"mimetype": "application/json",
|
||||||
**description_from_view(CaptureTags),
|
**description_from_view(CaptureTags),
|
||||||
},
|
},
|
||||||
"annotations": {
|
"annotations": {
|
||||||
"href": url_for(
|
"href": url_for(
|
||||||
CaptureAnnotations.endpoint, id_=data.id, _external=True
|
CaptureAnnotations.endpoint, id_=capture_id, _external=True
|
||||||
),
|
),
|
||||||
"mimetype": "application/json",
|
"mimetype": "application/json",
|
||||||
**description_from_view(CaptureAnnotations),
|
**description_from_view(CaptureAnnotations),
|
||||||
|
|
@ -68,14 +75,20 @@ class CaptureSchema(Schema):
|
||||||
"download": {
|
"download": {
|
||||||
"href": url_for(
|
"href": url_for(
|
||||||
CaptureDownload.endpoint,
|
CaptureDownload.endpoint,
|
||||||
id_=data.id,
|
id_=capture_id,
|
||||||
filename=data.name,
|
filename=capture_name,
|
||||||
_external=True,
|
_external=True,
|
||||||
),
|
),
|
||||||
"mimetype": "image/jpeg",
|
"mimetype": "image/jpeg",
|
||||||
**description_from_view(CaptureDownload),
|
**description_from_view(CaptureDownload),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isinstance(data, dict):
|
||||||
|
data["links"] = links
|
||||||
|
else:
|
||||||
|
data.links = links
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue