summaryrefslogtreecommitdiff
path: root/archaeological_files
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_files')
-rw-r--r--archaeological_files/data_importer.py315
-rw-r--r--archaeological_files/migrations/0018_auto__add_field_file_imported_line__chg_field_file_responsible_town_pl.py304
-rw-r--r--archaeological_files/models.py1
-rw-r--r--archaeological_files/tests.py6
4 files changed, 613 insertions, 13 deletions
diff --git a/archaeological_files/data_importer.py b/archaeological_files/data_importer.py
index b5f63fb67..23e9c6a32 100644
--- a/archaeological_files/data_importer.py
+++ b/archaeological_files/data_importer.py
@@ -17,11 +17,13 @@
# See the file COPYING for details.
-import re, copy
+import copy, datetime, re
import unicodecsv
from django.conf import settings
+from django.db import IntegrityError
from django.template.defaultfilters import slugify
+from django.utils.translation import ugettext_lazy as _
from ishtar_common.data_importer import *
from ishtar_common.models import Town, Person, OrganizationType
@@ -29,7 +31,95 @@ from ishtar_common.unicode_csv import unicode_csv_reader
from archaeological_files import models
+from archaeological_operations.models import Parcel
+from archaeological_operations.utils import parse_parcels
+
RE_FILTER_CEDEX = re.compile("(.*) *(?: *CEDEX|cedex|Cedex|Cédex|cédex *\d*)")
+RE_PERMIT_REFERENCE = re.compile('[A-Za-z]*(.*)')
+
+class StrToBoolean(Formater):
+ def __init__(self, choices={}, cli=False, strict=False):
+ self.dct = copy.copy(choices)
+ self.cli = cli
+ self.strict= strict
+ self.missings = set()
+
+ def prepare(self, value):
+ value = unicode(value).strip()
+ if not self.strict:
+ value = slugify(value)
+ return value
+
+ def check(self, values):
+ msgstr = unicode(_(u"Choice for \"%s\" is not available. "\
+ u"Which one is relevant?\n"))
+ msgstr += u"1. True\n"
+ msgstr += u"2. False\n"
+ msgstr += u"3. Empty\n"
+ for value in values:
+ value = self.prepare(value)
+ if value in self.dct:
+ continue
+ if not self.cli:
+ self.missings.add(value)
+ continue
+ res = None
+ while res not in range(1, 4):
+ sys.stdout.write(msgstr % value)
+ res = raw_input(">>> ")
+ try:
+ res = int(res)
+ except ValueError:
+ pass
+ if res == 1:
+ self.dct[value] = True
+ elif res == 2:
+ self.dct[value] = False
+ else:
+ self.dct[value] = None
+
+ def format(self, value):
+ value = self.prepare(value)
+ if value in self.dct:
+ return self.dct[value]
+
+class ImportClosingFormater(ImportFormater):
+ def post_process(self, obj, context, value, owner=None):
+ value = self.formater.format(value)
+ if not value:
+ return
+ open_date = obj.reception_date or obj.creation_date
+ if not open_date:
+ return
+ obj.end_date = open_date + datetime.timedelta(30)
+ obj.save()
+
+class ImportParcelFormater(ImportFormater):
+ NEED = ['town',]
+ PARCEL_OWNER_KEY = 'associated_file'
+
+ def post_process(self, obj, context, value, owner=None):
+ value = value.strip()
+ base_dct = {self.PARCEL_OWNER_KEY:obj, 'history_modifier':owner}
+ if 'parcels' in context:
+ for key in context['parcels']:
+ if context['parcels'][key]:
+ base_dct[key] = context['parcels'][key]
+ for parcel_dct in parse_parcels(value, owner=owner):
+ parcel_dct.update(base_dct)
+ try:
+ Parcel.objects.get_or_create(**parcel_dct)
+ except IntegrityError:
+ raise ImporterError("Erreur d'import parcelle, contexte : %s" \
+ % unicode(parcel_dct))
+
+class ImportYearFormater(ImportFormater):
+ def post_process(self, obj, context, value, owner=None):
+ value = self.formater.format(value)
+ if not value:
+ return
+ obj.year = value.year
+ obj.save()
class TownFormater(Formater):
def __init__(self, town_full_dct={}, town_dct={}):
@@ -69,15 +159,56 @@ class TownFormater(Formater):
if key in self._town_dct:
return self._town_dct[key]
+class TownINSEEFormater(Formater):
+ def __init__(self):
+ self._town_dct = {}
+
+ def format(self, value, extra=None):
+ value = value.strip()
+ if not value:
+ return None
+ if value in self._town_dct:
+ return self._town_dct[value]
+ q = Town.objects.filter(insee_code=value)
+ if not q.count():
+ return
+ self._town_dct[value] = q.all()[0]
+ return self._town_dct[value]
+
+class SurfaceFormater(Formater):
+ def test(self):
+ assert self.format(u"352 123") == 352123
+ assert self.format(u"456 789 m²") == 456789
+ assert self.format(u"78ha") == 780000
+
+ def format(self, value, extra=None):
+ value = value.strip()
+ if not value:
+ return None
+ factor = 1
+ if value.endswith(u"m2") or value.endswith(u"m²"):
+ value = value[:-2]
+ if value.endswith(u"ha"):
+ value = value[:-2]
+ factor = 10000
+ try:
+ return int(value.replace(' ', '')) * factor
+ except ValueError:
+ raise ImporterError("Erreur import surface : %s" \
+ % unicode(value))
+
#RE_ADD_CD_POSTAL_TOWN = re.compile("(.*)[, ](\d{5}) (.*?) *(?: "\
# "*CEDEX|cedex|Cedex *\d*)*")
-RE_ADD_CD_POSTAL_TOWN = re.compile("(.*)?[, ]+(\d{5})[, ]+(.+)")
+RE_NAME_ADD_CD_POSTAL_TOWN = re.compile("(.*)?[, ]*" + NEW_LINE_BREAK \
+ + "(.*)?[, ]*(\d{2} *\d{3})[, ]*(.+)")
RE_ADD_CD_POSTAL_TOWN = re.compile("(.*)?[, ]*(\d{2} *\d{3})[, ]*(.+)")
RE_CD_POSTAL_FILTER = re.compile("(\d*) (\d*)")
+RE_ORGA = re.compile("([^,]*)")
+
class FileImporterSraPdL(Importer):
LINE_FORMAT = []
OBJECT_CLS = models.File
@@ -89,30 +220,29 @@ class FileImporterSraPdL(Importer):
txt_idx="general_contractor")},
tuple():{
'file_type': models.FileType.objects.get(
- txt_idx='undefined'),}
+ txt_idx='undefined'),
+ },
+ ('in_charge',):{'attached_to':None}, # initialized in __init__
}
def _init_line_format(self):
tf = TownFormater()
tf.town_dct_init()
self.line_format = [
- ImportFormater('responsible_town_planning_service__name',
- UnicodeFormater(300),
- comment=u"Service instructeur - nom",
- required=False),
- ImportFormater(['address', 'postal_code', 'towns'],
+ None, # A, 1
+ ImportFormater(['address', 'postal_code', ['towns', 'parcels__town']], # B, 2
[UnicodeFormater(500, clean=True),
UnicodeFormater(5, re_filter=RE_CD_POSTAL_FILTER),
tf],
regexp=RE_ADD_CD_POSTAL_TOWN,
regexp_formater_args=[[0], [1], [2, 1]], required=False,
comment="Dossier - adresse"),
- ImportFormater('general_contractor__name',
+ ImportFormater('general_contractor__raw_name', # C, 3 TODO - extraire nom_prenom_titre
UnicodeFormater(200),
- comment=u"Aménageur - nom",
+ comment=u"Aménageur - nom brut",
duplicate_field='general_contractor__attached_to__name',
required=False),
- ImportFormater(['general_contractor__attached_to__address',
+ ImportFormater(['general_contractor__attached_to__address', # D, 4
'general_contractor__attached_to__postal_code',
'general_contractor__attached_to__town'],
[UnicodeFormater(500, clean=True),
@@ -122,13 +252,174 @@ class FileImporterSraPdL(Importer):
regexp=RE_ADD_CD_POSTAL_TOWN,
regexp_formater_args=[[0], [1], [2, 1]], required=False,
comment="Aménageur - adresse"),
- ImportFormater("general_contractor__title",
+ ImportFormater("general_contractor__title", # E, 5
StrChoiceFormater(Person.TYPE, cli=True),
+ required=False,
+ comment="Aménageur - titre"),
+ None, # F, 6
+ None, # G, 7
+ None, # H, 8
+ ImportFormater("parcels__year", # I, 9
+ YearNoFuturFormater(),
required=False),
+ ImportParcelFormater('', required=False, post_processing=True), # J, 10
+ None, # K, 11
+ ImportFormater([['towns', 'parcels__town']], # L, 12
+ tf,
+ required=False,
+ comment="Commune (si non définie avant)"),
+ ImportFormater([['towns', 'parcels__town']], # M, 13
+ tf,
+ required=False,
+ comment="Commune (si non définie avant)"),
+ ImportFormater('saisine_type', # N, 14
+ StrChoiceFormater(models.SaisineType.get_types(),
+ model=models.SaisineType, cli=True),
+ required=False,
+ comment="Type de saisine"),
+ None, # O, 15
+ ImportFormater('comment', # P, 16
+ UnicodeFormater(2000),
+ comment=u"Commentaire",
+ concat=True, required=False),
+ None, # Q, 17
+ ImportFormater([
+ 'responsible_town_planning_service__raw_name', # R, 18 service instructeur
+ 'responsible_town_planning_service__attached_to__address',
+ 'responsible_town_planning_service__attached_to__postal_code',
+ 'responsible_town_planning_service__attached_to__town',],
+ [UnicodeFormater(300, clean=True),
+ UnicodeFormater(300, clean=True),
+ UnicodeFormater(5, re_filter=RE_CD_POSTAL_FILTER),
+ TownFormater(town_full_dct=tf._town_full_dct,
+ town_dct=tf._town_dct)],
+ regexp=RE_NAME_ADD_CD_POSTAL_TOWN,
+ regexp_formater_args=[[0], [1], [2], [3, 2]],
+ comment="Aménageur - adresse",
+ required=False),
+ ImportFormater('comment', # S, 19
+ UnicodeFormater(2000),
+ comment=u"Commentaire",
+ concat=True, required=False),
+ ImportYearFormater('reception_date', # T, 20
+ DateFormater(),
+ comment=u"Date de création",
+ required=False,
+ duplicate_field='creation_date'),
+ None, # U, 21
+ None, # V, 22
+ None, # W, 23
+ None, # X, 24
+ None, # Y, 25
+ None, # Z, 26
+ None, # AA, 27
+ None, # AB, 28
+ None, # AC, 29
+ None, # AD, 30
+ None, # AE, 31
+ None, # AF, 32
+ None, # AG, 33
+ None, # AH, 34
+ ImportFormater('creation_date', # AI, 35
+ DateFormater(),
+ force_value=True,
+ comment=u"Date de création",
+ required=False,),
+ None, # AJ, 36
+ ImportFormater('comment', # AK, 37
+ UnicodeFormater(2000),
+ comment=u"Commentaire",
+ concat=True, required=False),
+ None, # AL, 38
+ None, # AM, 39
+ None, # AN, 40
+ None, # AO, 41
+ ImportFormater('comment', # AP, 42
+ UnicodeFormater(2000),
+ comment=u"Commentaire",
+ concat=True, required=False),
+ None, # AQ, 43
+ None, # AR, 44
+ None, # AS, 45
+ None, # AT, 46
+ ImportFormater('comment', # AU, 47
+ UnicodeFormater(2000),
+ comment=u"Commentaire",
+ concat=True, required=False),
+ None, # AV, 48
+ ImportFormater('permit_reference', # AW, 49
+ UnicodeFormater(300, clean=True),
+ regexp=RE_PERMIT_REFERENCE,
+ comment="Réf. du permis de construire",
+ required=False),
+ None, # AX, 50
+ None, # AY, 51
+ None, # AZ, 52
+ None, # BA, 53
+ None, # BB, 54
+ None, # BC, 55
+ None, # BD, 56
+ ImportFormater([['towns', 'parcels__town']], # BE, 57
+ TownINSEEFormater(),
+ required=False,
+ comment="Commune (si non définie avant)"),
+ ImportFormater('comment', # BF, 58
+ UnicodeFormater(2000),
+ comment=u"Commentaire",
+ concat=True, required=False),
+ None, # BG, 59
+ None, # BH, 60
+ None, # BI, 61
+ None, # BJ, 62
+ None, # BK, 63
+ None, # BL, 64
+ None, # BM, 65
+ None, # BN, 66
+ None, # BO, 67
+ None, # BP, 68
+ None, # BQ, 69
+ None, # BR, 70
+ None, # BS, 71
+ ImportFormater(
+ 'responsible_town_planning_service__attached_to__name', # BT, 72 service instructeur
+ UnicodeFormater(300, clean=True),
+ regexp=RE_ORGA,
+ comment="Service instructeur - nom",
+ required=False),
+ None, # BU, 73
+ ImportClosingFormater('', StrToBoolean(cli=True),
+ post_processing=True, required=False), # BV, 74, end date
+ ImportClosingFormater('in_charge__raw_name', # BW, 75 responsable
+ UnicodeFormater(200),
+ comment=u"Responsable - nom brut",
+ required=False),
+ ImportFormater('total_surface', # BX, 76 surface totale
+ SurfaceFormater(),
+ comment=u"Surface totale",
+ required=False),
+ ImportFormater('total_developed_surface', # BY, 77 surface totale aménagée
+ SurfaceFormater(),
+ comment=u"Surface totale aménagée",
+ required=False),
+ None, # BZ, 78
+ None, # CA, 79
+ None, # CB, 80
+ None, # CC, 81
+ None, # CD, 82
+ None, # CE, 83
+ None, # CF, 84
+ ImportFormater('permit_type',
+ StrChoiceFormater(models.PermitType.get_types(),
+ model=models.PermitType, cli=True),
+ required=False,
+ comment="Type de permis"), # CG, 85
+ None, # CH, 85
]
def __init__(self, *args, **kwargs):
super(FileImporterSraPdL, self).__init__(*args, **kwargs)
+ self.DEFAULTS[('in_charge',)]['attached_to'] = \
+ models.Organization.objects.get(name='SRA Pays de la Loire')
self._init_line_format()
if tuple() not in self._defaults:
self._defaults[tuple()] = {}
diff --git a/archaeological_files/migrations/0018_auto__add_field_file_imported_line__chg_field_file_responsible_town_pl.py b/archaeological_files/migrations/0018_auto__add_field_file_imported_line__chg_field_file_responsible_town_pl.py
new file mode 100644
index 000000000..4555145a3
--- /dev/null
+++ b/archaeological_files/migrations/0018_auto__add_field_file_imported_line__chg_field_file_responsible_town_pl.py
@@ -0,0 +1,304 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding field 'File.imported_line'
+ db.add_column('archaeological_files_file', 'imported_line',
+ self.gf('django.db.models.fields.TextField')(null=True, blank=True),
+ keep_default=False)
+
+
+ # Changing field 'File.responsible_town_planning_service'
+ db.alter_column('archaeological_files_file', 'responsible_town_planning_service_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['ishtar_common.Person']))
+
+ # Changing field 'File.general_contractor'
+ db.alter_column('archaeological_files_file', 'general_contractor_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['ishtar_common.Person']))
+
+ # Changing field 'File.in_charge'
+ db.alter_column('archaeological_files_file', 'in_charge_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['ishtar_common.Person']))
+
+ # Changing field 'File.scientist'
+ db.alter_column('archaeological_files_file', 'scientist_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['ishtar_common.Person']))
+
+ # Changing field 'File.organization'
+ db.alter_column('archaeological_files_file', 'organization_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['ishtar_common.Organization']))
+ # Adding field 'HistoricalFile.imported_line'
+ db.add_column('archaeological_files_historicalfile', 'imported_line',
+ self.gf('django.db.models.fields.TextField')(null=True, blank=True),
+ keep_default=False)
+
+
+ def backwards(self, orm):
+ # Deleting field 'File.imported_line'
+ db.delete_column('archaeological_files_file', 'imported_line')
+
+
+ # Changing field 'File.responsible_town_planning_service'
+ db.alter_column('archaeological_files_file', 'responsible_town_planning_service_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['ishtar_common.Person']))
+
+ # Changing field 'File.general_contractor'
+ db.alter_column('archaeological_files_file', 'general_contractor_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['ishtar_common.Person']))
+
+ # Changing field 'File.in_charge'
+ db.alter_column('archaeological_files_file', 'in_charge_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['ishtar_common.Person']))
+
+ # Changing field 'File.scientist'
+ db.alter_column('archaeological_files_file', 'scientist_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['ishtar_common.Person']))
+
+ # Changing field 'File.organization'
+ db.alter_column('archaeological_files_file', 'organization_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['ishtar_common.Organization'], null=True))
+ # Deleting field 'HistoricalFile.imported_line'
+ db.delete_column('archaeological_files_historicalfile', 'imported_line')
+
+
+ models = {
+ 'archaeological_files.file': {
+ 'Meta': {'ordering': "('cached_label',)", 'object_name': 'File'},
+ 'address': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'address_complement': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'cached_label': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True', 'blank': 'True'}),
+ 'cira_advised': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}),
+ 'classified_area': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'creation_date': ('django.db.models.fields.DateField', [], {'default': 'datetime.date.today'}),
+ 'departments': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['ishtar_common.Department']", 'null': 'True', 'blank': 'True'}),
+ 'end_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+ 'file_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archaeological_files.FileType']"}),
+ 'general_contractor': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'general_contractor'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['ishtar_common.Person']"}),
+ 'history_creator': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'to': "orm['auth.User']"}),
+ 'history_modifier': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['auth.User']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'imported_line': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'in_charge': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'file_responsability'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['ishtar_common.Person']"}),
+ 'internal_reference': ('django.db.models.fields.CharField', [], {'max_length': '60', 'null': 'True', 'blank': 'True'}),
+ 'mh_listing': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}),
+ 'mh_register': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'numeric_reference': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'organization': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'files'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['ishtar_common.Organization']"}),
+ 'permit_reference': ('django.db.models.fields.CharField', [], {'max_length': '60', 'null': 'True', 'blank': 'True'}),
+ 'permit_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archaeological_files.PermitType']", 'null': 'True', 'blank': 'True'}),
+ 'postal_code': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
+ 'protected_area': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}),
+ 'reception_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+ 'reference_number': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'related_file': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archaeological_files.File']", 'null': 'True', 'blank': 'True'}),
+ 'requested_operation_type': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'to': "orm['archaeological_operations.OperationType']"}),
+ 'research_comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'responsible_town_planning_service': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'responsible_town_planning_service'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['ishtar_common.Person']"}),
+ 'saisine_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archaeological_files.SaisineType']", 'null': 'True', 'blank': 'True'}),
+ 'scientist': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'scientist'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['ishtar_common.Person']"}),
+ 'total_developed_surface': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'total_surface': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'towns': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'file'", 'symmetrical': 'False', 'to': "orm['ishtar_common.Town']"}),
+ 'year': ('django.db.models.fields.IntegerField', [], {'default': '2014'})
+ },
+ 'archaeological_files.filebydepartment': {
+ 'Meta': {'object_name': 'FileByDepartment', 'db_table': "'file_department'", 'managed': 'False'},
+ 'department': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Department']", 'null': 'True', 'blank': 'True'}),
+ 'file': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archaeological_files.File']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+ },
+ 'archaeological_files.filetype': {
+ 'Meta': {'ordering': "('label',)", 'object_name': 'FileType'},
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'archaeological_files.historicalfile': {
+ 'Meta': {'ordering': "('-history_date', '-history_id')", 'object_name': 'HistoricalFile'},
+ 'address': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'address_complement': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'cached_label': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True', 'blank': 'True'}),
+ 'cira_advised': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}),
+ 'classified_area': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'creation_date': ('django.db.models.fields.DateField', [], {'default': 'datetime.date.today'}),
+ 'end_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+ 'file_type_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'general_contractor_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'history_creator_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'history_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'history_id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'history_modifier_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'history_type': ('django.db.models.fields.CharField', [], {'max_length': '1'}),
+ 'history_user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}),
+ 'id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'blank': 'True'}),
+ 'imported_line': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'in_charge_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'internal_reference': ('django.db.models.fields.CharField', [], {'max_length': '60', 'null': 'True', 'blank': 'True'}),
+ 'mh_listing': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}),
+ 'mh_register': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'numeric_reference': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'organization_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'permit_reference': ('django.db.models.fields.CharField', [], {'max_length': '60', 'null': 'True', 'blank': 'True'}),
+ 'permit_type_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'postal_code': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
+ 'protected_area': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}),
+ 'reception_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+ 'reference_number': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'related_file_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'requested_operation_type_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'research_comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'responsible_town_planning_service_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'saisine_type_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'scientist_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'total_developed_surface': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'total_surface': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'year': ('django.db.models.fields.IntegerField', [], {'default': '2014'})
+ },
+ 'archaeological_files.permittype': {
+ 'Meta': {'ordering': "('label',)", 'object_name': 'PermitType'},
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'archaeological_files.saisinetype': {
+ 'Meta': {'ordering': "('label',)", 'object_name': 'SaisineType'},
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'delay': ('django.db.models.fields.IntegerField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'archaeological_operations.operationtype': {
+ 'Meta': {'ordering': "['-preventive', 'order', 'label']", 'object_name': 'OperationType'},
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'order': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
+ 'preventive': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'ishtar_common.arrondissement': {
+ 'Meta': {'object_name': 'Arrondissement'},
+ 'department': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Department']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '30'})
+ },
+ 'ishtar_common.canton': {
+ 'Meta': {'object_name': 'Canton'},
+ 'arrondissement': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Arrondissement']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '30'})
+ },
+ 'ishtar_common.department': {
+ 'Meta': {'ordering': "['number']", 'object_name': 'Department'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '30'}),
+ 'number': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '3'})
+ },
+ 'ishtar_common.organization': {
+ 'Meta': {'object_name': 'Organization'},
+ 'address': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'address_complement': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'country': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+ 'history_creator': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'to': "orm['auth.User']"}),
+ 'history_modifier': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['auth.User']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'mobile_phone': ('django.db.models.fields.CharField', [], {'max_length': '18', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
+ 'organization_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.OrganizationType']"}),
+ 'phone': ('django.db.models.fields.CharField', [], {'max_length': '18', 'null': 'True', 'blank': 'True'}),
+ 'postal_code': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
+ 'town': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'})
+ },
+ 'ishtar_common.organizationtype': {
+ 'Meta': {'ordering': "('label',)", 'object_name': 'OrganizationType'},
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'ishtar_common.person': {
+ 'Meta': {'object_name': 'Person'},
+ 'address': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'address_complement': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'attached_to': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'members'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['ishtar_common.Organization']"}),
+ 'country': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+ 'history_creator': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'to': "orm['auth.User']"}),
+ 'history_modifier': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['auth.User']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'mobile_phone': ('django.db.models.fields.CharField', [], {'max_length': '18', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+ 'person_types': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['ishtar_common.PersonType']", 'symmetrical': 'False'}),
+ 'phone': ('django.db.models.fields.CharField', [], {'max_length': '18', 'null': 'True', 'blank': 'True'}),
+ 'postal_code': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
+ 'surname': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '2'}),
+ 'town': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'})
+ },
+ 'ishtar_common.persontype': {
+ 'Meta': {'ordering': "('label',)", 'object_name': 'PersonType'},
+ 'available': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['auth.Group']", 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'ishtar_common.town': {
+ 'Meta': {'ordering': "['numero_insee']", 'object_name': 'Town'},
+ 'canton': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Canton']", 'null': 'True', 'blank': 'True'}),
+ 'center': ('django.contrib.gis.db.models.fields.PointField', [], {'srid': '27572', 'null': 'True', 'blank': 'True'}),
+ 'departement': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Department']", 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'numero_insee': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '6'}),
+ 'surface': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
+ }
+ }
+
+ complete_apps = ['archaeological_files'] \ No newline at end of file
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index 0c18af090..a1b42f722 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -147,6 +147,7 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,
# <-- research archaeology
cached_label = models.CharField(_(u"Cached name"), max_length=500,
null=True, blank=True)
+ imported_line = models.TextField(_(u"Imported line"), null=True, blank=True)
history = HistoricalRecords()
class Meta:
diff --git a/archaeological_files/tests.py b/archaeological_files/tests.py
index b43967401..cf73b8726 100644
--- a/archaeological_files/tests.py
+++ b/archaeological_files/tests.py
@@ -27,7 +27,7 @@ from django.contrib.auth.models import User
from django.test import TestCase
from ishtar_common.models import PersonType
-import models
+from archaeological_files import models, data_importer
class FileTest(TestCase):
fixtures = [settings.ROOT_PATH + \
@@ -152,3 +152,7 @@ class FileTest(TestCase):
self.assertTrue(data['records'] == 1)
self.assertEqual(data['rows'][0]['internal_reference'], initial_ref)
+class ImporterTest(TestCase):
+ def testFormaters(self):
+ for formater in [data_importer.SurfaceFormater]:
+ formater().test()