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:
Dave Page
2015-02-11 10:00:57 +00:00
parent 506dd6437f
commit e995104000
8 changed files with 165 additions and 115 deletions

View 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