diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/admin.py | 7 | ||||
-rw-r--r-- | ishtar_common/data_importer.py | 5 | ||||
-rw-r--r-- | ishtar_common/fixtures/initial_importtypes-fr.json | 404 | ||||
-rw-r--r-- | ishtar_common/management/commands/clean_ishtar.py | 35 | ||||
-rw-r--r-- | ishtar_common/models.py | 12 | ||||
-rw-r--r-- | ishtar_common/templates/blocks/inline_formset.html | 2 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/display_item.html | 7 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/formset.html | 2 | ||||
-rw-r--r-- | ishtar_common/templates/welcome.html | 2 | ||||
-rw-r--r-- | ishtar_common/tests.py | 18 | ||||
-rw-r--r-- | ishtar_common/views.py | 9 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 13 |
12 files changed, 360 insertions, 156 deletions
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py index efb452e74..b3e0763b5 100644 --- a/ishtar_common/admin.py +++ b/ishtar_common/admin.py @@ -246,6 +246,13 @@ class IshtarUserAdmin(admin.ModelAdmin): admin.site.register(models.IshtarUser, IshtarUserAdmin) + +class ItemKeyAdmin(admin.ModelAdmin): + list_display = ('content_type', 'key', 'content_object', 'importer') + search_fields = ('key', ) +admin.site.register(models.ItemKey, ItemKeyAdmin) + + basic_models = [models.DocumentTemplate] if settings.COUNTRY == 'fr': basic_models += [models.Arrondissement, models.Canton] diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index b669995e3..49705f0df 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -1311,11 +1311,14 @@ class Importer(object): self.get_field(cls, attribute, data, m2ms, c_c_path, new_created) - # filter uncessary default values create_dict = copy.deepcopy(data) for k in create_dict.keys(): + # filter unnecessary default values if type(create_dict[k]) == dict: create_dict.pop(k) + # File doesn't like deepcopy + if type(create_dict[k]) == File: + create_dict[k] = copy.copy(data[k]) # default values path = tuple(path) diff --git a/ishtar_common/fixtures/initial_importtypes-fr.json b/ishtar_common/fixtures/initial_importtypes-fr.json index 0592ca60f..342367f2b 100644 --- a/ishtar_common/fixtures/initial_importtypes-fr.json +++ b/ishtar_common/fixtures/initial_importtypes-fr.json @@ -7,6 +7,7 @@ "is_template": true, "unicity_keys": "code_patriarche", "users": [ + 2 ], "slug": "operatio", "associated_models": "archaeological_operations.models.Operation", @@ -21,6 +22,7 @@ "is_template": true, "unicity_keys": null, "users": [ + 2 ], "slug": null, "associated_models": "archaeological_operations.models.Operation", @@ -35,6 +37,7 @@ "is_template": true, "unicity_keys": null, "users": [ + 2 ], "slug": null, "associated_models": "archaeological_context_records.models.ContextRecord", @@ -3136,7 +3139,7 @@ "description": "Chronologies associ\u00e9es (plusieurs possibles s\u00e9par\u00e9es par &), exemple : \"Gallo-romain & M\u00e9di\u00e9val\", \"GR&MED\", \"M\u00e9solithique final & M\u00e9so moyen & Epipal\", etc.", "regexp_pre_filter": null, "required": false, - "label": null, + "label": "Periodes", "importer_type": 18 } }, @@ -3421,7 +3424,7 @@ "model": "ishtar_common.importercolumn", "fields": { "col_number": 7, - "description": "R\u00e9f\u00e9rence du point topo, d'ordinaire un entier mais peut \u00eatre autre chose. Champ texte, max. 120 caract\u00e8res. Exemple : \"7220\", \"pt. 72\", etc.\r\n\r\nNON LI\u00c9 POUR L'INSTANT.", + "description": "R\u00e9f\u00e9rence du point topo, d'ordinaire un entier mais peut \u00eatre autre chose. Champ texte, max. 120 caract\u00e8res. Exemple : \"7220\", \"pt. 72\", etc.\r\n", "regexp_pre_filter": null, "required": false, "label": "Ref. point topo", @@ -3505,7 +3508,7 @@ "model": "ishtar_common.importercolumn", "fields": { "col_number": 14, - "description": "Type(s) d'objet(s), s\u00e9par\u00e9s par des \"&\". Exemple : \"tesson & charbon\", \"os & m\u00e9tal\", \"faune\", \"fibule & bague\", \"lame & lamelle\", \"\u00e9clat & nucl\u00e9us\", etc.", + "description": "Type(s) d'objet(s), s\u00e9par\u00e9s par des \"&\". Exemple : \"tesson & charbon\", \"vase\", \"scapula\", \"fibule & bague\", \"lame & lamelle\", \"\u00e9clat & nucl\u00e9us\", etc.", "regexp_pre_filter": null, "required": false, "label": "Type(s) d'objet(s)", @@ -3693,6 +3696,54 @@ } }, { + "pk": 365, + "model": "ishtar_common.importercolumn", + "fields": { + "col_number": 30, + "description": "Coordonn\u00e9e X pour cet objet", + "regexp_pre_filter": null, + "required": false, + "label": "Coordonn\u00e9e X", + "importer_type": 20 + } + }, + { + "pk": 366, + "model": "ishtar_common.importercolumn", + "fields": { + "col_number": 31, + "description": "Coordonn\u00e9e Y pour cet objet", + "regexp_pre_filter": null, + "required": false, + "label": "Coordonn\u00e9e Y", + "importer_type": 20 + } + }, + { + "pk": 367, + "model": "ishtar_common.importercolumn", + "fields": { + "col_number": 32, + "description": "Coordonn\u00e9e Z pour cet objet (altitude NGF ou arbitraire)", + "regexp_pre_filter": null, + "required": false, + "label": "Coordonn\u00e9e Z", + "importer_type": 20 + } + }, + { + "pk": 368, + "model": "ishtar_common.importercolumn", + "fields": { + "col_number": 33, + "description": "Code permettant de qualifi\u00e9 le mode de projection des donnes (SRS /EPSG). Exemple : \"EPSG:2154\" pour le Lambert 93", + "regexp_pre_filter": null, + "required": false, + "label": "Syst\u00e8me de r\u00e9f\u00e9rence spatiale", + "importer_type": 20 + } + }, + { "pk": 46, "model": "ishtar_common.importtarget", "fields": { @@ -4505,6 +4556,20 @@ } }, { + "pk": 38, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "label", + "column": 37, + "formater_type": 3, + "concat_str": null, + "regexp_filter": null, + "concat": false, + "force_new": false + } + }, + { "pk": 305, "model": "ishtar_common.importtarget", "fields": { @@ -4673,20 +4738,6 @@ } }, { - "pk": 335, - "model": "ishtar_common.importtarget", - "fields": { - "comment": "", - "target": "parcel__external_id", - "column": 311, - "formater_type": 28, - "concat_str": "", - "regexp_filter": null, - "concat": false, - "force_new": false - } - }, - { "pk": 338, "model": "ishtar_common.importtarget", "fields": { @@ -4757,20 +4808,6 @@ } }, { - "pk": 350, - "model": "ishtar_common.importtarget", - "fields": { - "comment": "", - "target": "datings__period", - "column": 325, - "formater_type": 6, - "concat_str": "", - "regexp_filter": null, - "concat": false, - "force_new": false - } - }, - { "pk": 353, "model": "ishtar_common.importtarget", "fields": { @@ -4813,20 +4850,6 @@ } }, { - "pk": 362, - "model": "ishtar_common.importtarget", - "fields": { - "comment": "", - "target": "context_record__external_id", - "column": 337, - "formater_type": 28, - "concat_str": "", - "regexp_filter": null, - "concat": false, - "force_new": false - } - }, - { "pk": 365, "model": "ishtar_common.importtarget", "fields": { @@ -4841,20 +4864,6 @@ } }, { - "pk": 368, - "model": "ishtar_common.importtarget", - "fields": { - "comment": "", - "target": "is_isolated", - "column": 344, - "formater_type": 19, - "concat_str": "", - "regexp_filter": null, - "concat": false, - "force_new": false - } - }, - { "pk": 371, "model": "ishtar_common.importtarget", "fields": { @@ -4953,34 +4962,6 @@ } }, { - "pk": 388, - "model": "ishtar_common.importtarget", - "fields": { - "comment": "", - "target": "find__datings__period", - "column": 364, - "formater_type": 6, - "concat_str": "", - "regexp_filter": null, - "concat": false, - "force_new": false - } - }, - { - "pk": 38, - "model": "ishtar_common.importtarget", - "fields": { - "comment": "", - "target": "label", - "column": 37, - "formater_type": 3, - "concat_str": null, - "regexp_filter": null, - "concat": false, - "force_new": false - } - }, - { "pk": 3, "model": "ishtar_common.importtarget", "fields": { @@ -5191,20 +5172,6 @@ } }, { - "pk": 336, - "model": "ishtar_common.importtarget", - "fields": { - "comment": "", - "target": "parcel__external_id", - "column": 312, - "formater_type": 11, - "concat_str": "", - "regexp_filter": null, - "concat": false, - "force_new": false - } - }, - { "pk": 339, "model": "ishtar_common.importtarget", "fields": { @@ -5317,20 +5284,6 @@ } }, { - "pk": 363, - "model": "ishtar_common.importtarget", - "fields": { - "comment": "", - "target": "context_record__external_id", - "column": 338, - "formater_type": 35, - "concat_str": "", - "regexp_filter": null, - "concat": false, - "force_new": false - } - }, - { "pk": 366, "model": "ishtar_common.importtarget", "fields": { @@ -6115,6 +6068,76 @@ } }, { + "pk": 336, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "parcel__external_id", + "column": 312, + "formater_type": 11, + "concat_str": "-", + "regexp_filter": null, + "concat": false, + "force_new": false + } + }, + { + "pk": 335, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "parcel__external_id", + "column": 311, + "formater_type": 28, + "concat_str": "-", + "regexp_filter": null, + "concat": false, + "force_new": false + } + }, + { + "pk": 362, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "context_record__external_id", + "column": 337, + "formater_type": 28, + "concat_str": "-", + "regexp_filter": null, + "concat": false, + "force_new": false + } + }, + { + "pk": 363, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "context_record__external_id", + "column": 338, + "formater_type": 35, + "concat_str": "-", + "regexp_filter": null, + "concat": false, + "force_new": false + } + }, + { + "pk": 388, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "find__datings__period", + "column": 364, + "formater_type": 6, + "concat_str": "", + "regexp_filter": null, + "concat": false, + "force_new": true + } + }, + { "pk": 99, "model": "ishtar_common.importtarget", "fields": { @@ -7445,34 +7468,6 @@ } }, { - "pk": 361, - "model": "ishtar_common.importtarget", - "fields": { - "comment": "", - "target": "context_record__external_id", - "column": 336, - "formater_type": 11, - "concat_str": "", - "regexp_filter": null, - "concat": false, - "force_new": false - } - }, - { - "pk": 364, - "model": "ishtar_common.importtarget", - "fields": { - "comment": "", - "target": "context_record__external_id", - "column": 339, - "formater_type": 3, - "concat_str": "", - "regexp_filter": null, - "concat": false, - "force_new": false - } - }, - { "pk": 367, "model": "ishtar_common.importtarget", "fields": { @@ -7529,6 +7524,20 @@ } }, { + "pk": 364, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "context_record__external_id", + "column": 339, + "formater_type": 3, + "concat_str": "-", + "regexp_filter": null, + "concat": false, + "force_new": false + } + }, + { "pk": 381, "model": "ishtar_common.importtarget", "fields": { @@ -7557,6 +7566,104 @@ } }, { + "pk": 389, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "topographic_localisation", + "column": 343, + "formater_type": 3, + "concat_str": "", + "regexp_filter": null, + "concat": false, + "force_new": false + } + }, + { + "pk": 390, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "x", + "column": 365, + "formater_type": 21, + "concat_str": "", + "regexp_filter": null, + "concat": false, + "force_new": false + } + }, + { + "pk": 391, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "y", + "column": 366, + "formater_type": 21, + "concat_str": "", + "regexp_filter": null, + "concat": false, + "force_new": false + } + }, + { + "pk": 392, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "z", + "column": 367, + "formater_type": 21, + "concat_str": "", + "regexp_filter": null, + "concat": false, + "force_new": false + } + }, + { + "pk": 350, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "datings__period", + "column": 325, + "formater_type": 6, + "concat_str": "", + "regexp_filter": null, + "concat": false, + "force_new": true + } + }, + { + "pk": 393, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "spatial_reference_system", + "column": 368, + "formater_type": 46, + "concat_str": "", + "regexp_filter": null, + "concat": false, + "force_new": false + } + }, + { + "pk": 361, + "model": "ishtar_common.importtarget", + "fields": { + "comment": "", + "target": "context_record__external_id", + "column": 336, + "formater_type": 11, + "concat_str": "-", + "regexp_filter": null, + "concat": false, + "force_new": false + } + }, + { "pk": 25, "model": "ishtar_common.formatertype", "fields": { @@ -7764,6 +7871,15 @@ } }, { + "pk": 46, + "model": "ishtar_common.formatertype", + "fields": { + "formater_type": "TypeFormater", + "many_split": "", + "options": "SpatialReferenceSystem" + } + }, + { "pk": 13, "model": "ishtar_common.formatertype", "fields": { @@ -8449,4 +8565,4 @@ "force_new": false } } -] +]
\ No newline at end of file diff --git a/ishtar_common/management/commands/clean_ishtar.py b/ishtar_common/management/commands/clean_ishtar.py new file mode 100644 index 000000000..d3da40fd8 --- /dev/null +++ b/ishtar_common/management/commands/clean_ishtar.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2017 É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 sys + +from django.core.management.base import BaseCommand + +from archaeological_operations.models import Parcel + + +class Command(BaseCommand): + args = '' + help = 'Clean unused items' + + def handle(self, *args, **options): + for parcel in Parcel.objects.all(): + parcel.skip_history_when_saving = True + parcel.save() + self.stdout.write('Parcel cleaned.\n') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index d58d549c8..d1d58f184 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -959,11 +959,12 @@ def post_delete_record_relation(sender, instance, **kwargs): # no symetric/inverse is defined if not sym_rel_type: return - - dct = {'right_record': instance.left_record, - 'left_record': instance.right_record, + dct = {'right_record_id': instance.left_record_id, + 'left_record_id': instance.right_record_id, 'relation_type': sym_rel_type} - instance.__class__.objects.filter(**dct).delete() + q = instance.__class__.objects.filter(**dct) + if q.count(): + q.delete() class ShortMenuItem(object): @@ -2048,10 +2049,13 @@ TARGET_MODELS = [ _(u"Conservatory state")), ('archaeological_finds.models.PreservationType', _(u"Preservation type")), ('archaeological_finds.models.ObjectType', _(u"Object type")), + ('archaeological_finds.models.IntegrityType', _(u"Integrity type")), + ('archaeological_finds.models.RemarkabilityType', _(u"Remarkability type")), ('archaeological_context_records.models.IdentificationType', _("Identification type")), ('archaeological_context_records.models.RelationType', _(u"Context record relation type")), + ('SpatialReferenceSystem', _(u"Spatial reference system")), ('SupportType', _(u"Support type")), ] diff --git a/ishtar_common/templates/blocks/inline_formset.html b/ishtar_common/templates/blocks/inline_formset.html index 4d4042985..9c1daad28 100644 --- a/ishtar_common/templates/blocks/inline_formset.html +++ b/ishtar_common/templates/blocks/inline_formset.html @@ -1,6 +1,6 @@ {% load i18n %} {% if extra_formset.non_form_errors %}<div class='errors'>{{extra_formset.non_form_errors.as_ul}}</div>{% endif %} - {% if header %}<table class='inline-table' id='{{formset}}'> + {% if header %}<table class='inline-table' id='{{formset.prefix}}'> <caption>{% trans caption %}</caption> <thead> <tr>{% for field in formset.0.visible_fields%} diff --git a/ishtar_common/templates/ishtar/display_item.html b/ishtar_common/templates/ishtar/display_item.html index 87dda6dcf..e00fef05b 100644 --- a/ishtar_common/templates/ishtar/display_item.html +++ b/ishtar_common/templates/ishtar/display_item.html @@ -1,11 +1,10 @@ {% extends "base.html" %} {% load i18n %} -{% load url from future %} {% block content %} -<h2>{{page_name}}</h2> <script type='text/javascript'> -$(function() { - load_window("{% url item_url pk %}"); +$(document).ready( +function(){ + load_window("/show-{{item_type}}/{{pk}}/"); }); </script> {% endblock %} diff --git a/ishtar_common/templates/ishtar/formset.html b/ishtar_common/templates/ishtar/formset.html index c8a92165e..5454ae7e5 100644 --- a/ishtar_common/templates/ishtar/formset.html +++ b/ishtar_common/templates/ishtar/formset.html @@ -5,7 +5,7 @@ <div class='form' id='global-vars'> <form action="." method="post">{% csrf_token %} {% inline_formset ' ' formset %} -<input type="submit" value="{% trans "Validate" %}"/> +<input type="submit" value="{% trans 'Validate' %}"/> </form> </div> {% endblock %} diff --git a/ishtar_common/templates/welcome.html b/ishtar_common/templates/welcome.html index eb9de475e..508f7be02 100644 --- a/ishtar_common/templates/welcome.html +++ b/ishtar_common/templates/welcome.html @@ -8,5 +8,5 @@ <li><a href='https://ishtar-archeo.net' target="_blank">{% trans "Presentation site and blog" %}</a>{% trans ":"%} {% trans "stay tuned with Ishtar news!" %}</li> <li><a href='{% url 'admin:index' %}' target="_blank">{% trans "Admin interface" %}</a>{% trans ":"%} {% trans "for admin only." %}</li> <li><a href="https://forum.ishtar-archeo.net/" target="_blank">{% trans "Forum" %}</a>{% trans ":"%} {% trans "need help? find a new bug? a fantastic feature to propose? Here is the place to go." %}</li> - <li><a href="https://gitlab.com/ishtar/ishtar" target="_blank">{% trans "Source code" %}</a> – <a href="https://tickets.iggdrasil.net/projects/ishtar" target="_blank">{% trans "tickets" %}</a>{% trans ":"%} {% trans "where the magic happens." %}</li> + <li><a href="https://gitlab.com/iggdrasil/ishtar" target="_blank">{% trans "Source code" %}</a> – <a href="https://tickets.iggdrasil.net/projects/ishtar" target="_blank">{% trans "tickets" %}</a>{% trans ":"%} {% trans "where the magic happens." %}</li> </ul> diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index f22e42e38..10584e4f2 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -17,6 +17,7 @@ # See the file COPYING for details. +from StringIO import StringIO from bs4 import BeautifulSoup as Soup from django.conf import settings @@ -25,6 +26,7 @@ from django.contrib.contenttypes.models import ContentType from django.core.cache import cache from django.core.exceptions import ValidationError from django.core.files.base import File as DjangoFile +from django.core.management import call_command from django.core.urlresolvers import reverse from django.template.defaultfilters import slugify from django.test import TestCase @@ -76,6 +78,22 @@ def create_user(): return username, password, user +class CommandsTestCase(TestCase): + def test_clean_ishtar(self): + """ + Clean ishtar db + """ + from archaeological_operations.models import Parcel + p = Parcel.objects.create( + town=models.Town.objects.create(name='test', numero_insee='25000')) + parcel_nb = Parcel.objects.count() + out = StringIO() + call_command('clean_ishtar', stdout=out) + # no operation or file attached - the parcel should have disappear + self.assertEqual(parcel_nb - 1, Parcel.objects.count()) + self.assertEqual(Parcel.objects.filter(pk=p.pk).count(), 0) + + class WizardTestFormData(object): """ Test set to simulate wizard steps diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 42ebdf277..b0817fc59 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1112,6 +1112,15 @@ def get_by_importer(request, slug, data_type='json', full=False, )(request, data_type, full, force_own, **dct) +def display_item(model, name, extra_dct=None): + def func(request, pk, **dct): + dct['item_type'] = name + dct['pk'] = pk + return render_to_response('ishtar/display_item.html', dct, + context_instance=RequestContext(request)) + return func + + def show_item(model, name, extra_dct=None): def func(request, pk, **dct): try: diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 18336cff5..735ad62fd 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -31,6 +31,7 @@ from django.core.files.storage import default_storage from django.core.mail import send_mail from django.db.models.fields.files import FileField from django.db.models.fields.related import ManyToManyField + from django.http import HttpResponseRedirect from django.forms import ValidationError from django.shortcuts import render_to_response, redirect @@ -679,6 +680,18 @@ class Wizard(NamedUrlWizardView): # material_index management for baseitems obj._cached_label_checked = False obj.save() + + # force post_save for old related m2ms (which can have been detached + # from the current object) + for model in old_m2ms: + for item in old_m2ms[model]: + # verify it hasn't been deleted + q = item.__class__.objects.filter(pk=item.pk) + if q.count(): + item = q.all()[0] + item.skip_history_when_saving = True + item.save() + # make the new object a default if self.current_obj_slug: self.request.session[self.current_obj_slug] = unicode(obj.pk) |