wip
authorOlivier Larchevêque <olivier.larcheveque@auf.org>
Thu, 15 Mar 2012 20:16:47 +0000 (16:16 -0400)
committerOlivier Larchevêque <olivier.larcheveque@auf.org>
Thu, 15 Mar 2012 20:16:47 +0000 (16:16 -0400)
project/dae/management/__init__.py [new file with mode: 0644]
project/dae/management/commands/__init__.py [new file with mode: 0644]
project/dae/management/commands/dae.py [new file with mode: 0644]
project/dae/models.py

diff --git a/project/dae/management/__init__.py b/project/dae/management/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/project/dae/management/commands/__init__.py b/project/dae/management/commands/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/project/dae/management/commands/dae.py b/project/dae/management/commands/dae.py
new file mode 100644 (file)
index 0000000..a688b64
--- /dev/null
@@ -0,0 +1,68 @@
+# -*- encoding: utf-8 -*-
+
+from django.core.management.base import BaseCommand
+from project.dae import  models as dae
+
+
+
+class Command(BaseCommand):
+
+    def explore(obj):
+        print obj
+        for f in obj._meta.fields:
+            def t(s):
+                s = "%s" % s
+                try:
+                    s = s.ljust(40)
+                    s = s.replace('\n', '')
+                    s = s[0:28]
+                except Exception, e:
+                    print e
+                    print s
+                    return
+                return s
+            print "%s%s%s" % (t(f.name), t(type(f).__name__), t(getattr(obj, f.name, "")))
+
+    def handle(self, *args, **options):
+
+        if len(args) != 2:
+            self.stdout.write("dae <modele> <id>\n")
+            return
+
+        classname = args[0]
+        klass = getattr(dae, classname, None)
+        self.stdout.write("Le modèle %s n'existe pas dans DAE.\n" % classname)
+
+        id = int(args[1])
+        try:
+            obj = klass.objects.get(id=id)
+        except:
+            self.stdout.write("L'id %s n'existe pas pour le modèle %s dans DAE.\n" % \
+                    (id, classname))
+            return
+
+        def copy_model(src, dst, exclude=[]):
+            keys = [f.name for f in src._meta.fields if f.name not in ['id', ] + exclude]
+            for k in keys:
+                setattr(dst, k, getattr(src, k))
+            return dst
+
+        print obj
+
+        def duplicate(obj, level=0):
+            print "%s%s" % ("|"*level, type(obj))
+            print "%s%s" % ("|"*level, obj)
+            for obj_composition in obj._meta._related_objects_cache:
+                app_label, field_name = obj_composition.name.split(':')
+                if app_label == obj._meta.app_label:
+                    import pdb; pdb.set_trace()
+                    
+                    sub_obj = getattr(obj, field_name)
+                    duplicate(sub_obj, level+1)
+                
+
+        duplicate(obj)
+
+
+
+        
index 31fbc10..680bd98 100644 (file)
@@ -60,7 +60,6 @@ class Poste(PosteWorkflow, rh.Poste_):
         return ImportPoste.objects.filter(dae=self).exists()
 
     def importer(self):
-        from django.db.models import AutoField
         if self.est_importe():
             return ImportPoste.objects.get(dae=self)
         rh_poste = rh.Poste()