summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-03-03 18:39:12 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-03-03 18:39:12 +0100
commit56b8c7a2705a0bf1434b5f917e3ba375646c6b35 (patch)
tree34cdac0680a3c6670e99e6c026f152f046bc507e
parent20898182ec24b990b7311977b684512701a2b892 (diff)
downloadIshtar-56b8c7a2705a0bf1434b5f917e3ba375646c6b35.tar.bz2
Ishtar-56b8c7a2705a0bf1434b5f917e3ba375646c6b35.zip
Operations import: improve operation type import
-rw-r--r--archaeological_operations/import_from_csv.py2
-rw-r--r--archaeological_operations/import_from_dbf.py34
2 files changed, 25 insertions, 11 deletions
diff --git a/archaeological_operations/import_from_csv.py b/archaeological_operations/import_from_csv.py
index b1f8989ce..96ffcf085 100644
--- a/archaeological_operations/import_from_csv.py
+++ b/archaeological_operations/import_from_csv.py
@@ -158,6 +158,8 @@ def parse_title(value):
def parse_person(surname, name, old_ref, owner):
values = {"surname":parse_title(surname),
"name":parse_title(name)}
+ if not values['surname'] and not values['name']:
+ return
q = Person.objects.filter(**values)
if q.count():
return q.all()[0]
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: