def validate_absolute_length(self, value):
     if self.length and len(value) != self.length:
         raise ValidationError(self.messages['absolute_length'] %
                               self.length)
Exemple #2
0
 def validate_uppercase(self, value):
     if value.upper() != value:
         raise ValidationError("Value must be uppercase!")
 def validate_lotID(self, data, lotID):
     if isinstance(data["__parent__"], Model):
         if not lotID and data["__parent__"].lots:
             raise ValidationError("This field is required.")
         if lotID and lotID not in [lot.id for lot in data["__parent__"].lots if lot]:
             raise ValidationError("lotID should be one of lots")
Exemple #4
0
 def validate_const(self, value):
     if value != self.const:
         raise ValidationError(f"value must be equal \"{self.const}\"")
def validate_cpv_group(items, *args):
    if items and len(set([i.classification.id[:3] for i in items])) != 1:
        raise ValidationError(u"CPV group of items be identical")
 def validate_email(self, data, value):
     if not value and not data.get('telephone'):
         raise ValidationError(u"telephone or email should be present")
 def validate_relatedParty(self, data, value):
     parent = data['__parent__']
     if value and isinstance(parent, Model) and value not in [i.id for i in parent.parties]:
         raise ValidationError(u"relatedParty should be one of parties.")
Exemple #8
0
 def validate_publish(self, data, dt, context):
     if dt > datetime.datetime(2012, 1, 1, 0,
                               0) and not data['can_future']:
         raise ValidationError(future_error_msg)
Exemple #9
0
 def validate_should_raise(self, data, value, context):
     if value:
         raise ValidationError('message')
Exemple #10
0
 def validate_cancellationOf(self, data, cancellationOf):
     if (isinstance(data["__parent__"], Model) and cancellationOf == "lot"
             and not hasattr(data["__parent__"], "lots")):
         raise ValidationError(
             u'Lot cancellation can not be submitted, since "multiple lots" option is not available for this type of tender.'
         )
Exemple #11
0
 def validate_cause(self, data, value):
     required = get_first_revision_date(
         data, default=get_now()) >= QUICK_CAUSE_REQUIRED_FROM
     if required and value is None:
         raise ValidationError(BaseType.MESSAGES["required"])
Exemple #12
0
 def validate_relatedLot(self, data, relatedLot):
     if not relatedLot and data.get("cancellationOf") == "lot":
         raise ValidationError(u"This field is required.")
     if (relatedLot and isinstance(data["__parent__"], Model) and relatedLot
             not in [i.id for i in data["__parent__"].get("lots", [])]):
         raise ValidationError(u"relatedLot should be one of lots")
Exemple #13
0
 def validate_dateSigned(self, data, value):
     if value and value > get_now():
         raise ValidationError(
             u"Contract signature date can't be in the future")
Exemple #14
0
 def validate_relatedLot(self, data, relatedLot):
     if relatedLot and isinstance(data["__parent__"], Model):
         raise ValidationError(u"This option is not available")
    def validate_violationType(self, data, value):
        if data["violationOccurred"] and not value:
            raise ValidationError(u"This field is required.")

        if value and OTHER_VIOLATION not in value:  # drop other type description
            data["otherViolationType"] = None
Exemple #16
0
 def validate_publish(self, data, dt, context):
     if data['should_raise'] is True:
         raise ValidationError(u'')
     return dt
 def validate_otherViolationType(self, data, value):
     if OTHER_VIOLATION in data["violationType"] and not value:
         raise ValidationError(u"This field is required.")
Exemple #18
0
 def validate_call_me(self, data, value, context):
     if data['name'] == u'Brad' and value is True:
         raise ValidationError(
             u'I\'m sorry I never call people who\'s name is Brad')
     return value
 def validate_startDate(self, data, value):
     if value and data.get('endDate') and data.get('endDate') < value:
         raise ValidationError(u"period should begin before its end")
Exemple #20
0
 def validate_call_me(self, data, value, context):
     if data['name'] == u'Joe':
         raise ValidationError(u"Don't try to decept me! You're Joe!")
     return value
Exemple #21
0
 def validate_date(self, data, value):
     if value >= datetime.datetime.now():
         return value
     else:
         raise ValidationError(u'Date and time less than the current')
Exemple #22
0
def test_clean_validation_messages():
    error = ValidationError("A")
    assert error.messages == ["A"]
def validate_items_uniq(items, *args):
    if items:
        ids = [i.id for i in items]
        if [i for i in set(ids) if ids.count(i) > 1]:
            raise ValidationError(u"Item id should be uniq for all items")
Exemple #24
0
def test_clean_validation_messages_list():
    error = ValidationError(["A", "B", "C"])
    assert error.messages, ["A", "B", "C"]
Exemple #25
0
 def validate_id(self, value):
     if not isinstance(value, bson.objectid.ObjectId):
         try:
             value = bson.objectid.ObjectId(unicode(value))
         except Exception, e:
             raise ValidationError('Invalid ObjectId')
Exemple #26
0
def test_builtin_validation_exception():
    with pytest.raises(ValueError):
        raise ValidationError('message')
Exemple #27
0
 def validate_contains_m_chars(self, value):
     if value.count("M") != self.number_of_m_chars:
         raise ValidationError(
             "Value must contain {} 'm' characters".format(
                 self.number_of_m_chars))
Exemple #28
0
 def is_not_future(dt, context=None):
     if dt > now:
         raise ValidationError(future_error_msg)
 def validate_milestones(self, data, value):
     required = get_first_revision_date(data, default=get_now()) > MILESTONES_VALIDATION_FROM
     if required and (value is None or len(value) < 1):
         raise ValidationError("Tender should contain at least one milestone")
 def validate_numeric(self, value):
     if re.compile(r'\D').match(value):
         raise ValidationError(self.messages['digits'])