Skip to content

Commit

Permalink
fixed snackbar without url prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
clemenstyp committed Mar 22, 2024
1 parent e43a20d commit fb17be7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Snackbar/Adminpage/MyUserModelView.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class MyUserModelView(ModelView):
lastName='Last Name',
imageName='User Image')

column_list = ('firstName', 'lastName', 'email', 'hidden')
column_sortable_list = ('firstName', 'lastName', 'email', 'hidden')
column_list = ('firstName', 'lastName', 'email', 'imageName', 'hidden')
column_sortable_list = ('firstName', 'lastName', 'email', 'imageName', 'hidden')

def is_accessible(self):
return loginflask.current_user.is_authenticated
6 changes: 5 additions & 1 deletion Snackbar/Adminpage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

def setup_admin(app):
init_login(app)
admin = Admin(app, name='SnackBar Admin Page', index_view=MyAdminIndexView(), base_template='my_master.html',
admin = Admin(app, name='SnackBar Admin Page',
url=app.config["APPLICATION_ROOT"],
index_view=MyAdminIndexView(),
base_template='my_master.html',
template_mode='bootstrap3')

admin.add_view(MyBillView(name='Bill', endpoint='bill'))
# admin.add_view(MyAccountingView(name='Accounting', endpoint='accounting'))
admin.add_view(MyPaymentModelView(Inpayment, db.session, 'Inpayment'))
Expand Down
25 changes: 15 additions & 10 deletions Snackbar_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class Options:


def simple(env, resp):
resp('301 Moved Permanently', [('Location', options.url_prefix)])
resp('307 Temporary Redirect', [('Location', options.url_prefix)])
return [b'']
# resp(b'200 OK', [(b'Content-Type', b'text/plain')])
# return [b'You have to call the url_prefix']
# return [bytes(f'you have to call the url_suffix: {options.url_prefix}', 'utf8')]


def load_args_options():
Expand Down Expand Up @@ -66,16 +66,16 @@ def get_default_options(default_host="0.0.0.0", default_port="5000", default_url
else:
default_options.port = default_port

if url_prefix := os.getenv("SNACKBAR_URL_PREFIX"):
default_options.url_prefix = url_prefix
if url_prefix := os.getenv("SNACKBAR_URL_PREFIX", "") != "":
if url_prefix.startswith("/"):
default_options.url_prefix = url_prefix
else:
default_options.url_prefix = f"/{url_prefix}"
else:
default_options.url_prefix = default_url_prefix

if debug := os.getenv("SNACKBAR_DEBUG"):
if debug.lower() == 'true':
default_options.debug = True
else:
default_options.debug = False
if os.getenv("SNACKBAR_DEBUG", 'False').lower() == 'true':
default_options.debug = True
else:
default_options.debug = False

Expand All @@ -96,6 +96,11 @@ def init_app():
global options
app.wsgi_app = DispatcherMiddleware(simple, {options.url_prefix: app.wsgi_app})
app.config["APPLICATION_ROOT"] = options.url_prefix
if options.url_prefix.startswith("/"):
app.config['SESSION_COOKIE_PATH'] = options.url_prefix
else:
app.config['SESSION_COOKIE_PATH'] = "/"

app.config['SECRET_KEY'] = f"{options.secret_key}_{options.url_prefix}"
app.config['DEBUG'] = options.debug

Expand Down Expand Up @@ -133,5 +138,5 @@ def init_app():
load_args_options()
init_app()
start_schedule()
app.run(debug=options.debug, host=options.host, port=int(options.port))
app.run(debug=options.debug, host=options.host, port=int(options.port), use_debugger=False, use_reloader=False)
stop_schedule()
2 changes: 1 addition & 1 deletion templates/my_master.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script src="{{url_for('static', filename='idleTimer.js')}}"></script>
<script type="text/javascript">
var idleTimer = new IdleTimerOpenURL();
idleTimer.setupTimer(30, '{{ url_for('initial') }}');
idleTimer.setupTimer(90, '{{ url_for('initial') }}');
</script>

{% endif %}
Expand Down

0 comments on commit fb17be7

Please sign in to comment.