mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Initial cut at saving/retrieving the main browser layout.
Still needs some work to: - Minimise AJAX calls by writing multiple settings at once. - Move the settings storage/retrieval JS code into a global file - Avoid using synchronous AJAX calls in the main thread
This commit is contained in:
37
web/pgadmin/settings/__init__.py
Normal file
37
web/pgadmin/settings/__init__.py
Normal file
@@ -0,0 +1,37 @@
|
||||
##########################################################################
|
||||
#
|
||||
# pgAdmin 4 - PostgreSQL Tools
|
||||
#
|
||||
# Copyright (C) 2013 - 2014, The pgAdmin Development Team
|
||||
# This software is released under the PostgreSQL Licence
|
||||
#
|
||||
##########################################################################
|
||||
|
||||
"""Utility functions for storing and retrieving user configuration settings."""
|
||||
|
||||
from flask import current_app
|
||||
from flask.ext.login import current_user
|
||||
from flask.ext.sqlalchemy import SQLAlchemy
|
||||
|
||||
from settings_model import db, Setting
|
||||
|
||||
def store_setting(setting, value):
|
||||
"""Set a configuration setting for the current user."""
|
||||
db.init_app(current_app)
|
||||
|
||||
data = Setting(user_id=current_user.id, setting=setting, value=value)
|
||||
|
||||
db.session.merge(data)
|
||||
db.session.commit()
|
||||
|
||||
def get_setting(setting, default=None):
|
||||
"""Retrieve a configuration setting for the current user, or return the
|
||||
default value specified by the caller."""
|
||||
db.init_app(current_app)
|
||||
|
||||
data = Setting.query.filter_by(user_id=current_user.id, setting=setting).first()
|
||||
|
||||
if not data or data.value is None:
|
||||
return default
|
||||
else:
|
||||
return data.value
|
Reference in New Issue
Block a user