本文整理汇总了Python中formalchemy.FieldSet类的典型用法代码示例。如果您正苦于以下问题:Python FieldSet类的具体用法?Python FieldSet怎么用?Python FieldSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FieldSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_blog_post
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)
示例2: edit_page
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: readonly_form
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()
示例4: post
def post(self):
fs = FieldSet(self.instance,
data=self.request.POST)
if fs.validate():
fs.sync()
self.session.flush()
return HTTPFound(location=fs.model.getUrl())
示例5: cFilter
def cFilter(context=None):
ffs = FieldSet(Channel,session=__session__)
ffs.permissions.is_collection = True
ffs.configure(include=[ffs.title.label(_(u"Title")),
ffs.permissions.label(_(u"Permissions")),
])
return {'form': ffs}
示例6: _makeFS
def _makeFS(klass, fields):
"""
Erzeugt aus einer Feldliste und einer Pythonklasse ein Fieldset fuer alle Felder.
"""
#print fields
fs = FieldSet(klass, session=__session__)
fs.configure(include=[getattr(fs, fname) for fname in fields])
return fs
示例7: __init__
def __init__(self, user = None):
"""Pre-configuration"""
FieldSet.__init__(self, User)
inc = [
self.username.label(_("* Username you provided when registering")),
self.email.label(_("* E-mail address you provided when registering")).required().validate(email_match),
]
self.configure(include = inc)
示例8: __init__
def __init__(self, *arg, **kwargs):
"""Pre-configuration"""
FieldSet.__init__(self, *arg, **kwargs)
options = [self.ip_address.required().validate(IPAddressValidator),
self.type.required(),
self.location.textarea(size="25x10"),
self.mac_address.validate(MacAddressValidator)
]
self.configure(options=options)
示例9: __init__
def __init__(self):
FieldSet.__init__(self, Session)
self.configure(options=[
self.sched_start.label("Scheduled Start"),
self.sched_end.label("Scheduled End"),
self.approved.label("Approved?"),
self.cancelled.label("Cancelled?"),
self.start.label("Actual Start"),
self.end.label("Actual End"),
self.notes.label("Log").textarea()], exclude=[
self.problem])
示例10: __init__
def __init__(self):
FieldSet.__init__(self, User)
self.add(Field('passwd1'))
self.add(Field('passwd2'))
include = [self.username,
self.passwd1.password().label(u'Password'),
self.passwd2.password().label(u'Confirm').\
validate(validators.passwords_match('passwd1')),
self.email,
self.firstname,
self.lastname,
]
self.configure(include=inc)
示例11: __init__
def __init__(self):
"""Pre-configuration"""
FieldSet.__init__(self, User)
self.add(Field('passwd1'))
self.add(Field('passwd2'))
inc = [self.username,
self.passwd1.password().label(u'Password'),
self.passwd2.password().label(u'Confirm') \
.validate(validators.passwords_match('passwd1')),
self.email,
self.fullname
]
self.configure(include=inc)
示例12: cpFilter
def cpFilter(context=None):
"""
"""
ffs = FieldSet(ChannelPermissions,session=__session__)
ffs.channel.is_collection = True
self = context.getContextObj()
if shasattr(self, "myDPTransferFolder", acquire=True):
c_field = ffs.channel_id.with_renderer(HiddenFieldRenderer)
else:
c_field = ffs.channel.with_null_as(('---', '')).dropdown(multiple=True,size=5)
ffs.configure(include=[c_field,
ffs.doc_type.label(_(u"Doc. type short")),
ffs.perm.label(_("Permission"))])
return {'form': ffs, 'filter' : p_pre_filter}
示例13: blogpost_form_factory
def blogpost_form_factory(model, session=None, request=None):
form = FieldSet(model, session=session, request=request)
exclude = [form.user_id, form.user, form.date]
form.configure(exclude=exclude,
options=[
form.text.textarea(),
form.image.with_renderer(
FileFieldRenderer.new(
storage_path=img_storage_path,
)
)
]
)
return form
示例14: new
def new(self, req, model_name):
model = self.model.get_model_or_404(model_name)
if req.method == 'POST':
item = model()
fs = FieldSet(item, session=session, data=req.form)
if fs.validate():
fs.sync()
item.save()
session.commit()
return self.redirect_to('list', model_name=model_name)
else:
fs = FieldSet(model, session=session)
return self.render_response('_admin/new.jinja',
item=None, model_name=model_name, fs=fs)
示例15: edit
def edit(self, req, model_name, id):
model = self.model.get_model_or_404(model_name)
item = model.query.get(id)
if req.method == 'POST':
fs = FieldSet(item, data=req.form)
if fs.validate():
fs.sync()
item.save()
session.commit()
return self.redirect_to('list', model_name=model_name)
else:
fs = FieldSet(item)
return self.render_response('_admin/new.jinja',
item=item, model_name=model_name, fs=fs, crumbs=[model_name, 'Edit'])