Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
9fea8c1d
Commit
9fea8c1d
authored
Oct 14, 2013
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prettified MongoEngine form rule-based rendering and added Text/HTML rules
parent
0d7d466d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
1 deletion
+35
-1
simple.py
examples/mongoengine/simple.py
+2
-1
rules.py
flask_admin/form/rules.py
+33
-0
No files found.
examples/mongoengine/simple.py
View file @
9fea8c1d
...
@@ -99,7 +99,8 @@ class PostView(ModelView):
...
@@ -99,7 +99,8 @@ class PostView(ModelView):
'inner'
:
{
'inner'
:
{
'form_subdocuments'
:
{
'form_subdocuments'
:
{
None
:
{
None
:
{
'form_rules'
:
(
'name'
,
'tags'
,
rules
.
Header
(
'Comment'
),
'value'
)
# Add <hr> at the end of the form
'form_rules'
:
(
'name'
,
'tag'
,
'value'
,
rules
.
HTML
(
'<hr>'
))
}
}
}
}
}
}
...
...
flask_admin/form/rules.py
View file @
9fea8c1d
...
@@ -93,6 +93,39 @@ class NestedRule(BaseRule):
...
@@ -93,6 +93,39 @@ class NestedRule(BaseRule):
return
Markup
(
self
.
separator
.
join
(
result
))
return
Markup
(
self
.
separator
.
join
(
result
))
class
Text
(
BaseRule
):
"""
Render text (or HTML snippet) from string.
"""
def
__init__
(
self
,
text
,
escape
=
True
):
"""
Constructor.
:param text:
Text snippet to render
:param escape:
Should text be escaped or not. Default is `True`.
"""
super
(
Text
,
self
)
.
__init__
()
self
.
text
=
text
self
.
escape
=
escape
def
__call__
(
self
,
form
,
form_opts
=
None
,
field_args
=
{}):
if
self
.
escape
:
return
self
.
text
return
Markup
(
self
.
text
)
class
HTML
(
Text
):
"""
Shortcut for `Text` rule with `escape` set to `False.
"""
def
__init__
(
self
,
html
):
super
(
HTML
,
self
)
.
__init__
(
html
,
escape
=
False
)
class
Macro
(
BaseRule
):
class
Macro
(
BaseRule
):
"""
"""
Render macro by its name from current Jinja2 context.
Render macro by its name from current Jinja2 context.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment