diff options
| author | Étienne Loks <etienne.loks@proxience.com> | 2015-10-24 03:50:36 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@proxience.com> | 2015-10-24 03:51:14 +0200 | 
| commit | ab66e177c787f4982790b20079e0d00d78829058 (patch) | |
| tree | 9e64c8d168e0ed4e73e3725b9c06d072d62233ff /archaeological_files/data_importer.py | |
| parent | 51c50d6f27b70fde3b83b2cdb41ad41f0ac5e972 (diff) | |
| download | Ishtar-ab66e177c787f4982790b20079e0d00d78829058.tar.bz2 Ishtar-ab66e177c787f4982790b20079e0d00d78829058.zip | |
Imports: manage soft import (update) with unicity keys - script to initialize SRA file import
Diffstat (limited to 'archaeological_files/data_importer.py')
| -rw-r--r-- | archaeological_files/data_importer.py | 51 | 
1 files changed, 15 insertions, 36 deletions
| diff --git a/archaeological_files/data_importer.py b/archaeological_files/data_importer.py index f3268d24d..a5fa3c18d 100644 --- a/archaeological_files/data_importer.py +++ b/archaeological_files/data_importer.py @@ -1,6 +1,6 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- -# Copyright (C) 2013-2014  Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2013-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 @@ -58,40 +58,7 @@ class ImportMayorFormater(ImportFormater):  class FilePostProcessing(object): -    # erroneaous date to be easily identified on post-processing -    DEFAULT_YEAR = 1871 -    EXTRA_DEFAULTS = {tuple(): {'year': DEFAULT_YEAR}} -      def post_processing(self, item, data): -        if item.year == self.DEFAULT_YEAR:  # the default year has been applied -            if item.creation_date: -                item.year = item.creation_date.year -            elif item.reception_date: -                item.year = item.reception_date.year -            if item.external_id: -                idx = None -                if '-' in item.external_id: -                    year, y_idx = item.external_id.split('-') -                    if len(year) == 4:  # 2007-XXXX -                        try: -                            item.year = int(year) -                            idx = y_idx -                        except ValueError: -                            pass -                if '.' in item.external_id: -                    year, y_idx = item.external_id.split('.') -                    if len(year) == 4:  # 2011.XXXX -                        try: -                            item.year = int(year) -                            idx = y_idx -                        except ValueError: -                            pass -                if not idx: -                    idx = item.external_id -                try: -                    item.numeric_reference = int(idx) -                except ValueError: -                    pass          if not item.end_date:  # auto-close              open_date = item.reception_date or item.creation_date              item.end_date = open_date + datetime.timedelta(30) @@ -104,6 +71,7 @@ class FileImporterSraPdL(FilePostProcessing, Importer):      SLUG = "sra-pdl-files"      LINE_FORMAT = []      OBJECT_CLS = models.File +    UNICITY_KEYS = ['external_id']      DEFAULTS = {          ('responsible_town_planning_service', 'attached_to'): {              'organization_type': OrganizationType.objects.get( @@ -228,8 +196,7 @@ class FileImporterSraPdL(FilePostProcessing, Importer):              ImportFormater('internal_reference',  # AL, 38                             UnicodeFormater(60),                             comment=u"Autre référence", -                           required=False, -                           duplicate_fields=[['external_id', False]]), +                           required=False),              None,  # AM, 39              None,  # AN, 40              ImportFormater('comment',  # AO, 41 @@ -337,6 +304,18 @@ class FileImporterSraPdL(FilePostProcessing, Importer):                             required=False,                             comment=u"Type de permis"),  # CG, 85              None,  # CH, 85 +            ImportFormater('year',  # CI, 86 +                           IntegerFormater(), +                           comment=u"Année du dossier", +                           required=True), +            ImportFormater('numeric_reference',  # CJ, 87 +                           IntegerFormater(), +                           comment=u"Identifiant numérique", +                           required=True), +            ImportFormater('external_id',  # CK, 88 +                           UnicodeFormater(), +                           comment=u"Identifiant externe", +                           required=True),          ]      def __init__(self, *args, **kwargs): | 
