Stop using the old rattail.db.api.settings
module
This commit is contained in:
parent
862198cf82
commit
4ff0450632
|
@ -34,7 +34,6 @@ from six.moves import urllib
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
from rattail.db import api
|
|
||||||
from rattail.db.types import GPCType
|
from rattail.db.types import GPCType
|
||||||
from rattail.util import prettify, pretty_boolean, pretty_quantity, pretty_hours
|
from rattail.util import prettify, pretty_boolean, pretty_quantity, pretty_hours
|
||||||
from rattail.time import localtime
|
from rattail.time import localtime
|
||||||
|
@ -743,7 +742,8 @@ class Grid(object):
|
||||||
|
|
||||||
# User defaults should have all or nothing, so just check one key.
|
# User defaults should have all or nothing, so just check one key.
|
||||||
key = 'tailbone.{}.grid.{}.sortkey'.format(user.uuid, self.key)
|
key = 'tailbone.{}.grid.{}.sortkey'.format(user.uuid, self.key)
|
||||||
return api.get_setting(session, key) is not None
|
app = self.request.rattail_config.get_app()
|
||||||
|
return app.get_setting(Session(), key) is not None
|
||||||
|
|
||||||
def apply_user_defaults(self, settings):
|
def apply_user_defaults(self, settings):
|
||||||
"""
|
"""
|
||||||
|
@ -751,7 +751,8 @@ class Grid(object):
|
||||||
"""
|
"""
|
||||||
def merge(key, normalize=lambda v: v):
|
def merge(key, normalize=lambda v: v):
|
||||||
skey = 'tailbone.{}.grid.{}.{}'.format(self.request.user.uuid, self.key, key)
|
skey = 'tailbone.{}.grid.{}.{}'.format(self.request.user.uuid, self.key, key)
|
||||||
value = api.get_setting(Session(), skey)
|
app = self.request.rattail_config.get_app()
|
||||||
|
value = app.get_setting(Session(), skey)
|
||||||
settings[key] = normalize(value)
|
settings[key] = normalize(value)
|
||||||
|
|
||||||
if self.filterable:
|
if self.filterable:
|
||||||
|
@ -929,7 +930,8 @@ class Grid(object):
|
||||||
def persist(key, value=lambda k: settings[k]):
|
def persist(key, value=lambda k: settings[k]):
|
||||||
if to == 'defaults':
|
if to == 'defaults':
|
||||||
skey = 'tailbone.{}.grid.{}.{}'.format(self.request.user.uuid, self.key, key)
|
skey = 'tailbone.{}.grid.{}.{}'.format(self.request.user.uuid, self.key, key)
|
||||||
api.save_setting(Session(), skey, value(key))
|
app = self.request.rattail_config.get_app()
|
||||||
|
app.save_setting(Session(), skey, value(key))
|
||||||
else: # to == session
|
else: # to == session
|
||||||
skey = 'grid.{}.{}'.format(self.key, key)
|
skey = 'grid.{}.{}'.format(self.key, key)
|
||||||
self.request.session[skey] = value(key)
|
self.request.session[skey] = value(key)
|
||||||
|
|
|
@ -174,8 +174,6 @@ def set_app_theme(request, theme, session=None):
|
||||||
This also saves the setting for the new theme, and updates the running app
|
This also saves the setting for the new theme, and updates the running app
|
||||||
registry settings with the new theme.
|
registry settings with the new theme.
|
||||||
"""
|
"""
|
||||||
from rattail.db import api
|
|
||||||
|
|
||||||
theme = get_effective_theme(request.rattail_config, theme=theme, session=session)
|
theme = get_effective_theme(request.rattail_config, theme=theme, session=session)
|
||||||
theme_path = get_theme_template_path(request.rattail_config, theme=theme, session=session)
|
theme_path = get_theme_template_path(request.rattail_config, theme=theme, session=session)
|
||||||
|
|
||||||
|
@ -190,7 +188,16 @@ def set_app_theme(request, theme, session=None):
|
||||||
# clear template cache for lookup object, so it will reload each (as needed)
|
# clear template cache for lookup object, so it will reload each (as needed)
|
||||||
lookup._collection.clear()
|
lookup._collection.clear()
|
||||||
|
|
||||||
api.save_setting(session, 'tailbone.theme', theme)
|
app = request.rattail_config.get_app()
|
||||||
|
close = False
|
||||||
|
if not session:
|
||||||
|
session = app.make_session()
|
||||||
|
close = True
|
||||||
|
app.save_setting(session, 'tailbone.theme', theme)
|
||||||
|
if close:
|
||||||
|
session.commit()
|
||||||
|
session.close()
|
||||||
|
|
||||||
request.registry.settings['tailbone.theme'] = theme
|
request.registry.settings['tailbone.theme'] = theme
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,10 +216,16 @@ def get_effective_theme(rattail_config, theme=None, session=None):
|
||||||
Validates and returns the "effective" theme. If you provide a theme, that
|
Validates and returns the "effective" theme. If you provide a theme, that
|
||||||
will be used; otherwise it is read from database setting.
|
will be used; otherwise it is read from database setting.
|
||||||
"""
|
"""
|
||||||
from rattail.db import api
|
app = rattail_config.get_app()
|
||||||
|
|
||||||
if not theme:
|
if not theme:
|
||||||
theme = api.get_setting(session, 'tailbone.theme') or 'default'
|
close = False
|
||||||
|
if not session:
|
||||||
|
session = app.make_session()
|
||||||
|
close = True
|
||||||
|
theme = app.get_setting(session, 'tailbone.theme') or 'default'
|
||||||
|
if close:
|
||||||
|
session.close()
|
||||||
|
|
||||||
# confirm requested theme is available
|
# confirm requested theme is available
|
||||||
available = rattail_config.getlist('tailbone', 'themes',
|
available = rattail_config.getlist('tailbone', 'themes',
|
||||||
|
|
|
@ -31,7 +31,7 @@ import re
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from rattail import mail
|
from rattail import mail
|
||||||
from rattail.db import api, model
|
from rattail.db import model
|
||||||
from rattail.config import parse_list
|
from rattail.config import parse_list
|
||||||
|
|
||||||
import colander
|
import colander
|
||||||
|
@ -213,15 +213,16 @@ class EmailSettingView(MasterView):
|
||||||
def save_edit_form(self, form):
|
def save_edit_form(self, form):
|
||||||
key = self.request.matchdict['key']
|
key = self.request.matchdict['key']
|
||||||
data = self.form_deserialized
|
data = self.form_deserialized
|
||||||
|
app = self.get_rattail_app()
|
||||||
session = self.Session()
|
session = self.Session()
|
||||||
api.save_setting(session, 'rattail.mail.{}.prefix'.format(key), data['prefix'])
|
app.save_setting(session, 'rattail.mail.{}.prefix'.format(key), data['prefix'])
|
||||||
api.save_setting(session, 'rattail.mail.{}.subject'.format(key), data['subject'])
|
app.save_setting(session, 'rattail.mail.{}.subject'.format(key), data['subject'])
|
||||||
api.save_setting(session, 'rattail.mail.{}.from'.format(key), data['sender'])
|
app.save_setting(session, 'rattail.mail.{}.from'.format(key), data['sender'])
|
||||||
api.save_setting(session, 'rattail.mail.{}.replyto'.format(key), data['replyto'])
|
app.save_setting(session, 'rattail.mail.{}.replyto'.format(key), data['replyto'])
|
||||||
api.save_setting(session, 'rattail.mail.{}.to'.format(key), (data['to'] or '').replace('\n', ', '))
|
app.save_setting(session, 'rattail.mail.{}.to'.format(key), (data['to'] or '').replace('\n', ', '))
|
||||||
api.save_setting(session, 'rattail.mail.{}.cc'.format(key), (data['cc'] or '').replace('\n', ', '))
|
app.save_setting(session, 'rattail.mail.{}.cc'.format(key), (data['cc'] or '').replace('\n', ', '))
|
||||||
api.save_setting(session, 'rattail.mail.{}.bcc'.format(key), (data['bcc'] or '').replace('\n', ', '))
|
app.save_setting(session, 'rattail.mail.{}.bcc'.format(key), (data['bcc'] or '').replace('\n', ', '))
|
||||||
api.save_setting(session, 'rattail.mail.{}.enabled'.format(key), six.text_type(data['enabled']).lower())
|
app.save_setting(session, 'rattail.mail.{}.enabled'.format(key), six.text_type(data['enabled']).lower())
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def template_kwargs_view(self, **kwargs):
|
def template_kwargs_view(self, **kwargs):
|
||||||
|
|
|
@ -31,7 +31,7 @@ import re
|
||||||
import json
|
import json
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from rattail.db import model, api
|
from rattail.db import model
|
||||||
from rattail.settings import Setting
|
from rattail.settings import Setting
|
||||||
from rattail.util import import_module_path
|
from rattail.util import import_module_path
|
||||||
|
|
||||||
|
@ -273,7 +273,8 @@ class AppSettingsView(View):
|
||||||
value = ', '.join(entries)
|
value = ', '.join(entries)
|
||||||
else:
|
else:
|
||||||
value = six.text_type(value)
|
value = six.text_type(value)
|
||||||
api.save_setting(Session(), legacy_name, value)
|
app = self.get_rattail_app()
|
||||||
|
app.save_setting(Session(), legacy_name, value)
|
||||||
|
|
||||||
def clean_list_entry(self, value):
|
def clean_list_entry(self, value):
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
|
|
Loading…
Reference in a new issue