import DAE
[auf_rh_dae.git] / project / dae / management / commands / dae.py
index 97d631f..0c2b404 100644 (file)
@@ -1,18 +1,17 @@
 # -*- encoding: utf-8 -*-
 
-import codecs
 from django.core.management.base import BaseCommand
+
 from project.dae import  models as dae
-from project.rh import  models as rh
 
 class Command(BaseCommand):
 
+    
     def handle(self, *args, **options):
 
-        self.stdout = codecs.getwriter('utf8')(self.stdout)
-
-        if len(args) != 2:
-            self.stdout.write("dae <modele> <id>\n")
+        if len(args) < 2:
+            print len(args)
+            self.stdout.write("dae <modele> <id> <run>\n")
             return
 
         classname = args[0]
@@ -29,50 +28,7 @@ class Command(BaseCommand):
             return
 
 
-        def duplicate(obj, level=0, skip=()):
-
-            klass = getattr(rh, obj.__class__.__name__)
-            copy = klass()
-
-            indent = " "*level*4
-            self.stdout.write(u"\n%s [%s] %s" % (indent, str(obj.__class__),
-                obj))
-            
-            self.stdout.write(u"\n*** SKIP: %s ***" % (", ".join(skip)))
-
-            for f in [f for f in obj._meta.fields if f.name not in skip]:
-                value = getattr(obj, f.name)
-                self.stdout.write(u"\n%s * %s: %s" % (indent, f.name, value))
-                setattr(copy, f.name, value)
-
-            for obj_composition in obj._meta._related_objects_cache:
-                app_label, dummy = obj_composition.name.split(':')
-                field_name = obj_composition.field.rel.related_name
-                if field_name in skip:
-                    continue
-                if app_label == obj._meta.app_label:
-                    try:
-                        children = getattr(obj, field_name)
-                        self.stdout.write(u"\n%s + [%s] %s" % (indent,
-                            app_label, field_name))
-                    except:
-                        # no reverse relation
-                        #print "%s %s %s" % (indent, obj_composition, field_name)
-                        continue
-                    for child in children.all():
-                        extra_skip = []
-                        
-                        for f in child._meta.fields:
-                            if getattr(child, f.name) == obj:
-                                extra_skip.append(f.name)
-                        
-                        child_copy = duplicate(child, level+1, skip + extra_skip)
-                        copy.save()
-                        setattr(child_copy, "%s_id" % extra_skip[0], copy.id)
-                        child_copy.save()
-            return copy
-
-        copy = duplicate(obj, skip=['id', 'dae_dossiers', ])
-        print copy.__class__
-        print copy.id
+        copy = obj.importer()
+        self.stdout.write(u"\n[%s] DAE:%s => RH:%s\n" %
+                (obj.__class__.__name__, obj.id, copy.id))