/usr/share/pyshared/threaded_multihost/fields.py is in python-django-threaded-multihost 1.3.2-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 ForeignKey
from django.contrib.auth.models import User
import threadlocals
class UserField(ForeignKey):
""" UserField
By defaults, foreign key to User; null=True, blank=True
"""
def __init__(self, **kwargs):
kwargs.setdefault('null', True)
kwargs.setdefault('blank', True)
ForeignKey.__init__(self, User, **kwargs)
class CreatorField(UserField):
""" CreatorField
By default, sets editable=False, default=threadlocals.get_current_user
"""
def __init__(self, **kwargs):
kwargs.setdefault('editable', False)
kwargs.setdefault('default', threadlocals.get_current_user)
UserField.__init__(self, **kwargs)
class EditorField(CreatorField):
""" EditorField
By default, sets editable=False, default=threadlocals.get_current_user
Sets value to get_current_user() on each save of the model.
"""
def __init__(self, **kwargs):
super(CreatorField, self).__init__(**kwargs)
def pre_save(self, model_instance, add):
value = threadlocals.get_current_user()
setattr(model_instance, self.name, value)
if value:
value = value.pk
setattr(model_instance, self.attname, value)
return value
|