Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _makeOne(self, wrapped):
from colander import deferred
return deferred(wrapped)
@deferred
def validator(self, kw: dict) -> callable:
"""Validate the :term:`post_pool` for the object reference."""
object_validator = create_post_pool_validator(self['object'], kw)
badge_assignment_validator = create_unique_badge_assignment_validator(
self['badge'], self['object'], kw)
return All(object_validator, badge_assignment_validator)
@colander.deferred
def parent_validator(node, kw):
request = kw.get('request')
def validator(node, value):
if request.params.get('id') and str(value) == request.params.get('id'):
raise colander.Invalid(
node,
_(u'Can not be parent of self'),
)
return validator
@colander.deferred
def today(node, kw):
return date.today().isoformat()
@colander.deferred
def deferred_tag_it_widget(node, kw):
all_tags = Tag.query.all()
available_tags = [tag.title.encode('utf-8') for tag in all_tags]
widget = TagItWidget(available_tags=available_tags,
missing='')
return widget
@colander.deferred
def username_validator(node, kw):
request = kw.get('request')
def validator(node, value):
user = User.by_username(value)
if (
user
and str(user.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'User with the same username exists'),
)
return colander.All(colander.Length(max=32), validator,)
@colander.deferred
def iso_code_validator(node, kw):
request = kw.get('request')
def validator(node, value):
country = Country.by_iso_code(value)
if (
country
and str(country.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Country with the same iso code exists'),
)
return colander.All(colander.Length(min=2, max=2), validator,)
@colander.deferred
def deferred_date_description(node, kw):
max_date = kw.get('max_date')
if max_date is None:
max_date = datetime.date.today()
return 'Blog post date (no earlier than %s)' % max_date.ctime()
@colander.deferred
def name_validator(node, kw):
request = kw.get('request')
def validator(node, value):
position = (
DBSession.query(Position)
.filter(
Position.name == value,
Position.structure_id == request.params.get('structure_id')
)
.first()
)
if (
position
and (
str(position.id) != request.params.get('id')
@colander.deferred
def date_validator(node, kw):
request = kw.get('request')
def validator(node, value):
if value >= parse_date(request.params.get('date_to')):
raise colander.Invalid(node, _(u"Invalid dates, please check"))
return colander.All(validator)