/usr/lib/python3/dist-packages/recurrence/fields.py is in python3-django-recurrence 1.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | from django.db.models import fields
from django.db.models.fields.subclassing import SubfieldBase
from django.utils.six import string_types, with_metaclass
import recurrence
from recurrence import forms
try:
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], [
"^recurrence\.fields\.RecurrenceField",
])
except ImportError:
pass
class RecurrenceField(with_metaclass(SubfieldBase, fields.Field)):
"""
Field that stores a `recurrence.base.Recurrence` object to the
database.
"""
def get_internal_type(self):
return 'TextField'
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)
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 value_to_string(self, obj):
return self.get_db_prep_value(self._get_val_from_obj(obj))
def formfield(self, **kwargs):
defaults = {
'form_class': forms.RecurrenceField,
'widget': forms.RecurrenceWidget,
}
defaults.update(kwargs)
return super(RecurrenceField, self).formfield(**defaults)
|