本文整理汇总了Python中formalchemy.FieldSet.render方法的典型用法代码示例。如果您正苦于以下问题:Python FieldSet.render方法的具体用法?Python FieldSet.render怎么用?Python FieldSet.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类formalchemy.FieldSet
的用法示例。
在下文中一共展示了FieldSet.render方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: readonly_form
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import render [as 别名]
def readonly_form(self, resource):
"""
returns a read-only view of a model
"""
# Exclude stuff we're displaying as subitems
exclude = []
# subitems_source can be a class or a str here
# we're only interested in str, as it's the name
# of an attribute
for (key, ss) in resource.subsections.items():
exclude.append(ss.subitems_source)
fs = FieldSet(resource.model)
include = []
# render models's fields using FA
# TODO: there's a way to set this on the form itself
# rather than on individual fields
for (k, field) in fs.render_fields.items():
if k not in exclude:
include.append(field.readonly())
else:
pass
fs.configure(include=include)
return fs.render()
示例2: edit_page
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import render [as 别名]
def edit_page(request):
"""Edit a given page."""
session = DBSession()
matchdict = request.matchdict
page = session.query(Page).join(User).filter(Page.id == matchdict["page_id"]).order_by(desc(Page.modified_time)).one()
if 'submitted' in request.params:
fs = FieldSet(page, data=request.params)
# TODO
# add validation
# Not sure why this is necessary...shouldn't I just be able to pass the session to FieldSet and have it sync?
page.title = fs.title.value
page.content = fs.content.value
page.modified_time = time.time()
page.location = fs.location.value
session.add(page)
return HTTPFound(location = route_url("view_page", request, page_location = page.location))
elif 'delete' in request.params:
session.delete(page)
return HTTPFound(location = route_url("edit_pages", request))
edit_blog_post_url = route_url("edit_page", request, page_id = page.id)
fs = FieldSet(page)
fs.configure(options=[fs.content.textarea(size=(45, 10))], exclude = [fs["modified_time"], fs["created_time"], fs["user"]])
form = fs.render()
# TODO
# Figure out how to delete using checkboxes
return dict(title = "Edit '%s'" % page.title, save_name = save_name, delete_name = delete_name, form = form)
示例3: edit_blog_post
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import render [as 别名]
def edit_blog_post(request):
session = DBSession()
matchdict = request.matchdict
post = session.query(Post).filter(Post.id == matchdict["post_id"]).one()
if 'submitted' in request.params:
fs = FieldSet(post, data=request.params)
# TODO
# Not sure why this is necessary...shouldn't I just be able to pass the session to FieldSet and have it sync?
post.title = fs.title.value
post.content = fs.content.value
post.modified_time = time.time()
session.add(post)
return HTTPFound(location = route_url("view_blog_post", request, post_id = post.id))
if 'delete' in request.params:
session.delete(post)
return HTTPFound(location = route_url("edit_blog", request))
edit_blog_post_url = route_url("edit_blog_post", request, post_id = post.id)
fs = FieldSet(post)
fs.configure(options=[fs.content.textarea(size=(45, 10))], exclude = [fs["modified_time"], fs["created_time"], fs["user"]])
form = fs.render()
return dict(form = form, title = post.title, edit_blog_post_url = edit_blog_post_url)
示例4: add_form
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import render [as 别名]
def add_form(self, resource, dbsession):
"""
returns an edit form for the model
"""
fs = FieldSet(resource.create_transient_subitem(), session=dbsession)
#
# Make the foreign key fields read-only in the add form
#
# 1. If it's a str, we're inside a subsection filtered by
# our parent
if isinstance(resource.subitems_source, str):
parent_wrapper = resource.parent_model()
parent_instance = parent_wrapper.model
relation_attr = getattr(parent_instance.__class__, resource.subitems_source)
child_attr_name = getattr(relation_attr.property.backref, 'key', None)
if child_attr_name is not None:
fs.render_fields[child_attr_name] = fs.render_fields[child_attr_name].hidden()
return fs.render()
示例5: new_blog_post
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import render [as 别名]
def new_blog_post(request):
session = DBSession()
if 'submitted' in request.params:
post = Post()
fs = FieldSet(Post, data=request.params)
post.title = fs.title.value
post.content = fs.content.value
now = time.time()
post.modified_time = now
post.created_time = now
post.user_id = authenticated_userid(request)
session.add(post)
return HTTPFound(location = route_url("edit_blog", request))
new_blog_post_url = route_url("new_blog_post", request)
fs = FieldSet(Post, session = session)
fs.configure(options=[fs.content.textarea(size=(45, 10))], exclude = [fs["modified_time"], fs["user"], fs["comments"], fs["created_time"]])
form = fs.render()
return dict(title = _("New Fluid Nexus Blog Post"), form = form, new_blog_post_url = new_blog_post_url)
示例6: new_page
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import render [as 别名]
def new_page(request):
session = DBSession()
if 'submitted' in request.params:
page = Page()
fs = FieldSet(Page, data=request.params)
page.title = fs.title.value
page.content = fs.content.value
page.location = fs.location.value.lower()
now = time.time()
page.modified_time = now
page.created_time = now
page.user_id = authenticated_userid(request)
session.add(page)
return HTTPFound(location = route_url("edit_pages", request))
new_page_url = route_url("new_page", request)
fs = FieldSet(Page, session = session)
fs.configure(options=[fs.content.textarea(size=(45, 10))], exclude = [fs["modified_time"], fs["user"], fs["created_time"]])
form = fs.render()
return dict(title = "Create new Fluid Nexus page", save_name = save_name, form = form)
示例7: edit_form
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import render [as 别名]
def edit_form(self, resource):
"""
returns an edit form for the model
"""
fs = FieldSet(resource.model)
return fs.render()
示例8: edit_form
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import render [as 别名]
def edit_form(self, proxy):
"""
returns an edit form for the model
"""
fs = FieldSet(proxy.model)
return fs.render()