Skip to content

Commit

Permalink
Working citeStructure but None citeStructure are broken
Browse files Browse the repository at this point in the history
  • Loading branch information
PonteIneptique committed Aug 26, 2024
1 parent f35d203 commit 9607ebd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
35 changes: 18 additions & 17 deletions dapitains/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,23 @@ def collection_view(
"totalChildren": coll.total_children,
"collection": templates["collection"].uri,
"member": [
(
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
]
related.json(
inject=dict(
**{
"collection": templates["collection"].partial({"id": related.identifier}).uri,
"document": templates["document"].partial({"resource": related.identifier}).uri,
},
**(
{
"navigation": templates["navigation"].partial({"resource": related.identifier}).uri,
} if 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 @@ -126,7 +127,7 @@ def create_app(
Initialisation of the DB is up to you
"""
navigation_template = uritemplate.URITemplate("/navigation/{?resource}{&ref,start,end,tree,down}")
collection_template = uritemplate.URITemplate("/navigation/collection/{?id,nav}")
collection_template = uritemplate.URITemplate("/collection/collection/{?id,nav}")
document_template = uritemplate.URITemplate("/document/{?resource}{&ref,start,end,tree}")

@app.route("/collection/")
Expand Down
5 changes: 4 additions & 1 deletion dapitains/app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Collection(db.Model):
filepath = db.Column(db.String, nullable=True)
dublin_core = db.Column(JSONEncoded, nullable=True)
extensions = db.Column(JSONEncoded, nullable=True)
citeStructure = db.Column(JSONEncoded, nullable=True)

# One-to-one relationship with Navigation
navigation = db.relationship('Navigation', uselist=False, backref='collection', lazy=True)
Expand Down Expand Up @@ -91,7 +92,9 @@ def json(self, inject: Optional[Dict[str, Any]] = None):
}
if self.description:
data["description"] = self.description
if self.dublin_core:
if self.citeStructure:
data["citeStructure"] = self.citeStructure
if self.dublin_core: # ToDo: Fix the way it's presented to adapt to dts view
data["dublinCore"] = self.dublin_core
if self.extensions:
data["extensions"] = self.extensions
Expand Down
21 changes: 13 additions & 8 deletions dapitains/app/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ def store_catalog(catalog: Catalog):
keys[coll_db.identifier] = coll_db.id
if collection.resource:
doc = Document(collection.filepath)
references = {
tree: [ref.json() for ref in obj.find_refs(doc.xml, structure=obj.units)]
for tree, obj in doc.citeStructure.items()
}
paths = {key: generate_paths(tree) for key, tree in references.items()}
nav = Navigation(collection_id=coll_db.id, paths=paths, references=references)
db.session.add(nav)
if doc.citeStructure:
references = {
tree: [ref.json() for ref in obj.find_refs(doc.xml, structure=obj.units)]
for tree, obj in doc.citeStructure.items()
}
paths = {key: generate_paths(tree) for key, tree in references.items()}
nav = Navigation(collection_id=coll_db.id, paths=paths, references=references)
db.session.add(nav)
coll_db.citeStructure = {
key: value.units.json()
for key, value in doc.citeStructure.items()
}
db.session.commit()

for parent, child in catalog.relationships:
Expand Down Expand Up @@ -169,4 +174,4 @@ def get_nav(

catalog, _ = ingest_catalog("/home/thibault/dev/MyDapytains/tests/catalog/example-collection.xml")

store_catalog(catalog)
store_catalog(catalog)
11 changes: 11 additions & 0 deletions dapitains/tei/citeStructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ def get(self, ref: str):
return f"{self.match}[{self.use}='{ref}']"
return f"{self.match}[{self.use}={ref}]"

def json(self):
out = {
"citeType": self.citeType,
}
if self.children:
out["citeStructure"] = [
child.json()
for child in self.children
]
return out


@dataclass
class CitableUnit:
Expand Down

0 comments on commit 9607ebd

Please sign in to comment.