Skip to content

Commit

Permalink
Removed obsolete code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed May 7, 2024
1 parent d1c4fe1 commit 6127c3d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 54 deletions.
19 changes: 0 additions & 19 deletions openatlas/database/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,6 @@ def get_by_ids(
return [dict(row) for row in g.cursor.fetchall()]


def get_by_link_property(code: str, class_: str) -> list[dict[str, Any]]:
g.cursor.execute(
"""
SELECT
e.id,
e.cidoc_class_code,
e.name,
e.openatlas_class_name,
e.description,
e.created,
e.modified
FROM model.entity e
JOIN model.link l ON e.id = l.domain_id AND l.property_code = %(code)s
WHERE e.openatlas_class_name = %(class)s;
""",
{'code': code, 'class': class_})
return [dict(row) for row in g.cursor.fetchall()]


def get_by_project_id(project_id: int) -> list[dict[str, Any]]:
g.cursor.execute(
"""
Expand Down
12 changes: 8 additions & 4 deletions openatlas/display/tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,17 @@ def set_buttons(self, name: str, entity: Optional[Entity] = None) -> None:
if name == 'actor':
if view == 'file':
self.buttons.append(
button('link', url_for('file_add', id_=id_, view=name)))
button('link', url_for('file_add', id_=id_, view='actor')))
elif view == 'reference':
self.buttons.append(
button(
'link',
url_for('reference_add', id_=id_, view=name)))
url_for('reference_add', id_=id_, view='actor')))
elif view == 'source':
self.buttons.append(
button('link', url_for('link_insert', id_=id_, view=name)))
button(
'link',
url_for('link_insert', id_=id_, view='actor')))
elif view == 'event':
self.buttons.append(button(
'link',
Expand Down Expand Up @@ -236,7 +238,9 @@ def set_buttons(self, name: str, entity: Optional[Entity] = None) -> None:
url_for('reference_add', id_=id_, view=name)))
elif view == 'source':
self.buttons.append(
button('link', url_for('link_insert', id_=id_, view=name)))
button(
'link',
url_for('link_insert', id_=id_, view='source')))
self.buttons.append(
button(
g.classes[name].label,
Expand Down
4 changes: 0 additions & 4 deletions openatlas/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,6 @@ def get_by_project_id(project_id: int) -> list[Entity]:
entities.append(entity)
return entities

@staticmethod
def get_by_link_property(code: str, class_: str) -> list[Entity]:
return [Entity(row) for row in db.get_by_link_property(code, class_)]

@staticmethod
def get_similar_named(class_: str, ratio: int) -> dict[int, Any]:
similar: dict[int, Any] = {}
Expand Down
18 changes: 2 additions & 16 deletions openatlas/views/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,15 @@ def link_delete(id_: int, origin_id: int) -> Response:
@required_group('contributor')
def link_insert(id_: int, view: str) -> str | Response:
entity = Entity.get_by_id(id_)
property_code = 'P67'
inverse = False
if entity.class_.view == 'actor' and view == 'artifact':
property_code = 'P52'
inverse = True
if request.method == 'POST':
if request.form['checkbox_values']:
entity.link_string(
property_code,
request.form['checkbox_values'],
inverse=inverse)
entity.link_string('P67', request.form['checkbox_values'])
return redirect(f"{url_for('view', id_=entity.id)}#tab-{view}")
if entity.class_.view == 'actor' and view == 'artifact':
excluded = \
Entity.get_by_link_property(property_code, 'artifact') + \
Entity.get_by_link_property(property_code, 'human_remains')
else:
excluded = entity.get_linked_entities(property_code, inverse=inverse)
return render_template(
'content.html',
content=get_table_form(
g.view_class_mapping[view],
[e.id for e in excluded]),
[e.id for e in entity.get_linked_entities('P67')]),
title=_(entity.class_.view),
crumbs=[
[_(entity.class_.view), url_for('index', view=entity.class_.view)],
Expand Down
13 changes: 3 additions & 10 deletions tests/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def test_artifact(self) -> None:
'super': place.id})
artifact_id = rv.location.split('/')[-1]

rv = self.app.get(url_for('view', id_=actor.id))
assert b'Love-letter' in rv.data

rv = self.app.get(url_for('add_subunit', super_id=place.id))
assert b'Love-letter' not in rv.data

Expand Down Expand Up @@ -72,16 +75,6 @@ def test_artifact(self) -> None:
follow_redirects=True)
assert b'Event Zero' in rv.data

rv = self.app.get(
url_for('link_insert', id_=actor.id, view='artifact'))
assert b'A little hate' in rv.data

rv = self.app.post(
url_for('link_insert', id_=actor.id, view='artifact'),
data={'checkbox_values': [artifact_id]},
follow_redirects=True)
assert b'A little hate' in rv.data

rv = self.app.get(
url_for('insert', class_='artifact', origin_id=actor.id))
assert b'Conan' in rv.data
Expand Down
7 changes: 6 additions & 1 deletion tests/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ def test_source(self) -> None:
assert b'Artifact with inscription' in rv.data

rv = self.app.get(
url_for('link_insert', id_=source_id, view='actor'))
assert b'Gillian' in rv.data

rv = self.app.post(
url_for('link_insert', id_=source_id, view='actor'),
data={'checkbox_values': [gillian.id]})
data={'checkbox_values': [gillian.id]},
follow_redirects=True)
assert b'Gillian' in rv.data

rv = self.app.get(url_for('update', id_=source_id))
Expand Down

0 comments on commit 6127c3d

Please sign in to comment.