本文整理汇总了Python中colander.null方法的典型用法代码示例。如果您正苦于以下问题:Python colander.null方法的具体用法?Python colander.null怎么用?Python colander.null使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类colander
的用法示例。
在下文中一共展示了colander.null方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contact_invariant
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def contact_invariant(self, appstruct):
appstruct_copy = appstruct.copy()
appstruct_copy.pop('surtax')
if 'title' in appstruct_copy:
appstruct_copy.pop('title')
if not any(v != "" and v != colander.null
for v in list(appstruct_copy.values())):
raise colander.Invalid(self,
_('One value must be entered.'))
if 'phone' in appstruct and appstruct['phone'] and \
('surtax' not in appstruct or \
'surtax' in appstruct and not appstruct['surtax']):
raise colander.Invalid(self,
_('Surcharge field must be filled in.'))
示例2: convert_type
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def convert_type(self, schema_node):
converted = {
'type': self.type
}
if schema_node.title:
converted['title'] = schema_node.title
if schema_node.description:
converted['description'] = schema_node.description
if schema_node.default is not colander.null:
converted['default'] = schema_node.default
if 'example' in schema_node.__dict__:
converted['example'] = schema_node.example
return converted
示例3: serialize
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def serialize(self, node, appstruct):
if appstruct is colander.null:
return colander.null
if not isinstance(appstruct, User):
raise colander.Invalid(node, '%r is not a instance of User' % appstruct)
return appstruct.name
示例4: deserialize
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def deserialize(self, node, cstruct):
if cstruct is colander.null:
return colander.null
if not isinstance(cstruct, basestring):
raise colander.Invalid(node, '%r is not a valid username' % cstruct)
user = DBSession.query(User).filter_by(name=cstruct).first()
if not user:
raise colander.Invalid(node, 'User with name %r does not exist' % cstruct)
return user
示例5: prepare_name
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def prepare_name(name):
""" Convert a given value to a name. """
if name is None or name is null:
return ''
return unicode(name).strip()
示例6: deserialize
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def deserialize(self, node, cstruct):
if cstruct is null:
return null
value = self.decode(cstruct)
if value is None:
raise Invalid(node, 'Missing')
return value
示例7: serialize
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def serialize(self, node, appstruct):
if appstruct is colander.null:
return colander.null
impl = colander.Mapping()
if isinstance(appstruct, str):
impl = StringSchema()
return impl.serialize(node, appstruct)
示例8: deserialize
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def deserialize(self, node, cstruct):
if not cstruct:
return colander.null
try:
result = parse_date(cstruct)
except:
raise colander.Invalid(
node,
_(
self.err_template,
mapping={'val': cstruct}
)
)
return result
示例9: serialize
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def serialize(self, node, appstruct):
if appstruct is colander.null:
return colander.null
return appstruct
示例10: contact_invariant
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def contact_invariant(self, appstruct):
can_add_keywords = appstruct.get('can_add_keywords', 'false')
can_add_keywords = False if can_add_keywords == 'false' else True
keywords = appstruct.get('keywords', colander.null)
if not can_add_keywords and keywords is colander.null:
raise colander.Invalid(
self, _('You must enter at least one keyword.'))
示例11: deserialize
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def deserialize(self, field, pstruct):
result = super(FilesWidget, self).deserialize(field, pstruct)
return [f for f in result if f is not null]
示例12: serialize
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def serialize(self, field, cstruct, **kw):
if cstruct is null:
cstruct = ''
elif isinstance(cstruct, dict):
cstruct = cstruct.get('icon_class')+','+cstruct.get('icon')
return super(BootstrapIconInputWidget, self).serialize(
field, cstruct, **kw)
示例13: deserialize
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def deserialize(self, cstruct=colander.null):
return cstruct
示例14: deserialize
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def deserialize(self, node, cstruct):
if cstruct is col.null:
return col.null
cat = M.TroveCategory.query.get(fullpath=cstruct)
if not cat:
cat = M.TroveCategory.query.get(fullname=cstruct)
if not cat:
raise col.Invalid(node,
'"%s" is not a valid trove category.' % cstruct)
if not cat.fullpath.startswith(self.root_type):
raise col.Invalid(node,
'"%s" is not a valid "%s" trove category.' %
(cstruct, self.root_type))
return cat
示例15: start
# 需要导入模块: import colander [as 别名]
# 或者: from colander import null [as 别名]
def start(self, context, request, appstruct, **kw):
data = context.get_data(PersonSchema())
annotations = getattr(context, 'annotations', {}).get(PROCESS_HISTORY_KEY, [])
data.update({'password': appstruct['password']})
data = {key: value for key, value in data.items()
if value is not colander.null}
data.pop('title')
root = getSite()
locale = my_locale_negotiator(request)
data['locale'] = locale
person = Person(**data)
principals = find_service(root, 'principals')
name = person.first_name + ' ' + person.last_name
users = principals['users']
name = name_chooser(users, name=name)
users[name] = person
grant_roles(person, roles=('Member',))
grant_roles(person, (('Owner', person),))
person.state.append('active')
oid = str(get_oid(context))
get_socket().send_pyobj(('stop', 'persistent_' + oid))
organization = context.organization
if organization:
person.setproperty('organization', organization)
root.delfromproperty('preregistrations', context)
person.init_annotations()
person.annotations.setdefault(
PROCESS_HISTORY_KEY, PersistentList()).extend(annotations)
person.reindex()
request.registry.notify(ActivityExecuted(self, [person], person))
root.addtoproperty('news_letter_members', person)
newsletters = root.get_newsletters_automatic_registration()
email = getattr(person, 'email', '')
if newsletters and email:
for newsletter in newsletters:
newsletter.subscribe(
person.first_name, person.last_name, email)
transaction.commit()
if email:
mail_template = root.get_mail_template(
'registration_confiramtion', person.user_locale)
subject = mail_template['subject'].format(
novaideo_title=root.title)
recipientdata = get_user_data(person, 'recipient', request)
message = mail_template['template'].format(
login_url=request.resource_url(root, '@@login'),
novaideo_title=root.title,
**recipientdata)
alert('email', [root.get_site_sender()], [email],
subject=subject, body=message)
return {'person': person}