diff options
Diffstat (limited to 'archaeological_finds/data_importer.py')
-rw-r--r-- | archaeological_finds/data_importer.py | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/archaeological_finds/data_importer.py b/archaeological_finds/data_importer.py new file mode 100644 index 000000000..cfcce7178 --- /dev/null +++ b/archaeological_finds/data_importer.py @@ -0,0 +1,208 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2015 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# See the file COPYING for details. + +import re + +from django.utils.translation import ugettext_lazy as _ + +from ishtar_common.data_importer import * + +from archaeological_finds import models +from archaeological_context_records.models import Period + +class FindsImporterBibracte(Importer): + DESC = u"Exports Bibracte : importeur pour l'onglet mobilier" + OBJECT_CLS = models.BaseFind + DEFAULTS = { + } + LINE_FORMAT = [ + # OA + ImportFormater('context_record__operation__operation_code', + IntegerFormater(),), + # external_id + ImportFormater('external_id', UnicodeFormater(120, notnull=True), + duplicate_fields=['find__external_id']), + # isolé ou non (si non isolé = lot) + ImportFormater('is_isolated', StrToBoolean( + choices={'lot':False, 'objet':True}), required=False), + # ??? + None, + # A voir + None, + # cf type + None, + # Type = sous classe de matériaux = Liste hiérarchique + ImportFormater('find__material_type', TypeFormater(models.MaterialType), + required=False), + # ??? + None, + # lien avec contenant + None, + # = nombre + ImportFormater('find__find_number', IntegerFormater(), required=False), + # poids + ImportFormater('find__weight', FloatFormater(), required=False), + # unité (g par défault) + ImportFormater('find__weight_unit', StrChoiceFormater(models.WEIGHT_UNIT), + required=False), + # lien UE + ImportFormater('context_record__external_id', UnicodeFormater(120),), + # date decouverte + ImportFormater('discovery_date', DateFormater('%Y/%m/%d'), required=False,), + # lien parcelle (unique) + None, + # etat conservation + ImportFormater('find__conservatory_state', + TypeFormater(models.ConservatoryState), required=False), + # preservation_to_consider + ImportFormater('find__preservation_to_consider', + TypeFormater(models.PreservationType), required=False), + # comment + ImportFormater('comment', UnicodeFormater(1000), required=False), + # lien vers plusieurs chrono (voir gestion actuelle chrono) + ImportFormater('find__dating__period', TypeFormater(Period, + many_split="&"), required=False), + # topographic_localisation + ImportFormater('topographic_localisation', UnicodeFormater(120), + required=False), + # special_interest + ImportFormater('special_interest', UnicodeFormater(120), + required=False), + # description + ImportFormater('description', UnicodeFormater(1000), required=False), + # remontage + None + ] + + +class FindAltImporterBibracte(Importer): + DESC = u"Exports Bibracte : importeur pour l'onglet prélèvement" + OBJECT_CLS = models.BaseFind + DEFAULTS = { + } + LINE_FORMAT = [ + # code OA + ImportFormater('context_record__operation__operation_code', + IntegerFormater(),), + # identifiant prelevement + ImportFormater('external_id', UnicodeFormater(120, notnull=True), + duplicate_fields=['find__external_id']), + # nature + ImportFormater('find__material_type', TypeFormater(models.MaterialType), + required=False), + # identifiant UE + ImportFormater('context_record__external_id', UnicodeFormater(120),), + # identifiant materiel + None, + # commentaire + ImportFormater('comment', UnicodeFormater(1000), required=False), + ] + +class ImportTreatmentFormater(ImportFormater): + def post_process(self, obj, context, value, owner=None): + if obj.upstream_treatment.count(): + return + ope_code = context['upstream_treatment']['base_finds']\ + ['context_record']['operation']['operation_code'] + ope_code = int(ope_code) + downstream = models.Find.objects.filter( + external_id=value, + base_finds__context_record__operation__operation_code=ope_code) + if not downstream.count(): + return + downstream = downstream.all()[0] + downstream.upstream_treatment = obj + downstream.save() + upstream = downstream.duplicate(owner) + upstream.downstream_treatment = obj + upstream.save() + return + +class TreatmentImporterBibracte(Importer): + DESC = u"Exports Bibracte : importeur pour l'onglet traitement" + OBJECT_CLS = models.Treatment + DEFAULTS = { + } + LINE_FORMAT = [ + # code OA + ImportFormater( + 'upstream_treatment__base_finds__context_record__operation__operation_code', + UnicodeFormater(120, notnull=True)), + # identifiant + ImportTreatmentFormater('external_id', + UnicodeFormater(120, notnull=True), post_processing=True), + None, + # traitement + ImportFormater('treatment_type', TypeFormater(models.TreatmentType),), + ] + + +""" +class ContextRecordsImporterBibracte(Importer): + DESC = u"Exports Bibracte : importeur pour l'onglet UE" + OBJECT_CLS = models.ContextRecord + DEFAULTS = { + } + LINE_FORMAT = [ + # ID operation + ImportFormater('operation__operation_code', IntegerFormater(), + duplicate_field='parcel__operation__operation_code',), + # ID UE + ImportFormater('external_id', UnicodeFormater(120),), + # Type + ImportFormater('unit', TypeFormater(models.Unit), required=False), + # description + ImportFormater('description', UnicodeFormater(1000), required=False,), + # interprétation + ImportFormater('interpretation', UnicodeFormater(1000), required=False,), + # date ouverture + ImportFormater('opening_date', DateFormater('%Y/%m/%d'), required=False,), + # date fermeture + ImportFormater('closing_date', DateFormater('%Y/%m/%d'), required=False,), + # lien vers parcelle + ImportFormater('parcel__external_id', UnicodeFormater(12), + required=False,), + # lien vers ID sig + None, + # commentaire + ImportFormater('comment', UnicodeFormater(1000), required=False,), + # ???? + None, + # chrono + ImportFormater('dating__period', TypeFormater(models.Period, + many_split="&"), required=False), + ] + +class ContextRecordsRelationImporterBibracte(Importer): + DESC = u"Exports Bibracte : importeur pour l'onglet relations entre UE" + OBJECT_CLS = models.RecordRelations + DEFAULTS = {} + LINE_FORMAT = [ + # code OA + ImportFormater('left_record__operation__operation_code', + IntegerFormater(), + duplicate_field='right_record__operation__operation_code',), + # identifiant UE 1 + ImportFormater('left_record__external_id', UnicodeFormater(120),), + # type relation + ImportFormater('relation_type', TypeFormater(models.RelationType),), + # identifiant UE 2 + ImportFormater('right_record__external_id', UnicodeFormater(120),), + ] +""" |