From a0f6ddaeb0c15f0a1560ffa6e96992e077d8c372 Mon Sep 17 00:00:00 2001 From: Sean McCarthy Date: Fri, 3 Jun 2022 11:59:32 -0600 Subject: [PATCH] improved documentation and functionality for legacy class Row() in form rules --- examples/forms-files-images/app.py | 5 ++++- flask_admin/form/rules.py | 30 ++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/examples/forms-files-images/app.py b/examples/forms-files-images/app.py index 59fd61516c..fc3a34b65d 100644 --- a/examples/forms-files-images/app.py +++ b/examples/forms-files-images/app.py @@ -65,7 +65,9 @@ class User(db.Model): email = db.Column(db.Unicode(128)) phone = db.Column(db.Unicode(32)) city = db.Column(db.Unicode(128)) + state = db.Column(db.Unicode(128)) country = db.Column(db.Unicode(128)) + continent = db.Column(db.Unicode(128)) notes = db.Column(db.UnicodeText) @@ -176,7 +178,8 @@ class UserView(sqla.ModelView): rules.Header('Location'), rules.Field('city'), # String is resolved to form field, so there's no need to explicitly use `rules.Field` - 'country', + 'state', + rules.Row('country', 'continent'), # Show macro that's included in the templates rules.Container('rule_demo.wrap', rules.Field('notes')), # Bootstrap container with embedded row and columns diff --git a/flask_admin/form/rules.py b/flask_admin/form/rules.py index 50b766c130..3e185be4c3 100644 --- a/flask_admin/form/rules.py +++ b/flask_admin/form/rules.py @@ -360,13 +360,39 @@ def __init__(self, rules, header=None, separator=''): class Row(NestedRule): + """ + Bootstrap grid "row" div with automatic Bootstrap columns + """ def __init__(self, *columns, **kw): - super(Row, self).__init__() + """ + Constructor + + :param columns: + Arguments (args, unlimited number) which each will become Bootstrap columns. + :param kw: + Keyword arguments, which may contain: + "row_classes" + Specify the classes for the Bootstrap row (e.g. "form-row justify-content-center"). + Default "form-row" + "col_classes": + Space-separated classes to use for the Bootstrap columns (e.g. "col-md-6"). + Default "col" + """ + super(Row, self).__init__(rules=columns, separator="") self.row_classes = kw.get("row_classes", "form-row") self.col_classes = kw.get("col_classes", "col") - self.rules = columns def __call__(self, form, form_opts=None, field_args={}): + """ + Render all children when called in the Jinja template. + + :param form: + Form object + :param form_opts: + Form options + :param field_args: + Optional arguments that should be passed to template or the field + """ cols = [] for col in self.rules: if col.visible_fields: