Beispiel #1
0
 def to_python(self, value):
     if value is None:
         return value
     if isinstance(value, recurrence.Recurrence):
         return value
     value = super(RecurrenceField, self).to_python(value) or u''
     return recurrence.deserialize(value)
Beispiel #2
0
 def to_python(self, value):
     if value is None:
         return value
     if isinstance(value, recurrence.Recurrence):
         return value
     value = super(RecurrenceField, self).to_python(value) or u''
     return recurrence.deserialize(value)
Beispiel #3
0
 def to_python(self, value):
     print('topython', value)
     traceback.print_stack()
     if value is None or isinstance(value, recurrence.Recurrence):
         return value
     value = super(RecurrenceField, self).to_python(value) or u''
     return recurrence.deserialize(value, self.include_dtstart)
def test_rule_serialization():
    rule = Rule(
        recurrence.WEEKLY
    )

    serialized = recurrence.serialize(rule)
    assert 'RRULE:FREQ=WEEKLY' == serialized
    assert recurrence.deserialize(serialized) == Recurrence(rrules=[rule])
Beispiel #5
0
def test_rule_serialization():
    rule = Rule(
        recurrence.WEEKLY
    )

    serialized = recurrence.serialize(rule)
    assert 'RRULE:FREQ=WEEKLY' == serialized
    assert recurrence.deserialize(serialized) == Recurrence(rrules=[rule])
Beispiel #6
0
    def get_db_prep_value(self, value, connection=None, prepared=False):
        if value is None and self.null == False:
            raise ValueError(
                'Cannot assign None: "%s.%s" does not allow null values.' %
                (self.model._meta.object_name, self.name))

        if isinstance(value, basestring):
            value = recurrence.deserialize(value)
        return recurrence.serialize(value)
Beispiel #7
0
    def get_db_prep_value(self, value, connection=None, prepared=False):
        if value is None and self.null == False:
            raise ValueError(
                'Cannot assign None: "%s.%s" does not allow null values.' % (
                self.model._meta.object_name, self.name))

        if isinstance(value, basestring):
            value = recurrence.deserialize(value)
        return recurrence.serialize(value)
Beispiel #8
0
    def clean(self, value):
        """
        Validates that ``value`` deserialized into a
        `recurrence.base.Recurrence` object falls within the
        parameters specified to the `RecurrenceField` constructor.
        """
        try:
            recurrence_obj = recurrence.deserialize(value)
        except exceptions.DeserializationError as error:
            raise forms.ValidationError(error.args[0])
        except TypeError:
            return None
        if not self.accept_dtstart:
            recurrence_obj.dtstart = None
        if not self.accept_dtend:
            recurrence_obj.dtend = None

        if self.max_rrules is not None:
            if len(recurrence_obj.rrules) > self.max_rrules:
                raise forms.ValidationError(
                    self.error_messages['max_rrules_exceeded'] % {
                        'limit': self.max_rrules
                    }
                )
        if self.max_exrules is not None:
            if len(recurrence_obj.exrules) > self.max_exrules:
                raise forms.ValidationError(
                    self.error_messages['max_exrules_exceeded'] % {
                        'limit': self.max_exrules
                    }
                )
        if self.max_rdates is not None:
            if len(recurrence_obj.rdates) > self.max_rdates:
                raise forms.ValidationError(
                    self.error_messages['max_rdates_exceeded'] % {
                        'limit': self.max_rdates
                    }
                )
        if self.max_exdates is not None:
            if len(recurrence_obj.exdates) > self.max_exdates:
                raise forms.ValidationError(
                    self.error_messages['max_exdates_exceeded'] % {
                        'limit': self.max_exdates
                    }
                )

        for rrule in recurrence_obj.rrules:
            if rrule.freq not in self.frequencies:
                raise forms.ValidationError(
                    self.error_messages['invalid_frequency'])
        for exrule in recurrence_obj.exrules:
            if exrule.freq not in self.frequencies:
                raise forms.ValidationError(
                    self.error_messages['invalid_frequency'])

        return recurrence_obj
Beispiel #9
0
 def clean(self, value):
     """
     Validates that ``value`` deserialized into a
     `recurrence.base.Recurrence` object falls within the
     parameters specified to the `RecurrenceField` constructor.
     """
     try:
         recurrence_obj = recurrence.deserialize(value)
     except exceptions.DeserializationError, error:
         raise forms.ValidationError(error.args[0])
Beispiel #10
0
 def clean(self, value):
     """
     Validates that ``value`` deserialized into a
     `recurrence.base.Recurrence` object falls within the
     parameters specified to the `RecurrenceField` constructor.
     """
     try:
         recurrence_obj = recurrence.deserialize(value)
     except exceptions.DeserializationError, error:
         raise forms.ValidationError(error.args[0])
Beispiel #11
0
    def clean(self, value):
        """
        Validates that ``value`` deserialized into a
        `recurrence.base.Recurrence` object falls within the
        parameters specified to the `RecurrenceField` constructor.
        """
        try:
            recurrence_obj = recurrence.deserialize(value)
        except exceptions.DeserializationError as error:
            raise forms.ValidationError(error.args[0])

        if not self.accept_dtstart:
            recurrence_obj.dtstart = None
        if not self.accept_dtend:
            recurrence_obj.dtend = None

        if self.max_rrules is not None:
            if len(recurrence_obj.rrules) > self.max_rrules:
                raise forms.ValidationError(
                    self.error_messages['max_rrules_exceeded'] % {
                        'limit': self.max_rrules
                    }
                )
        if self.max_exrules is not None:
            if len(recurrence_obj.exrules) > self.max_exrules:
                raise forms.ValidationError(
                    self.error_messages['max_exrules_exceeded'] % {
                        'limit': self.max_exrules
                    }
                )
        if self.max_rdates is not None:
            if len(recurrence_obj.rdates) > self.max_rdates:
                raise forms.ValidationError(
                    self.error_messages['max_rdates_exceeded'] % {
                        'limit': self.max_rdates
                    }
                )
        if self.max_exdates is not None:
            if len(recurrence_obj.exdates) > self.max_exdates:
                raise forms.ValidationError(
                    self.error_messages['max_exdates_exceeded'] % {
                        'limit': self.max_exdates
                    }
                )

        for rrule in recurrence_obj.rrules:
            if rrule.freq not in self.frequencies:
                raise forms.ValidationError(
                    self.error_messages['invalid_frequency'])
        for exrule in recurrence_obj.exrules:
            if exrule.freq not in self.frequencies:
                raise forms.ValidationError(
                    self.error_messages['invalid_frequency'])

        return recurrence_obj
def test_complex_rule_serialization_with_weekday_instance():
    rule = Rule(
        recurrence.WEEKLY,
        interval=17,
        wkst=recurrence.to_weekday(1),
        count=7,
        byday=[recurrence.to_weekday('-1MO'),
               recurrence.to_weekday('TU')],
        bymonth=[1, 3])

    serialized = recurrence.serialize(rule)
    assert ('RRULE:FREQ=WEEKLY;INTERVAL=17;WKST=TU;'
            'COUNT=7;BYDAY=-1MO,TU;BYMONTH=1,3') == serialized
    assert recurrence.deserialize(serialized) == Recurrence(rrules=[rule])
def test_complex_rule_serialization_with_weekday_instance():
    rule = Rule(
        recurrence.WEEKLY,
        interval=17,
        wkst=recurrence.to_weekday(1),
        count=7,
        byday=[
            recurrence.to_weekday('-1MO'),
            recurrence.to_weekday('TU')
        ],
        bymonth=[1, 3]
    )

    serialized = recurrence.serialize(rule)
    assert ('RRULE:FREQ=WEEKLY;INTERVAL=17;WKST=TU;'
            'COUNT=7;BYDAY=-1MO,TU;BYMONTH=1,3') == serialized
    assert recurrence.deserialize(serialized) == Recurrence(rrules=[rule])
def test_bad_wkst():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:WKST=X')
 def set_rule(self, i):
     self.recurrence = deserialize(i)
def test_bad_byday():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:BYDAY=X')
def test_bad_BYMONTH():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:BYMONTH=X')
def test_unknown_key():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:A=X')
def test_bad_BYMONTH():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:BYMONTH=X')
def test_bad_byday():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:BYDAY=X')
Beispiel #21
0
 def get_prep_value(self, value):
     if isinstance(value, basestring):
         value = recurrence.deserialize(value)
     return recurrence.serialize(value)
def test_bad_interval():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:INTERVAL=X')
def test_no_value():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:A=')
def test_no_equal_sign():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:A')
def test_bad_count():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:COUNT=X')
Beispiel #26
0
 def get_db_prep_value(self, value, connection=None, prepared=False):
     if isinstance(value, string_types):
         value = recurrence.deserialize(value)
     return recurrence.serialize(value)
 def get_db_prep_value(self, value, connection=None, prepared=False):
     if isinstance(value, basestring):
         value = recurrence.deserialize(value)
     return recurrence.serialize(value)
def test_no_value():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:A=')
def test_bad_freq():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:FREQ=X')
def test_bad_interval():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:INTERVAL=X')
Beispiel #31
0
 def to_python(self, value):
     if value is None or isinstance(value, recurrence.Recurrence):
         return value
     value = self.strip_time.sub('', value)  # HACKS
     return recurrence.deserialize(value)
def test_bad_wkst():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:WKST=X')
def test_unknown_key():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:A=X')
def test_bad_count():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:COUNT=X')
def test_bad_freq():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:FREQ=X')
def test_no_equal_sign():
    with pytest.raises(DeserializationError):
        recurrence.deserialize('RRULE:A')