コード例 #1
0
def name_validator(val, field=None):
    # check basic textual rules
    min_length = 2
    if len(val) < min_length:
        raise formalchemy.ValidationError(
            _('Name must be at least %s characters long') % min_length)
    if not name_match.match(val):
        raise formalchemy.ValidationError(
            _('Name must be purely lowercase alphanumeric (ascii) characters and these symbols: -_'
              ))
コード例 #2
0
 def extras_validator(self, val, field=None):
     val_dict = dict(val)
     for key, value in val:
         if value != val_dict[key]:
             raise formalchemy.ValidationError(
                 _('Duplicate key "%s"') % key)
         if value and not key:
             # Note value is allowed to be None - REST way of deleting fields.
             raise formalchemy.ValidationError(
                 _('Extra key-value pair: key is not set for value "%s".') %
                 value)
コード例 #3
0
 def tag_name_validator(self, val, field):
     for tag in val:
         min_length = 2
         if len(tag) < min_length:
             raise formalchemy.ValidationError(
                 _('Tag "%s" length is less than minimum %s') %
                 (tag, min_length))
         if not self.tagname_match.match(tag):
             raise formalchemy.ValidationError(
                 _('Tag "%s" must be alphanumeric characters or symbols: -_.'
                   ) % (tag))
         if self.tagname_uppercase.search(tag):
             raise formalchemy.ValidationError(
                 _('Tag "%s" must not be uppercase' % (tag)))
コード例 #4
0
 def validate(self, value, field=None):
     if not value:
         # if value is required then this is checked by 'required' validator
         return
     if value not in [id_ for label, id_ in self.options] and \
            value != field.model_value:
         raise formalchemy.ValidationError('Value %r is not one of the options.' % id_)
コード例 #5
0
 def validate_re(self, value, field=None):
     if value:
         match = re.match(self._validate_re[0], value)
         if not match:
             raise formalchemy.ValidationError(
                 _('Value does not match required format: %s') %
                 self._validate_re[1])
コード例 #6
0
def harvest_source_type_validator(val, field=None):
    if not val.strip().lower() in [
            'csw server', 'web accessible folder (waf)', 'single document'
    ]:
        raise formalchemy.ValidationError(
            'Unknown Harvest Source Type: %s. Please choose between CSW Server, Web Accessible Folder (WAF), Single Document'
            % val)
コード例 #7
0
def group_name_validator(val, field=None):
    name_validator(val, field)
    # we disable autoflush here since may get used in package preview
    groups = model.Session.query(
        model.Group).autoflush(False).filter_by(name=val)
    for group in groups:
        if group != field.parent.model:
            raise formalchemy.ValidationError(
                _('Group name already exists in database'))
コード例 #8
0
def package_name_validator(val, field=None):
    name_validator(val, field)
    # we disable autoflush here since may get used in package preview
    pkgs = model.Session.query(
        model.Package).autoflush(False).filter_by(name=val)
    for pkg in pkgs:
        if pkg != field.parent.model:
            raise formalchemy.ValidationError(
                _('Package name already exists in database'))
コード例 #9
0
def action_name_validator(val, field=None):
    name_validator(val, field)

    # we disable autoflush here since may get used in dataset preview
    pkgs = model.Session.query(lightbaseDatasetActions).autoflush(
        False).filter_by(action_name=val)
    for pkg in pkgs:
        if pkg != field.parent.model:
            raise formalchemy.ValidationError(
                _('Action name already exists in database'))
コード例 #10
0
def national_statistic_validator(value, field=None):
    if value != 'yes':
        return
    fs = field.parent
    for publisher_field in ('published_by', 'published_via'):
        pub = fs[publisher_field].value
        if pub and 'Office for National Statistics' in pub:
            return
    raise formalchemy.ValidationError(
        "'National Statistic' should only be checked if the package is "
        "'published by' or 'published via' the Office for National Statistics.")
コード例 #11
0
    def tag_name_validator(self, val, field):
        for tag in val:

            # formalchemy deserializes an empty string into None.
            # This happens if the tagstring gets split on commas, and
            # there's an empty string in the resulting list.
            # e.g. "tag1,,tag2" ; "  ,tag1" and "tag1," will all result
            # in an empty tag name.
            if tag is None:
                tag = u''  # let the minimum length validator take care of it.

            min_length = 2
            if len(tag) < min_length:
                raise formalchemy.ValidationError(
                    _('Tag "%s" length is less than minimum %s') %
                    (tag, min_length))
            if not self.tagname_match.match(tag):
                raise formalchemy.ValidationError(
                    _('Tag "%s" must not contain any quotation marks: "') %
                    (tag))
コード例 #12
0
ファイル: field_types.py プロジェクト: changhw01/OpenFoodData
 def form_validator(form_date_str, field=None):
     try:
         DateType.form_to_db(form_date_str)
     except DateConvertError, e:
         raise formalchemy.ValidationError(e)
コード例 #13
0
def harvest_source_url_validator(val, field=None):
    if not val.strip().startswith('http://'):
        raise formalchemy.ValidationError(
            'Harvest source URL is invalid (must start with "http://").')