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:
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):
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,