/usr/share/pyshared/djapian/models.py is in python-django-djapian 2.3.1-3.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.utils.encoding import smart_str
from datetime import datetime
from djapian import utils
class ChangeManager(models.Manager):
def create(self, object, action, **kwargs):
ct = ContentType.objects.get_for_model(object.__class__)
pk = smart_str(object.pk)
try:
old_change = self.get(
content_type=ct,
object_id=pk
)
if old_change.action=="add":
if action=="edit":
old_change.save()
return old_change
elif action=="delete":
old_change.delete()
return None
old_change.delete()
except self.model.DoesNotExist:
old_change = self.model(content_type=ct, object_id=pk)
old_change.action = action
old_change.save()
return old_change
class Change(models.Model):
ACTIONS = (
("add", "object added"),
("edit", "object edited"),
("delete", "object deleted"),
)
content_type = models.ForeignKey(ContentType, db_index=True)
object_id = models.CharField(max_length=150)
date = models.DateTimeField(default=datetime.now)
action = models.CharField(max_length=6, choices=ACTIONS)
object = generic.GenericForeignKey()
objects = ChangeManager()
def __unicode__(self):
return u'%s %s#%s on %s' % (
self.action,
self.content_type,
self.object_id,
self.date
)
def save(self):
self.date = datetime.now()
super(Change, self).save()
class Meta:
unique_together = [("content_type", "object_id")]
|