diff options
Diffstat (limited to 'archaeological_operations/import_from_dbf.py')
| -rw-r--r-- | archaeological_operations/import_from_dbf.py | 34 | 
1 files changed, 23 insertions, 11 deletions
| diff --git a/archaeological_operations/import_from_dbf.py b/archaeological_operations/import_from_dbf.py index a3e35c291..5c3d942d7 100644 --- a/archaeological_operations/import_from_dbf.py +++ b/archaeological_operations/import_from_dbf.py @@ -61,10 +61,10 @@ ope_types = {      'OPD':('diag_prev_excavation',             "Opération préventive de diagnostic", True),      'PAN':('analysis_program', -           "Programme d'analyses", False) +           "Programme d'analyses", False),      'PCR':('collective_research_project',             "Projet collectif de recherche", False), -    'PMS':('specialized_equipment_prospection', +    'PMS':('specialized_eqp_prospection',             "Prospection avec matériel spécialisé", False),      'PRD':('diachronic_prospection',             "Prospection diachronique", False), @@ -86,17 +86,21 @@ ope_types = {            "Fouille préventive d'urgence", True),  } +_CACHED_OPE_TYPES = {} +def _prepare_ope_types(): +    for k in ope_types.keys(): +        txt_idx, label, preventive = ope_types[k] +        ot, created = OperationType.objects.get_or_create(txt_idx=txt_idx, +                              defaults={'label':label, 'preventive':preventive}) +        if k not in _CACHED_OPE_TYPES.keys(): +            _CACHED_OPE_TYPES[k] = ot  def parse_patriarche_operationtype(value): -    if value not in ope_types.keys(): +    if value not in _CACHED_OPE_TYPES.keys(): +        print value          return None -    if not ope_types[value]: -        return None -    txt_idx, name, preventive = ope_types[value] -    ot, created = OperationType.objects.get_or_create(txt_idx=txt_idx, -                               defaults={'name':name, 'preventive':preventive}) -    return ot +    return _CACHED_OPE_TYPES[value]  PATRIARCHE_DBF_OPE_COLS = [   (('operation_type',), 'parse_patriarche_operationtype', []), @@ -156,6 +160,9 @@ def import_operations_dbf(values, col_defs=DBF_OPE_COLS, update=False,                             'act_type':ActType.objects.get(                                        txt_idx='excavation_order')}, 'operation'),      } +    # prepare ope types +    _prepare_ope_types() +      ope_default = {'history_modifier':default_person}      current_import = []      new_ops = 0 @@ -246,6 +253,9 @@ def import_operations_dbf(values, col_defs=DBF_OPE_COLS, update=False,          # creation          if not op:              args.update(ope_default) +            for k in args.keys(): +                if not args[k]: +                    args.pop(k)              op = Operation.objects.create(**args)              new_ops += 1              transaction.commit() @@ -253,8 +263,10 @@ def import_operations_dbf(values, col_defs=DBF_OPE_COLS, update=False,          else: # mise à jour              try:                  for k in args: -                    if getattr(op, k): -                        continue +                    if not args[k]: +                        args[k] = None +                    #if getattr(op, k): +                    #    continue                      setattr(op, k, args[k])                  op.save()              except: | 
