2
0
Fork 0

feat: allow app db to be rattail-native instead of wutta-native

not sure if that's even a good idea, but it sort of works..  more
improvements would be needed, just saving the progress for now
This commit is contained in:
Lance Edgar 2024-08-23 22:10:25 -05:00
parent 43ad0ae1c1
commit 1804e74d13
7 changed files with 36 additions and 6 deletions

View file

@ -61,7 +61,7 @@ class WebAppProvider(AppProvider):
return self.web_handler return self.web_handler
def make_wutta_config(settings): def make_wutta_config(settings, config_maker=None, **kwargs):
""" """
Make a WuttaConfig object from the given settings. Make a WuttaConfig object from the given settings.
@ -93,8 +93,9 @@ def make_wutta_config(settings):
"section of config to the path of your " "section of config to the path of your "
"config file. Lame, but necessary.") "config file. Lame, but necessary.")
# make config per usual, add to settings # make config, add to settings
wutta_config = make_config(path) config_maker = config_maker or make_config
wutta_config = config_maker(path, **kwargs)
settings['wutta_config'] = wutta_config settings['wutta_config'] = wutta_config
# configure database sessions # configure database sessions

View file

@ -258,7 +258,12 @@ class PersonRef(ObjectRef):
This is a subclass of :class:`ObjectRef`. This is a subclass of :class:`ObjectRef`.
""" """
model_class = Person
@property
def model_class(self):
""" """
model = self.app.model
return model.Person
def sort_query(self, query): def sort_query(self, query):
""" """ """ """

View file

@ -223,7 +223,7 @@ class UserRefsWidget(WuttaCheckboxChoiceWidget):
users = [] users = []
if cstruct: if cstruct:
for uuid in cstruct: for uuid in cstruct:
user = self.session.query(model.User).get(uuid) user = self.session.get(model.User, uuid)
if user: if user:
users.append(dict([(key, getattr(user, key)) users.append(dict([(key, getattr(user, key))
for key in columns + ['uuid']])) for key in columns + ['uuid']]))

View file

@ -1047,7 +1047,13 @@ class Grid:
filters = filters or {} filters = filters or {}
if self.model_class: if self.model_class:
for key in self.get_model_columns(): # TODO: i tried using self.get_model_columns() here but in
# many cases that will be too aggressive. however it is
# often the case that the *grid* columns are a subset of
# the unerlying *table* columns. so until a better way
# is found, we choose "too few" instead of "too many"
# filters here. surely must improve it at some point.
for key in self.columns:
if key in filters: if key in filters:
continue continue
prop = getattr(self.model_class, key, None) prop = getattr(self.model_class, key, None)

View file

@ -123,6 +123,12 @@ class PersonView(MasterView):
@classmethod @classmethod
def defaults(cls, config): def defaults(cls, config):
""" """ """ """
# nb. Person may come from custom model
wutta_config = config.registry.settings['wutta_config']
app = wutta_config.get_app()
cls.model_class = app.model.Person
cls._defaults(config) cls._defaults(config)
cls._people_defaults(config) cls._people_defaults(config)

View file

@ -51,6 +51,7 @@ class AppInfoView(MasterView):
model_name = 'AppInfo' model_name = 'AppInfo'
model_title_plural = "App Info" model_title_plural = "App Info"
route_prefix = 'appinfo' route_prefix = 'appinfo'
filterable = False
sort_on_backend = False sort_on_backend = False
sort_defaults = 'name' sort_defaults = 'name'
paginated = False paginated = False

View file

@ -207,6 +207,17 @@ class UserView(MasterView):
role = session.get(model.Role, uuid) role = session.get(model.Role, uuid)
user.roles.remove(role) user.roles.remove(role)
@classmethod
def defaults(cls, config):
""" """
# nb. User may come from custom model
wutta_config = config.registry.settings['wutta_config']
app = wutta_config.get_app()
cls.model_class = app.model.User
cls._defaults(config)
def defaults(config, **kwargs): def defaults(config, **kwargs):
base = globals() base = globals()