Skip to content

Commit

Permalink
Invalid sub dates
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Aug 20, 2024
1 parent de04e4a commit b74e753
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
25 changes: 25 additions & 0 deletions openatlas/database/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,28 @@ def invalid_preceding_dates() -> list[dict[str, Any]]:
AND succeeding.begin_from < preceding.begin_from;
""")
return [dict(row) for row in g.cursor.fetchall()]


def invalid_sub_dates() -> list[dict[str, Any]]:
g.cursor.execute(
"""
SELECT link.id
FROM model.entity super
JOIN model.link ON super.id = link.domain_id
AND link.property_code = 'P9'
JOIN model.entity sub ON link.range_id = sub.id
WHERE
(super.begin_from IS NOT NULL
AND sub.begin_from IS NOT NULL
AND sub.begin_from < super.begin_from)
OR (super.end_from IS NOT NULL AND sub.end_from IS NOT NULL
AND (super.end_to IS NULL AND sub.end_to IS NULL AND
sub.end_from > super.end_from)
OR (super.end_to IS NULL AND sub.end_to IS NOT NULL AND
sub.end_from > super.end_to)
OR (super.end_to IS NOT NULL AND sub.end_to IS NULL AND
sub.end_to > super.end_from)
OR (super.end_to IS NOT NULL AND sub.end_to IS NOT NULL AND
sub.end_to > super.end_to));
""")
return [dict(row) for row in g.cursor.fetchall()]
2 changes: 2 additions & 0 deletions openatlas/display/tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
_('invalid dates')
_('invalid link dates')
_('invalid involvement dates')
_('invalid preceding dates')
_('invalid sub dates')
_('member of')
_('missing files')
_('modules')
Expand Down
6 changes: 6 additions & 0 deletions openatlas/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,12 @@ def invalid_preceding_dates() -> list[Link]:
Link.get_by_id(row['id'])
for row in date.invalid_preceding_dates()]

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

@staticmethod
def get_invalid_link_dates() -> list[Link]:
return [
Expand Down
13 changes: 7 additions & 6 deletions openatlas/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,9 @@ def check_similar() -> str:
@app.route('/check/dates')
@required_group('contributor')
def check_dates() -> str:
manual_link = manual('admin/data_integrity_checks')
tabs = {
'dates': Tab(
'invalid_dates',
buttons=[manual_link],
table=Table([
'name',
'class',
Expand All @@ -402,17 +400,15 @@ def check_dates() -> str:
'description'])),
'link_dates': Tab(
'invalid_link_dates',
buttons=[manual_link],
table=Table(['link', 'domain', 'range'])),
'involvement_dates': Tab(
'invalid_involvement_dates',
buttons=[manual_link],
table=Table(
['actor', 'event', 'class', 'involvement', 'description'])),
'preceding_dates': Tab(
'invalid_preceding_dates',
buttons=[manual_link],
table=Table(['preceding', 'succeeding']))}
table=Table(['preceding', 'succeeding'])),
'sub_dates': Tab('invalid_sub_dates', table=Table(['super', 'sub']))}
for entity in get_invalid_dates():
tabs['dates'].table.rows.append([
link(entity),
Expand Down Expand Up @@ -445,7 +441,12 @@ def check_dates() -> str:
tabs['preceding_dates'].table.rows.append([
link(link_.range),
link(link_.domain)])
for link_ in Link.invalid_sub_dates():
tabs['sub_dates'].table.rows.append([
link(link_.range),
link(link_.domain)])
for tab in tabs.values():
tab.buttons = manual('admin/data_integrity_checks'),
if not tab.table.rows:
tab.content = _('Congratulations, everything looks fine!')
return render_template(
Expand Down

0 comments on commit b74e753

Please sign in to comment.