Skip to content

Commit

Permalink
Profile frontend URLs (#2430)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Feb 7, 2025
1 parent b69cc42 commit 56e0592
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
6 changes: 4 additions & 2 deletions openatlas/display/classes_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ def add_file_tab_thumbnails(self) -> None:

def add_info_tab_content(self) -> None:
self.add_data()
resolver_url = g.settings['frontend_resolver_url']
if hasattr(current_user, 'settings'):
self.data |= get_system_data(self.entity)
resolver_url = current_user.settings['frontend_resolver_url']
self.tabs['info'].buttons = self.buttons
frontend_link = None
if url := g.settings['frontend_resolver_url']:
if resolver_url:
frontend_link = link(
'<i class="fas fa-eye"></i> ' +
uc_first(_('presentation site')),
url + str(self.entity.id),
resolver_url + str(self.entity.id),
external=True)
self.tabs['info'].content = render_template(
'entity/view.html',
Expand Down
8 changes: 6 additions & 2 deletions openatlas/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ def get_settings(user_id: int) -> dict[str, Any]:
'table_show_icons': False,
'show_email': False}
for setting in g.settings:
if setting in \
['map_zoom_max', 'map_zoom_default', 'table_rows'] \
if setting in [
'frontend_website_url',
'frontend_resolver_url',
'map_zoom_max',
'map_zoom_default',
'table_rows'] \
or setting.startswith('module_'):
settings[setting] = g.settings[setting]
for row in db.get_settings(user_id):
Expand Down
5 changes: 4 additions & 1 deletion openatlas/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,10 @@ def settings(category: str) -> str | Response:
form = getattr(
importlib.import_module('openatlas.forms.setting'),
f"{uc_first(category)}Form")()
tab = (category.replace('api', 'data').replace('mail', 'email'))
tab = (
category.replace('api', 'data')
.replace('mail', 'email')
.replace('frontend', 'presentation-site'))
redirect_url = f"{url_for('admin_index')}#tab-{tab}"
crumbs = [[
_('admin'),
Expand Down
6 changes: 3 additions & 3 deletions openatlas/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def overview() -> str:
'index/index_guest.html',
intro=get_translation('intro')))},
crumbs=['overview'])
frontend_url = current_user.settings['frontend_website_url']
tabs = {
'info': Tab(
'info',
Expand All @@ -51,9 +52,8 @@ def overview() -> str:
link(
'<i class="fas fa-eye"></i> ' +
uc_first(_('presentation site')),
g.settings['frontend_website_url'],
external=True) if g.settings['frontend_website_url']
else '']),
frontend_url,
external=True) if frontend_url else '']),
'bookmarks': Tab(
'bookmarks',
table=Table(['name', 'class', 'begin', 'end'])),
Expand Down
19 changes: 13 additions & 6 deletions openatlas/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from openatlas.display.util2 import manual, uc_first
from openatlas.forms.display import display_form
from openatlas.forms.field import SubmitField, generate_password_field
from openatlas.forms.setting import DisplayForm, ModulesForm
from openatlas.forms.setting import DisplayForm, FrontendForm, ModulesForm
from openatlas.forms.util import get_form_settings, set_form_settings


Expand Down Expand Up @@ -72,17 +72,23 @@ def profile_index() -> str:
'display': Tab(
'display',
display_info(get_form_settings(DisplayForm(), True)),
buttons=[manual('tools/profile')]),
'frontend': Tab(
'presentation_site',
display_info(get_form_settings(FrontendForm(), True)),
buttons=[manual('tools/profile')])}
if not app.config['DEMO_MODE']:
tabs['profile'].buttons += [
button(_('edit'), url_for('profile_settings', category='profile')),
button(_('change password'), url_for('profile_password'))]
tabs['modules'].buttons.append(
button(
_('edit'),
url_for('profile_settings', category='modules')))
button(_('edit'), url_for('profile_settings', category='modules')))
tabs['display'].buttons.append(
button(_('edit'), url_for('profile_settings', category='display')))
tabs['frontend'].buttons.append(
button(
_('edit'),
url_for('profile_settings', category='frontend')))
return render_template(
'tabs.html',
tabs=tabs,
Expand All @@ -96,6 +102,7 @@ def profile_settings(category: str) -> str | Response:
form = getattr(
importlib.import_module('openatlas.forms.setting'),
f"{uc_first(category)}Form")()
tab = 'presentation-site' if category == 'frontend' else category
if form.validate_on_submit():
settings = {}
for field in form:
Expand All @@ -121,14 +128,14 @@ def profile_settings(category: str) -> str | Response:
Transaction.rollback()
g.logger.log('error', 'database', 'transaction failed', e)
flash(_('error transaction'), 'error')
return redirect(f"{url_for('profile_index')}#tab-{category}")
return redirect(f"{url_for('profile_index')}#tab-{tab}")
set_form_settings(form, True)
return render_template(
'content.html',
content=display_form(form, manual_page='profile'),
title=_('profile'),
crumbs=[
[_('profile'), f"{url_for('profile_index')}#tab-{category}"],
[_('profile'), f"{url_for('profile_index')}#tab-{tab}"],
_(category)])


Expand Down

0 comments on commit 56e0592

Please sign in to comment.