Skip to content

Commit

Permalink
Formatting and refactoring with Pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Jun 25, 2024
1 parent c7a8579 commit e9331ce
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 32 deletions.
2 changes: 1 addition & 1 deletion openatlas/display/base_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def add_note_tab(self) -> None:
_('public') if note['public'] else _('private'),
link(User.get_by_id(note['user_id'])),
note['text'],
link(_("view"), url_for("note_view", id_=note["id"]))]
link(_('view'), url_for('note_view', id_=note['id']))]
self.tabs['note'].table.rows.append(data)

def add_buttons(self) -> None:
Expand Down
20 changes: 11 additions & 9 deletions openatlas/display/tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,13 @@ def set_buttons(self, name: str, entity: Optional[Entity] = None) -> None:
type_='member',
origin_id=id_)))
case 'member_of':
self.buttons.append(button(
'link',
url_for(
'insert_relation',
type_='membership',
origin_id=id_)))
self.buttons.append(
button(
'link',
url_for(
'insert_relation',
type_='membership',
origin_id=id_)))
case 'note' if is_authorized('contributor'):
self.buttons.append(
button(_('note'), url_for('note_insert', entity_id=id_)))
Expand Down Expand Up @@ -281,9 +282,10 @@ def set_buttons(self, name: str, entity: Optional[Entity] = None) -> None:
self.buttons.append(
button('link', url_for('entity_add_reference', id_=id_)))
for item in g.view_class_mapping['reference']:
self.buttons.append(button(
g.classes[item].label,
url_for('insert', class_=item, origin_id=id_)))
self.buttons.append(
button(
g.classes[item].label,
url_for('insert', class_=item, origin_id=id_)))
case 'relation':
self.buttons.append(
button(
Expand Down
15 changes: 6 additions & 9 deletions openatlas/display/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ def display_menu(entity: Optional[Entity], origin: Optional[Entity]) -> str:
view_name = origin.class_.view
html = ''
for item in [
'source', 'event', 'actor', 'place', 'artifact', 'reference',
'type', 'file']:
'source', 'event', 'actor', 'place', 'artifact', 'reference',
'type', 'file']:
active = ''
request_parts = request.path.split('/')
if view_name == item \
Expand All @@ -218,11 +218,8 @@ def display_menu(entity: Optional[Entity], origin: Optional[Entity]) -> str:

@app.template_filter()
def profile_image(entity: Entity) -> str:
if not entity.image_id:
if not entity.image_id or not (path := get_file_path(entity.image_id)):
return ''
if not (path := get_file_path(entity.image_id)):
return '' # pragma: no cover

file_id = entity.image_id
src = url_for('display_file', filename=path.name)
url = src
Expand Down Expand Up @@ -302,7 +299,7 @@ def format_name_and_aliases(entity: Entity, show_links: bool) -> str:
def get_base_table_data(entity: Entity, show_links: bool = True) -> list[Any]:
data: list[Any] = [format_name_and_aliases(entity, show_links)]
if entity.class_.view in [
'actor', 'artifact', 'event', 'place', 'reference']:
'actor', 'artifact', 'event', 'place', 'reference']:
data.append(entity.class_.label)
if entity.class_.standard_type_id:
data.append(entity.standard_type.name if entity.standard_type else '')
Expand Down Expand Up @@ -504,11 +501,11 @@ def link(
def button(
label: str,
url: Optional[str] = None,
css: Optional[str] = 'primary',
id_: Optional[str] = None,
onclick: Optional[str] = None,
tooltip_text: Optional[str] = None) -> str:
tag = 'a' if url else 'span'
css = 'secondary' if id_ in ['date-switcher'] else 'primary'
if url and '/insert' in url and label != _('link'):
label = f'+ <span class="uc-first d-inline-block">{label}</span>'
tooltip_ = ''
Expand Down Expand Up @@ -631,6 +628,6 @@ def convert_image_to_iiif(id_: int, path: Optional[Path] = None) -> bool:
try:
with subprocess.Popen(command) as sub_process:
sub_process.wait()
return True
except Exception: # pragma: no cover
return False
return True
5 changes: 2 additions & 3 deletions openatlas/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def __init__(self, data: dict[str, Any]) -> None:
self.origin_id: Optional[int] = None # When coming from another entity
self.image_id: Optional[int] = None # Profile image
self.location: Optional[Entity] = None # Respective location if place

self.standard_type = None
self.types = {}
self.standard_type = None

if 'types' in data and data['types']:
for item in data['types']: # f1 = type id, f2 = value
type_ = g.types[item['f1']]
Expand All @@ -51,7 +51,6 @@ def __init__(self, data: dict[str, Any]) -> None:
self.aliases = dict(
sorted(self.aliases.items(), key=lambda item_: item_[1]))

# Dates
self.begin_from = None
self.begin_to = None
self.begin_comment = None
Expand Down
7 changes: 3 additions & 4 deletions openatlas/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def update(self) -> None:
'password_reset_code': self.password_reset_code,
'password_reset_date': self.password_reset_date})

def delete(self) -> None:
db.delete(self.id)

def update_settings(self, settings: dict[str, Any]) -> None:
for name, value in settings.items():
db.update_settings(self.id, name, value)
Expand Down Expand Up @@ -126,10 +129,6 @@ def get_created_entities_count(user_id: int) -> int:
def insert(data: dict[str, Any]) -> int:
return db.insert(data)

@staticmethod
def delete(id_: int) -> None:
db.delete(id_)

@staticmethod
def get_users_for_form() -> list[tuple[int, str]]:
return db.get_users_for_form()
Expand Down
2 changes: 1 addition & 1 deletion openatlas/templates/util/dates.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<label>{{ _('date')|uc_first }}</label> {{ _('tooltip date')|tooltip|safe }}
</td>
<td class="date-switcher">
{{ label|button(id_='date-switcher', css='secondary')|safe }}
{{ label|button(id_='date-switcher')|safe }}
</td>
</tr>

Expand Down
9 changes: 5 additions & 4 deletions openatlas/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,11 @@ def log() -> str:
row['message'],
user,
row['info']])
buttons = [button(
_('delete all logs'),
url_for('log_delete'),
onclick=f"return confirm('{_('delete all logs')}?')")]
buttons = [
button(
_('delete all logs'),
url_for('log_delete'),
onclick=f"return confirm('{_('delete all logs')}?')")]

return render_template(
'tabs.html',
Expand Down
2 changes: 1 addition & 1 deletion openatlas/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def user_delete(id_:int) -> Response:
or user.id == current_user.id \
or (user.group == 'admin' and not is_authorized('admin')):
abort(403)
User.delete(id_)
user.delete()
flash(_('user deleted'), 'info')
return redirect(f"{url_for('admin_index')}#tab-user")

Expand Down

0 comments on commit e9331ce

Please sign in to comment.