Skip to content

Commit

Permalink
Unworking
Browse files Browse the repository at this point in the history
  • Loading branch information
PonteIneptique committed Aug 26, 2024
1 parent e5711db commit f35d203
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
36 changes: 30 additions & 6 deletions dapitains/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ def msg_4xx(string, code=404) -> Response:
return Response(json.dumps({"message": string}), status=code, mimetype="application/json")


def collection_view(identifier: Optional[str], nav: str, templates: Dict[str, str]) -> Response:
def collection_view(
identifier: Optional[str],
nav: str,
templates: Dict[str, uritemplate.URITemplate]
) -> Response:
""" Builds a collection view, regardless of how the parameters are received
:param identifier:
:param nav:
:param templates:
"""
if not identifier:
coll: Collection = db.session.query(Collection).filter(~Collection.parents.any()).first()
else:
Expand All @@ -49,8 +59,22 @@ def collection_view(identifier: Optional[str], nav: str, templates: Dict[str, st
**out,
"totalParents": coll.total_parents,
"totalChildren": coll.total_children,
"collection": templates["collection"].uri,
"member": [
related.json()
(
related.json(inject=(**{
"collection": templates["collection"].partial({"id": related.identifier}).uri,
"document": templates["collection"].partial({"id": related.identifier}).uri,
}, **(
{
"navigation": templates["collection"].partial(
{"id": related.identifier}).uri,
} if hasattr(coll, "citeStructure") else {}))
if related.resource
else related.json({
"collection": templates["collection"].partial({"id": related.identifier}).uri
})
)
for related in related_collections
]
}), mimetype="application/json", status=200)
Expand Down Expand Up @@ -108,12 +132,12 @@ def create_app(
@app.route("/collection/")
def collection_route():
resource = request.args.get("id")
nav = request.args.get("nav")
nav = request.args.get("nav", "children")

return collection_view(resource, nav, templates={
"navigation": navigation_template.partial({"resource": resource}).uri,
"collection": collection_template.partial({"id": resource}).uri,
"document": document_template.partial({"resource": resource}).uri,
"navigation": navigation_template,
"collection": collection_template,
"document": document_template,
})

@app.route("/navigation/")
Expand Down
1 change: 1 addition & 0 deletions dapitains/app/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def store_catalog(catalog: Catalog):
child_id=keys[child]
)
db.session.execute(insert_statement)
db.session.commit()



Expand Down

0 comments on commit f35d203

Please sign in to comment.