def test_next_sequence_custom_with_reset_yearly(self):
     sequence = Sequence.next('test.sequence.4',
                              template='%Y%m%d${code}%NNNNN',
                              params={'code': 'XYZ'},
                              reset_counter=True, reset_counter_strategy='yearly')
     self.assertEqual(sequence, time.strftime('%Y%m%dXYZ00001'))  # TODO
     self.assertEqual(Sequence.objects.get(key='test.sequence.4').__str__(), "test.sequence.4:1")
Exemple #2
0
 def _next_value(self):
     kwargs = {}
     kwargs["key"] = self.key
     kwargs["template"] = self.template
     kwargs["params"] = self.params
     kwargs["reset_counter"] = self.reset_counter
     kwargs["reset_counter_strategy"] = self.reset_counter_strategy
     kwargs["commit"] = True
     return Sequence.next(**kwargs)
    def __init__(self,
                 verbose_name=None,
                 key="default_key",
                 template="%NNNNN",
                 default=None,
                 name=None,
                 pattern=None,
                 expanders=None,
                 params={},
                 auto=True,
                 **kwargs):

        super().__init__(verbose_name, name, default=default, **kwargs)
        self.default_error_messages = {
            'invalid': strings.SEQUENCE_FIELD_PATTERN_MISMATCH
        }
        self._db_type = kwargs.pop('db_type', None)
        self.evaluate_formfield = kwargs.pop('evaluate_formfield', False)

        self.lazy = kwargs.pop('lazy', True)

        self.key = key

        default_pattern = \
            sequence_field_settings.SEQUENCE_FIELD_DEFAULT_PATTERN
        self.pattern = pattern or default_pattern

        default_template = Sequence.get_template_by_key(self.key)
        self.template = template or default_template

        Sequence.create_if_missing(self.key, self.template)

        default_expanders = \
            sequence_field_settings.SEQUENCE_FIELD_DEFAULT_EXPANDERS

        self.params = params or {}

        self.expanders = expanders or default_expanders

        self.auto = auto

        kwargs['help_text'] = kwargs.get(
            'help_text', self.default_error_messages['invalid'])
Exemple #4
0
    def __init__(self, *args, **kwargs):
        self.default_error_messages = {
            'invalid': strings.SEQUENCE_FIELD_PATTERN_MISMATCH
        }
        self._db_type = kwargs.pop('db_type', None)
        self.evaluate_formfield = kwargs.pop('evaluate_formfield', False)

        self.lazy = kwargs.pop('lazy', True)

        try:
            self.key = kwargs.pop('key')
        except KeyError:
            raise SequenceFieldException(strings.SEQUENCE_FIELD_MISSING_KEY)

        default_pattern = \
            sequence_field_settings.SEQUENCE_FIELD_DEFAULT_PATTERN
        self.pattern = kwargs.pop('pattern', default_pattern)

        default_template = Sequence.get_template_by_key(self.key)
        self.template = kwargs.pop('template', default_template)

        Sequence.create_if_missing(self.key, self.template)

        default_expanders = \
            sequence_field_settings.SEQUENCE_FIELD_DEFAULT_EXPANDERS

        self.params = kwargs.pop('params', {})

        self.expanders = kwargs.pop('expanders', default_expanders)

        self.auto = kwargs.pop('auto', False)

        kwargs['help_text'] = kwargs.get(
            'help_text', self.default_error_messages['invalid'])

        super(SequenceField, self).__init__(*args, **kwargs)
 def _next_value(self):
     seq = Sequence.create_if_missing(self.key, self.template)
     return seq.next_value(self.template, self.params, self.expanders)
 def test_next_sequence_default(self):
     sequence = Sequence.next(default_settings.SEQUENCE_FIELD_DEFAULT_NAME)
     self.assertEqual(sequence, '2')  # already created
     sequence = Sequence.next(default_settings.SEQUENCE_FIELD_DEFAULT_NAME)
     self.assertEqual(sequence, '3')
 def test_next_sequence_custom_with_date_param(self):
     sequence = Sequence.next('test.sequence.1',
                              template='%Y%m%d${code}%NNNNN',
                              params={'code': 'XYZ'})
     self.assertEqual(sequence, time.strftime('%Y%m%dXYZ00001'))
     self.assertEqual(Sequence.objects.get(key='test.sequence.1').__str__(), "test.sequence.1:1")
 def test_next_sequence_default_with_date_param(self):
     sequence = Sequence.next("sequence.dateparam",
                              template='${code}%y%m%d%NNN',
                              params={'code': 'S'})
     self.assertEqual(sequence, time.strftime('S%y%m%d001'))
 def test_next_sequence_default_with_param(self):
     sequence = Sequence.next("sequence.param",
                              template='${code}%NNN',
                              params={'code': 'NEXT'})
     self.assertEqual(sequence, 'NEXT001')
 def test_next_sequence_default_with_date(self):
     sequence = Sequence.next("sequence.date",
                              '%y%m%d%NNN')
     self.assertEqual(sequence, time.strftime('%y%m%d001'))