Massive overhaul of "generate project" feature

previous incarnation was woefully lacking.  new feature is much more
extensible.  still need to remove old POS integration specifics in
some places.

and a couple of unrelated things that snuck in..

- deprecate `rattail.util.OrderedDict`
- deprecate `rattail.util.import_module_path()`
- deprecate `rattail.util.import_reload()`
This commit is contained in:
Lance Edgar 2023-05-05 00:18:16 -05:00
parent 026d98551c
commit 2ed63b1c1a
22 changed files with 424 additions and 700 deletions

View file

@ -26,6 +26,7 @@ Forms Core
import json
import logging
from collections import OrderedDict
import sqlalchemy as sa
from sqlalchemy import orm
@ -346,6 +347,7 @@ class Form(object):
self.schema = schema
if self.fields is None and self.schema:
self.set_fields([f.name for f in self.schema])
self.grouping = None
self.request = request
self.readonly = readonly
self.readonly_fields = set(readonly_fields or [])
@ -371,6 +373,7 @@ class Form(object):
self.validators = validators or {}
self.required = required or {}
self.helptext = helptext or {}
self.dynamic_helptext = {}
self.focus_spec = focus_spec
self.action_url = action_url
self.cancel_url = cancel_url
@ -404,6 +407,9 @@ class Form(object):
return get_fieldnames(self.request.rattail_config, self.model_class,
columns=True, proxies=True, relations=True)
def set_grouping(self, items):
self.grouping = OrderedDict(items)
def make_renderers(self):
"""
Return a default set of field renderers, based on :attr:`model_class`.
@ -728,11 +734,15 @@ class Form(object):
"""
self.defaults[key] = value
def set_helptext(self, key, value):
def set_helptext(self, key, value, dynamic=False):
"""
Set the help text for a given field.
"""
self.helptext[key] = value
if value and dynamic:
self.dynamic_helptext[key] = True
else:
self.dynamic_helptext.pop(key, None)
def has_helptext(self, key):
"""
@ -935,7 +945,10 @@ class Form(object):
# TODO: older logic did this only if field was *not*
# readonly, perhaps should add that back..
if self.has_helptext(fieldname):
attrs['message'] = self.render_helptext(fieldname)
msgkey = 'message'
if self.dynamic_helptext.get(fieldname):
msgkey = ':message'
attrs[msgkey] = self.render_helptext(fieldname)
# show errors if present
error_messages = self.get_error_messages(field) if field else None