Skip to content

Commit

Permalink
improved documentation and functionality for legacy class Row() in fo…
Browse files Browse the repository at this point in the history
…rm rules
  • Loading branch information
mccarthysean committed Jun 3, 2022
1 parent b4d40b8 commit a0f6dda
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
5 changes: 4 additions & 1 deletion examples/forms-files-images/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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
Expand Down
30 changes: 28 additions & 2 deletions flask_admin/form/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a0f6dda

Please sign in to comment.