Version initiale
authorcyril robert <Cyril Robert crobert@inverse.ca>
Fri, 29 Jan 2010 15:17:27 +0000 (10:17 -0500)
committercyril robert <Cyril Robert crobert@inverse.ca>
Fri, 29 Jan 2010 15:17:27 +0000 (10:17 -0500)
.gitignore [new file with mode: 0644]
django_historique/__init__.py [new file with mode: 0644]
django_historique/models.py [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..0d20b64
--- /dev/null
@@ -0,0 +1 @@
+*.pyc
diff --git a/django_historique/__init__.py b/django_historique/__init__.py
new file mode 100644 (file)
index 0000000..cd237d8
--- /dev/null
@@ -0,0 +1,3 @@
+from models import History
+
+__all__ = ["History"]
diff --git a/django_historique/models.py b/django_historique/models.py
new file mode 100644 (file)
index 0000000..7475e4c
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+from django.db import models
+from django.db.models.base import ModelBase
+from django.db import connection, transaction
+from copy import deepcopy
+import datetime
+
+
+
+def log_instance (i, prefix=""):
+    print prefix, i, i.__class__.__name__
+    for f in i._meta.fields:
+        print prefix, "  ", f.name, f.__class__.__name__
+
+class History (models.Model):
+    history_datetime = models.DateTimeField(default=datetime.datetime.now)
+    history_objectid = models.PositiveIntegerField() # these two are
+    history_revision = models.PositiveIntegerField() # unique_together ?
+    history_comment = models.CharField(max_length=1024, default="")
+
+    def save_log (self, instance):
+        iClass = instance.__class__
+        hClass = self.__class__
+        instance = iClass.objects.get(id = instance.id)
+        self.history_objectid = instance.id
+        self.history_comment = "pre_save history item <%s>" \
+                % (repr(instance))
+        self.history_revision = hClass.objects.filter(history_objectid=instance.id).count()+1
+        for field in instance._meta.fields:
+            if field.__class__.__name__ != 'AutoField':
+                print field.name
+                if getattr(field, 'unique', False):
+                    field._unique = False
+                setattr(self, field.name, getattr(instance, field.name))
+        log_instance (instance, "I")
+        log_instance (self, "S")
+        self.save ()
+
+#    def save (self):
+#        pass
+
+    class Meta:
+        abstract = True
+
+