Beispiel #1
0
class TestState(models.TimeStampedModel):
    """
    Register iospec expansions for a given question.
    """
    class Meta:
        unique_together = [('question', 'hash')]

    question = models.ForeignKey('CodingIoQuestion')
    hash = models.models.CharField(max_length=32)
    uuid = models.UUIDField(default=uuid.uuid4, editable=False)
    pre_tests_source = models.TextField(blank=True)
    post_tests_source = models.TextField(blank=True)
    pre_tests_source_expansion = models.TextField(blank=True)
    post_tests_source_expansion = models.TextField(blank=True)

    @property
    def is_current(self):
        return self.hash == self.question.test_state_hash

    def __str__(self):
        status = 'current' if self.is_current else 'outdated'
        return 'TestState for %s (%s)' % (self.question, status)
Beispiel #2
0
class Choice(models.Orderable):
    question = models.ParentalKey(MultipleChoiceQuestion,
                                  related_name='choices')
    text = models.RichTextField(_('Choice description'))
    uuid = models.UUIDField(default=uuid.uuid4)
    value = models.DecimalField(
        _('Value'), decimal_places=1, max_digits=4,
        validators=[validators.MinValueValidator(0),
                    validators.MaxValueValidator(100)],
        help_text=_(
            'Grade given for users that choose these option (value=0, for an '
            'incorrect choice and value=100 for a correct one).'
        ),
        default=0,
    )

    def __repr__(self):
        return 'Choice(value=%s, ...)' % self.value

    panels = [
        panels.FieldPanel('text'),
        panels.FieldPanel('value'),
    ]