Set explicit referrer when changing app theme

to include url #hash value if there is one, so switching theme is more
seamless from the view profile page
This commit is contained in:
Lance Edgar 2024-06-04 01:05:05 -05:00
parent 6a7c06d26e
commit 00e2af1561
3 changed files with 10 additions and 7 deletions

View file

@ -401,6 +401,7 @@
<div class="level-item">
${h.form(url('change_theme'), method="post", ref='themePickerForm')}
${h.csrf_token(request)}
<input type="hidden" name="referrer" :value="referrer" />
<div style="display: flex; align-items: center; gap: 0.5rem;">
<span>Theme:</span>
<b-select name="theme"
@ -856,6 +857,7 @@
% if expose_theme_picker and request.has_perm('common.change_app_theme'):
globalTheme: ${json.dumps(theme)|n},
referrer: location.href,
% endif
% if can_edit_help:

View file

@ -792,6 +792,7 @@
% if expose_theme_picker and request.has_perm('common.change_app_theme'):
${h.form(url('change_theme'), method="post", ref='themePickerForm')}
${h.csrf_token(request)}
<input type="hidden" name="referrer" :value="referrer" />
<div style="display: flex; align-items: center; gap: 0.5rem;">
<span>Theme:</span>
<b-select name="theme"
@ -1121,6 +1122,7 @@
% if expose_theme_picker and request.has_perm('common.change_app_theme'):
globalTheme: ${json.dumps(theme)|n},
referrer: location.href,
% endif
% if can_edit_help:

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2023 Lance Edgar
# Copyright © 2010-2024 Lance Edgar
#
# This file is part of Rattail.
#
@ -24,16 +24,14 @@
Various common views
"""
import importlib
import os
from collections import OrderedDict
from rattail.batch import consume_batch_id
from rattail.util import simple_error, import_module_path
from rattail.util import simple_error
from rattail.files import resource_path
from pyramid import httpexceptions
from pyramid.response import Response
from tailbone import forms
from tailbone.forms.common import Feedback
from tailbone.db import Session
@ -110,7 +108,7 @@ class CommonView(View):
return self.project_version
pkg = self.rattail_config.app_package()
mod = import_module_path(pkg)
mod = importlib.import_module(pkg)
return mod.__version__
def exception(self):
@ -155,7 +153,8 @@ class CommonView(View):
self.request.session.flash(msg, 'error')
else:
self.request.session.flash("App theme has been changed to: {}".format(theme))
return self.redirect(self.request.get_referrer())
referrer = self.request.params.get('referrer') or self.request.get_referrer()
return self.redirect(referrer)
def change_db_engine(self):
"""