Example #1
0
class ActorIssue(CSVColumn, typesystem.Schema):
    """
    #A;actor;issue;position;salience;power
    """

    starts_with = "#D"
    actor = typesystem.String()
    issue = typesystem.String()
    position = typesystem.Decimal()
    salience = typesystem.Decimal(minimum=0, maximum=100)
    power = typesystem.Decimal(minimum=0, maximum=100)
    comment = typesystem.Text(allow_blank=True, allow_null=True)

    def __str__(self):
        return str(self.actor) + "-" + str(self.issue)

    def __hash__(self):
        return hash(self.__str__())

    def __eq__(self, other):

        if isinstance(other, PartialIssue):
            return self.__str__() == other.__str__()

        return NotImplemented

    def __lt__(self, other):
        return self.issue.__lt__(other.issue)

    def validate_position(self, issue: PartialIssue):

        issue.validate_interval()

        if not issue.lower <= self.position <= issue.upper:
            raise ValidationError(
                key='position',
                text='exceeds the issue interval of {}-{}'.format(
                    issue.lower, issue.upper))
Example #2
0
 class InventoryItem(typesystem.Schema):
     name = typesystem.String()
     price = typesystem.Decimal(precision="0.01", allow_null=True)
Example #3
0
 def get_validator(self, **kwargs) -> typesystem.Field:
     return typesystem.Decimal(**kwargs)