Exemple #1
0
def _column_order_validator(v):
    if not v:
        return
    column_order = v.split(',')
    if not all(_is_canonical_int(a) and int(a) >= 0 for a in column_order):
        raise ductmodels.ValidationError("each must be a nonnegative integer in canonical form")
    if len(column_order) != len(set(column_order)):
        raise ductmodels.ValidationError("a column index cannot be specified twice")
Exemple #2
0
def _divider_validator(v):
    if not v:
        return
    dividers = v.split(',')
    if not all(_is_canonical_int(a) for a in dividers):
        raise ductmodels.ValidationError("each must be an integer in canonical form")
    dividers = [int(a) for a in dividers]
    for i in xrange(len(dividers) - 1):
        if not dividers[i] < dividers[i + 1]:
            raise ductmodels.ValidationError("dividers must be provided in order, without duplicates")
Exemple #3
0
 def _do_column_validation(v):
     # FlashcardDeck's validator will automatically make sure the columns exist,
     # so we need not worry about that here
     if v:
         prompts = v.split(',')
     else:
         prompts = []
     if len(frozenset(prompts)) != len(prompts):
         raise ductmodels.ValidationError("each must be from a unique column")
     if not all(_is_canonical_int(a) for a in prompts):
         raise ductmodels.ValidationError("each must be an integer in canonical form")
     if not _re_like_interpretation[re_like](len(prompts)):
         raise ductmodels.ValidationError("incorrect number of columns given.  Expecting re-like matching '%s'." % re_like)
Exemple #4
0
    def validate(self, strict=True):
        super(FlashcardDeck, self).validate(strict)

        headings_length = len(self.headings)

        if headings_length == 0:
            raise ductmodels.ValidationError("there are no sides")

        if strict:
            if any(len(card.get().sides) != headings_length for card in self.cards):
                raise ductmodels.ValidationError("each card must have the same number of sides as headers given")

        nonempty_headings = [h.text for h in self.headings if h.text]
        if len(frozenset(nonempty_headings)) != len(nonempty_headings):
            raise ductmodels.ValidationError("all nonempty headings must be unique")

        r = set(range(headings_length))
        for interaction in self.interactions.array:
            if not all(c in r for c in interaction.get().get_columns_referenced()):
                raise ductmodels.ValidationError("all referenced columns must exist in the FlashcardDeck")

        if self.dividers:
            first_divider_index = int(self.dividers.partition(',')[0])
            last_divider_index = int(self.dividers.rpartition(',')[2])
            if first_divider_index < 1 or last_divider_index >= len(self.cards):
                raise ductmodels.ValidationError("divider index out of range")

        if self.column_order:
            highest_column_index = max(int(a) for a in self.column_order.split(','))
            if highest_column_index >= headings_length:
                raise ductmodels.ValidationError("column index out of range")
Exemple #5
0
    def validate(self, strict=True):
        super(Flashcard, self).validate(strict)

        if len(self.sides) == 0:
            raise ductmodels.ValidationError("a flashcard must have at least one side")