dossier
authorOlivier Larchevêque <olivier.larcheveque@auf.org>
Fri, 23 Mar 2012 16:20:50 +0000 (12:20 -0400)
committerOlivier Larchevêque <olivier.larcheveque@auf.org>
Fri, 23 Mar 2012 16:20:50 +0000 (12:20 -0400)
project/dae/management/commands/dae.py

index 1b7af8e..7a791f7 100644 (file)
@@ -134,7 +134,23 @@ class PosteCopier(SuperCopier):
 
 class DossierCopier(SuperCopier):
 
-    def clean_employe(self, source, copy, field, value):
+    def clean_rh_contrats(self, source, copy, parent, field, value):
+        self.out("\n** SKIP **", 1)
+        return []
+
+    def clean_rh_dossierpieces(self, source, copy, parent, field, value):
+        self.out("\n** SKIP **", 1)
+        return []
+
+    def clean_rh_comparaisons(self, source, copy, parent, field, value):
+        self.out("\n** SKIP **", 1)
+        return []
+    
+    def clean_rh_remunerations(self, source, copy, parent, field, value):
+        self.out("\n** SKIP **", 1)
+        return []
+
+    def clean_employe(self, source, copy, parent, field, value):
         if source.employe.id_rh is not None:
             copy.employe = source.employe.id_rh
         else:
@@ -145,11 +161,42 @@ class DossierCopier(SuperCopier):
             nouvel_employe.save()
             copy.employe = nouvel_employe
 
-    def clean_fichier(self, source, copy, field, value):
-        pass
+    def clean_poste(self, source, copy, parent, field, value):
+        copier = PosteCopier(verbosity=self.verbosity, dry_run=self.dry_run)
+        poste = copier.duplicate(value)
+        copy.poste_id = poste.id
 
-    def clean_poste(self, source, copy, field, value):
-        pass
+    def clean_fichier(self, source, copy, parent, field, value):
+        try:
+            filename = value.path.split('/')[-1]
+        except:
+            setattr(copy, field.name, value)
+            return
+
+        copy.dossier_id = parent.id
+        
+        ct = copy.__class__.__name__.lower()
+        if ct == 'contrat':
+            new_value = rh.contrat_dispatch(copy, filename)
+        elif ct == 'dossierpiece':
+            new_value = rh.dossier_piece_dispatch(copy, filename)
+        else:
+            raise Exception('fichier %s à mapper!' % ct)
+        
+        app, model, id, f = new_value.split('/')
+        app_path = os.path.join(settings.PRIVE_MEDIA_ROOT, app)
+        model_path = os.path.join(settings.PRIVE_MEDIA_ROOT, app, model)
+        id_path = os.path.join(settings.PRIVE_MEDIA_ROOT, app, model, id)
+        if not os.path.exists(app_path):
+            os.mkdir(app_path)
+        if not os.path.exists(model_path):
+            os.mkdir(model_path)
+        if not os.path.exists(id_path):
+            os.mkdir(id_path)
+        src = value.path
+        dst = os.path.join(settings.PRIVE_MEDIA_ROOT, new_value)
+        shutil.copy(src, dst)
+        setattr(copy, field.name, new_value)
 
 
 class Command(BaseCommand):
@@ -177,11 +224,11 @@ class Command(BaseCommand):
 
 
         dry_run = True
-        if len(args) == 3 and args[2] == "run":
+        if len(args) >= 3 and args[2] == "run":
             dry_run = False
 
         verbosity = 0
-        if len(args) == 4:
+        if len(args) >= 4:
             verbosity = int(args[3])
 
         copier = globals()[ "%sCopier" %  classname.title()](verbosity=verbosity,