Skip to content

Commit

Permalink
added with count to cidoc properties
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardKoschicek committed Mar 6, 2025
1 parent 5145468 commit 9c489be
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
8 changes: 3 additions & 5 deletions openatlas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import locale
import datetime
import locale
from typing import Any, Optional

from flask import Flask, Response, g, request, session
Expand Down Expand Up @@ -55,21 +55,20 @@ def before_request() -> None:

if request.path.startswith('/static'):
return # Avoid files overhead if not using Apache with static alias

g.logger = Logger()
g.db = open_connection(app.config)
g.db.autocommit = True
g.cursor = g.db.cursor(cursor_factory=extras.DictCursor)
g.settings = Settings.get_settings()
session['language'] = get_locale()
g.cidoc_classes = CidocClass.get_all(session['language'])
g.properties = CidocProperty.get_all(session['language'])
g.classes = OpenatlasClass.get_all()
with_count = False
if (request.path.startswith(('/type', '/api/type_tree/', '/admin/orphans'))
or (request.path.startswith('/entity/') and
request.path.split('/entity/')[1].isdigit())):
with_count = True
g.properties = CidocProperty.get_all(session['language'], with_count)
g.classes = OpenatlasClass.get_all()
g.types = Type.get_all(with_count)
g.radiocarbon_type = Type.get_hierarchy('Radiocarbon')
g.sex_type = Type.get_hierarchy('Features for sexing')
Expand All @@ -86,7 +85,6 @@ def before_request() -> None:
setup_files()
setup_api()


def setup_files() -> None:
from openatlas.models.entity import Entity
g.files = {}
Expand Down
2 changes: 1 addition & 1 deletion openatlas/api/resources/database_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_all_links_as_dict() -> list[dict[str, Any]]:


def get_properties() -> list[dict[str, Any]]:
return db_property.get_properties()
return db_property.get_properties(True)


def get_property_hierarchy() -> list[dict[str, Any]]:
Expand Down
8 changes: 4 additions & 4 deletions openatlas/database/cidoc_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
from flask import g


def get_properties() -> list[dict[str, Any]]:
def get_properties(with_count: bool) -> list[dict[str, Any]]:
g.cursor.execute(
"""
f"""
SELECT
p.code,
p.comment,
p.domain_class_code,
p.range_class_code,
p.name,
p.name_inverse,
COUNT(l.id) AS count
{'COUNT(l.id)' if with_count else 0} AS count
FROM model.property p
LEFT JOIN model.link l ON p.code = l.property_code
{'LEFT JOIN model.link l ON p.code = l.property_code' if with_count else ''}
GROUP BY (
p.code,
p.comment,
Expand Down
5 changes: 3 additions & 2 deletions openatlas/models/cidoc_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ def find_subs(
return False

@staticmethod
def get_all(language: str) -> dict[str, CidocProperty]:
def get_all(language: str, with_count: bool) -> dict[str, CidocProperty]:
properties = {
row['code']: CidocProperty(row) for row in db.get_properties()}
row['code']: CidocProperty(row)
for row in db.get_properties(with_count)}
for row in db.get_hierarchy():
properties[row['super_code']].sub.append(row['sub_code'])
properties[row['sub_code']].super.append(row['super_code'])
Expand Down

0 comments on commit 9c489be

Please sign in to comment.