class ActivityTypeForm(CremeModelForm): default_hour_duration = DurationField(label=_('Duration')) class Meta(CremeModelForm.Meta): model = ActivityType def save(self): # TODO: *args, **kwargs instance = self.instance if not instance.id: super().save(commit=False) generate_string_id_and_save( ActivityType, [instance], 'creme_config-useractivitytype', ) else: super().save() return instance
def test_ok01(self): clean = DurationField().clean self.assertEqual('10:2:0', clean([u'10', u'2', u'0'])) self.assertEqual('10:2:0', clean([10, 2, 0]))
def test_positive01(self): self.assertFieldValidationError(DurationField, 'min_value', DurationField().clean, [u'-1', u'-1', u'-1'], message_args={'limit_value': 0})
def test_invalid01(self): self.assertFieldValidationError(DurationField, 'invalid', DurationField().clean, [u'a', u'b', u'c'])
def test_empty01(self): clean = DurationField().clean self.assertFieldValidationError(DurationField, 'required', clean, None) self.assertFieldValidationError(DurationField, 'required', clean, '') self.assertFieldValidationError(DurationField, 'required', clean, [])