def validate_absolute_length(self, value):
     if self.length and len(value) != self.length:
         raise ValidationError(self.messages['absolute_length'] %
                               self.length)
Exemplo n.º 2
0
 def validate_uppercase(self, value):
     if value.upper() != value:
         raise ValidationError("Value must be uppercase!")
Exemplo n.º 3
0
 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")
Exemplo n.º 4
0
 def validate_const(self, value):
     if value != self.const:
         raise ValidationError(f"value must be equal \"{self.const}\"")
Exemplo n.º 5
0
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")
Exemplo n.º 6
0
 def validate_email(self, data, value):
     if not value and not data.get('telephone'):
         raise ValidationError(u"telephone or email should be present")
Exemplo n.º 7
0
 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.")
Exemplo n.º 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)
Exemplo n.º 9
0
 def validate_should_raise(self, data, value, context):
     if value:
         raise ValidationError('message')
Exemplo n.º 10
0
Arquivo: models.py Projeto: lttga/op2
 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.'
         )
Exemplo n.º 11
0
Arquivo: models.py Projeto: lttga/op2
 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"])
Exemplo n.º 12
0
Arquivo: models.py Projeto: lttga/op2
 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")
Exemplo n.º 13
0
Arquivo: models.py Projeto: lttga/op2
 def validate_dateSigned(self, data, value):
     if value and value > get_now():
         raise ValidationError(
             u"Contract signature date can't be in the future")
Exemplo n.º 14
0
Arquivo: models.py Projeto: lttga/op2
 def validate_relatedLot(self, data, relatedLot):
     if relatedLot and isinstance(data["__parent__"], Model):
         raise ValidationError(u"This option is not available")
Exemplo n.º 15
0
    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
Exemplo n.º 16
0
 def validate_publish(self, data, dt, context):
     if data['should_raise'] is True:
         raise ValidationError(u'')
     return dt
Exemplo n.º 17
0
 def validate_otherViolationType(self, data, value):
     if OTHER_VIOLATION in data["violationType"] and not value:
         raise ValidationError(u"This field is required.")
Exemplo n.º 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
Exemplo n.º 19
0
 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")
Exemplo n.º 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
Exemplo n.º 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')
Exemplo n.º 22
0
def test_clean_validation_messages():
    error = ValidationError("A")
    assert error.messages == ["A"]
Exemplo n.º 23
0
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")
Exemplo n.º 24
0
def test_clean_validation_messages_list():
    error = ValidationError(["A", "B", "C"])
    assert error.messages, ["A", "B", "C"]
Exemplo n.º 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')
Exemplo n.º 26
0
def test_builtin_validation_exception():
    with pytest.raises(ValueError):
        raise ValidationError('message')
Exemplo n.º 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))
Exemplo n.º 28
0
 def is_not_future(dt, context=None):
     if dt > now:
         raise ValidationError(future_error_msg)
Exemplo n.º 29
0
 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'])