Changeset 4ff0450 in tailbone


Ignore:
Timestamp:
08/03/2022 02:50:45 PM (6 months ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
927470d
Parents:
862198c
git-author:
Lance Edgar <lance@…> (08/03/2022 02:44:38 PM)
git-committer:
Lance Edgar <lance@…> (08/03/2022 02:50:45 PM)
Message:

Stop using the old rattail.db.api.settings module

Location:
tailbone
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • tailbone/grids/core.py

    r862198c r4ff0450  
    3535from sqlalchemy import orm
    3636
    37 from rattail.db import api
    3837from rattail.db.types import GPCType
    3938from rattail.util import prettify, pretty_boolean, pretty_quantity, pretty_hours
     
    744743        # User defaults should have all or nothing, so just check one key.
    745744        key = 'tailbone.{}.grid.{}.sortkey'.format(user.uuid, self.key)
    746         return api.get_setting(session, key) is not None
     745        app = self.request.rattail_config.get_app()
     746        return app.get_setting(Session(), key) is not None
    747747
    748748    def apply_user_defaults(self, settings):
     
    752752        def merge(key, normalize=lambda v: v):
    753753            skey = 'tailbone.{}.grid.{}.{}'.format(self.request.user.uuid, self.key, key)
    754             value = api.get_setting(Session(), skey)
     754            app = self.request.rattail_config.get_app()
     755            value = app.get_setting(Session(), skey)
    755756            settings[key] = normalize(value)
    756757
     
    930931            if to == 'defaults':
    931932                skey = 'tailbone.{}.grid.{}.{}'.format(self.request.user.uuid, self.key, key)
    932                 api.save_setting(Session(), skey, value(key))
     933                app = self.request.rattail_config.get_app()
     934                app.save_setting(Session(), skey, value(key))
    933935            else: # to == session
    934936                skey = 'grid.{}.{}'.format(self.key, key)
  • tailbone/util.py

    r862198c r4ff0450  
    175175    registry settings with the new theme.
    176176    """
    177     from rattail.db import api
    178 
    179177    theme = get_effective_theme(request.rattail_config, theme=theme, session=session)
    180178    theme_path = get_theme_template_path(request.rattail_config, theme=theme, session=session)
     
    191189    lookup._collection.clear()
    192190
    193     api.save_setting(session, 'tailbone.theme', theme)
     191    app = request.rattail_config.get_app()
     192    close = False
     193    if not session:
     194        session = app.make_session()
     195        close = True
     196    app.save_setting(session, 'tailbone.theme', theme)
     197    if close:
     198        session.commit()
     199        session.close()
     200
    194201    request.registry.settings['tailbone.theme'] = theme
    195202
     
    210217    will be used; otherwise it is read from database setting.
    211218    """
    212     from rattail.db import api
     219    app = rattail_config.get_app()
    213220
    214221    if not theme:
    215         theme = api.get_setting(session, 'tailbone.theme') or 'default'
     222        close = False
     223        if not session:
     224            session = app.make_session()
     225            close = True
     226        theme = app.get_setting(session, 'tailbone.theme') or 'default'
     227        if close:
     228            session.close()
    216229
    217230    # confirm requested theme is available
  • tailbone/views/email.py

    r862198c r4ff0450  
    3232
    3333from rattail import mail
    34 from rattail.db import api, model
     34from rattail.db import model
    3535from rattail.config import parse_list
    3636
     
    214214        key = self.request.matchdict['key']
    215215        data = self.form_deserialized
     216        app = self.get_rattail_app()
    216217        session = self.Session()
    217         api.save_setting(session, 'rattail.mail.{}.prefix'.format(key), data['prefix'])
    218         api.save_setting(session, 'rattail.mail.{}.subject'.format(key), data['subject'])
    219         api.save_setting(session, 'rattail.mail.{}.from'.format(key), data['sender'])
    220         api.save_setting(session, 'rattail.mail.{}.replyto'.format(key), data['replyto'])
    221         api.save_setting(session, 'rattail.mail.{}.to'.format(key), (data['to'] or '').replace('\n', ', '))
    222         api.save_setting(session, 'rattail.mail.{}.cc'.format(key), (data['cc'] or '').replace('\n', ', '))
    223         api.save_setting(session, 'rattail.mail.{}.bcc'.format(key), (data['bcc'] or '').replace('\n', ', '))
    224         api.save_setting(session, 'rattail.mail.{}.enabled'.format(key), six.text_type(data['enabled']).lower())
     218        app.save_setting(session, 'rattail.mail.{}.prefix'.format(key), data['prefix'])
     219        app.save_setting(session, 'rattail.mail.{}.subject'.format(key), data['subject'])
     220        app.save_setting(session, 'rattail.mail.{}.from'.format(key), data['sender'])
     221        app.save_setting(session, 'rattail.mail.{}.replyto'.format(key), data['replyto'])
     222        app.save_setting(session, 'rattail.mail.{}.to'.format(key), (data['to'] or '').replace('\n', ', '))
     223        app.save_setting(session, 'rattail.mail.{}.cc'.format(key), (data['cc'] or '').replace('\n', ', '))
     224        app.save_setting(session, 'rattail.mail.{}.bcc'.format(key), (data['bcc'] or '').replace('\n', ', '))
     225        app.save_setting(session, 'rattail.mail.{}.enabled'.format(key), six.text_type(data['enabled']).lower())
    225226        return data
    226227
  • tailbone/views/settings.py

    r862198c r4ff0450  
    3232import six
    3333
    34 from rattail.db import model, api
     34from rattail.db import model
    3535from rattail.settings import Setting
    3636from rattail.util import import_module_path
     
    274274            else:
    275275                value = six.text_type(value)
    276             api.save_setting(Session(), legacy_name, value)
     276            app = self.get_rattail_app()
     277            app.save_setting(Session(), legacy_name, value)
    277278
    278279    def clean_list_entry(self, value):
Note: See TracChangeset for help on using the changeset viewer.