Skip to content

Commit

Permalink
Refactor: formatting and checking uc_first link params
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Nov 24, 2024
1 parent dde3e00 commit d99babe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
2 changes: 0 additions & 2 deletions openatlas/display/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,11 @@ def link(
html = link(
object_.code,
url_for('cidoc_class_view', code=object_.code),
uc_first_=False,
external=external)
elif isinstance(object_, CidocProperty):
html = link(
object_.code,
url_for('property_view', code=object_.code),
uc_first_=False,
external=external)
elif isinstance(object_, Project):
html = link(
Expand Down
9 changes: 2 additions & 7 deletions openatlas/views/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from flask_babel import lazy_gettext as _

from openatlas import app
from openatlas.display.util import link


@app.route('/changelog')
Expand Down Expand Up @@ -1012,9 +1011,5 @@ def index_changelog() -> str:
'318': 'Import definitions from CIDOC rdfs'}}],
'0.0.1': ['2014-11-05', {
'feature': {
'': 'Initial version based on the Zend Base project from ' +
link(
'craws.net',
'https://craws.net',
uc_first_=False,
external=True)}}]}
'': 'Initial version based on the Zend Base project from craws.net'
}}]}
11 changes: 4 additions & 7 deletions openatlas/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,17 @@ def user_view(id_: int) -> str:
user = User.get_by_id(id_)
if not user:
abort(404)
created_count = ''
if count := User.get_created_entities_count(user.id):
created_count = link(
format_number(count),
url_for("user_entities", id_=user.id),
uc_first_=False)
count = ''
if x := User.get_created_entities_count(user.id):
count = link(format_number(x), url_for("user_entities", id_=user.id))
info = {
_('username'): user.username,
_('group'): user.group,
_('full name'): user.real_name,
_('email'):
user.email
if is_authorized('manager') or user.settings['show_email'] else '',
_('created entities'): created_count,
_('created entities'): count,
_('activity'):
link(_('log'), url_for('user_activity', user_id=user.id)),
_('language'): user.settings['language'],
Expand Down
26 changes: 13 additions & 13 deletions tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def test_file(self) -> None:

logo = Path(
app.root_path) / 'static' / 'images' / 'layout' / 'logo.png'

with open(logo, 'rb') as img_1, open(logo, 'rb') as img_2:
rv: Any = self.app.post(
url_for('insert', class_='file', origin_id=place.id),
Expand Down Expand Up @@ -172,8 +171,7 @@ def test_file(self) -> None:
rv = self.app.get(url_for('view', id_=iiif_id))
assert b'View in IIIF' in rv.data

rv = self.app.get(
url_for('view', id_=place.id, _anchor="tab-file"))
rv = self.app.get(url_for('view', id_=place.id))
assert b'view all IIIF images' in rv.data

with app.test_request_context():
Expand Down Expand Up @@ -206,9 +204,11 @@ def test_file(self) -> None:

rv = self.app.get(url_for('api.licensed_file_overview'))
assert bool(len(rv.get_json().keys()) == 4)

rv = self.app.get(
url_for('api.licensed_file_overview', download=True))
assert bool(len(rv.get_json().keys()) == 4)

rv = self.app.get(
url_for('api.licensed_file_overview', file_id=iiif_id))
assert bool(len(rv.get_json().keys()) == 1)
Expand All @@ -234,9 +234,7 @@ def test_file(self) -> None:
follow_redirects=True)
assert b'An interesting annotation' in rv.data

rv = self.app.get(url_for(
'view_iiif',
id_=iiif_id))
rv = self.app.get(url_for('view_iiif', id_=iiif_id))
assert b'Mirador' in rv.data

rv = self.app.get(
Expand Down Expand Up @@ -266,9 +264,10 @@ def test_file(self) -> None:
assert bool(str(iiif_id) in json['@id'])

annotation_id = json['resources'][0]['@id'].rsplit('/', 1)[-1]
rv = self.app.get(url_for(
'api.iiif_annotation',
annotation_id=annotation_id.replace('.json', '')))
rv = self.app.get(
url_for(
'api.iiif_annotation',
annotation_id=annotation_id.replace('.json', '')))
assert bool(annotation_id in rv.get_json()['@id'])

with app.test_request_context():
Expand All @@ -289,10 +288,11 @@ def test_file(self) -> None:
app.preprocess_request()
iiif_file.delete_links(['P67'])

rv = self.app.get(url_for(
'admin_annotation_remove_entity',
annotation_id=1,
entity_id=place.id),
rv = self.app.get(
url_for(
'admin_annotation_remove_entity',
annotation_id=1,
entity_id=place.id),
follow_redirects=True)
assert b'Entity removed from annotation' in rv.data

Expand Down

0 comments on commit d99babe

Please sign in to comment.