Skip to content

Commit

Permalink
Check for preceding event dates
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Aug 19, 2024
1 parent 5289141 commit de04e4a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions openatlas/database/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,19 @@ def invalid_involvement_dates() -> list[dict[str, Any]]:
AND involvement.begin_from < event.begin_from);
""")
return [dict(row) for row in g.cursor.fetchall()]


def invalid_preceding_dates() -> list[dict[str, Any]]:
g.cursor.execute(
"""
SELECT link.id
FROM model.entity preceding
JOIN model.link ON preceding.id = link.range_id
AND link.property_code = 'P134'
JOIN model.entity succeeding ON link.domain_id = succeeding.id
WHERE
preceding.begin_from IS NOT NULL
AND succeeding.begin_from IS NOT NULL
AND succeeding.begin_from < preceding.begin_from;
""")
return [dict(row) for row in g.cursor.fetchall()]
6 changes: 6 additions & 0 deletions openatlas/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,12 @@ def invalid_involvement_dates() -> list[Link]:
Link.get_by_id(row['id'])
for row in date.invalid_involvement_dates()]

@staticmethod
def invalid_preceding_dates() -> list[Link]:
return [
Link.get_by_id(row['id'])
for row in date.invalid_preceding_dates()]

@staticmethod
def get_invalid_link_dates() -> list[Link]:
return [
Expand Down
10 changes: 9 additions & 1 deletion openatlas/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ def check_dates() -> str:
'invalid_involvement_dates',
buttons=[manual_link],
table=Table(
['actor', 'event', 'class', 'involvement', 'description']))}
['actor', 'event', 'class', 'involvement', 'description'])),
'preceding_dates': Tab(
'invalid_preceding_dates',
buttons=[manual_link],
table=Table(['preceding', 'succeeding']))}
for entity in get_invalid_dates():
tabs['dates'].table.rows.append([
link(entity),
Expand Down Expand Up @@ -437,6 +441,10 @@ def check_dates() -> str:
_('edit'),
url_for('link_update', id_=link_.id, origin_id=actor.id))]
tabs['involvement_dates'].table.rows.append(data)
for link_ in Link.invalid_preceding_dates():
tabs['preceding_dates'].table.rows.append([
link(link_.range),
link(link_.domain)])
for tab in tabs.values():
if not tab.table.rows:
tab.content = _('Congratulations, everything looks fine!')
Expand Down

0 comments on commit de04e4a

Please sign in to comment.