diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2014-07-15 19:22:49 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2014-07-15 19:22:49 +0200 |
commit | 3c4675c7d2f657a5dce8bf55cc8b6a3289197943 (patch) | |
tree | 195f2dba6fccee16cea401e1d440156449476ec3 /archaeological_operations | |
parent | 7c5c1f73ba17425c3737e96bbc600be43608b0a2 (diff) | |
download | Ishtar-3c4675c7d2f657a5dce8bf55cc8b6a3289197943.tar.bz2 Ishtar-3c4675c7d2f657a5dce8bf55cc8b6a3289197943.zip |
Clean act type script (refs #1949)
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/admin.py | 4 | ||||
-rw-r--r-- | archaeological_operations/forms.py | 4 | ||||
-rw-r--r-- | archaeological_operations/management/commands/clean_acttypes.py | 53 | ||||
-rw-r--r-- | archaeological_operations/models.py | 2 |
4 files changed, 59 insertions, 4 deletions
diff --git a/archaeological_operations/admin.py b/archaeological_operations/admin.py index 03531d54c..5395a7b25 100644 --- a/archaeological_operations/admin.py +++ b/archaeological_operations/admin.py @@ -25,9 +25,9 @@ from ishtar_common.admin import HistorizedObjectAdmin, GeneralTypeAdmin import models class AdministrativeActAdmin(HistorizedObjectAdmin): - list_display = ('operation', 'act_type', 'signature_date') + list_display = ('operation', 'associated_file', 'act_type', 'year', 'index') list_filter = ('act_type',) - search_fields = ('operation__name',) + search_fields = ('year', 'index') model = models.AdministrativeAct admin.site.register(models.AdministrativeAct, AdministrativeActAdmin) diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index efbd279ed..0d01c7f0e 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -383,7 +383,9 @@ class OperationFormGeneral(forms.Form): super(OperationFormGeneral, self).__init__(*args, **kwargs) self.fields['operation_type'].choices = models.OperationType.get_types() self.fields['operation_type'].help_text = models.OperationType.get_help() - if kwargs and kwargs['data']: # data POSTED + # data POSTED + if kwargs and kwargs['data'] \ + and 'readonly' in self.fields['operation_code'].widget.attrs: self.fields['operation_code'].widget.attrs.pop('readonly') def clean(self): diff --git a/archaeological_operations/management/commands/clean_acttypes.py b/archaeological_operations/management/commands/clean_acttypes.py new file mode 100644 index 000000000..d3e2deb96 --- /dev/null +++ b/archaeological_operations/management/commands/clean_acttypes.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2014 É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.db import models +from django.core.management.base import BaseCommand, CommandError +from django.core.exceptions import ValidationError + +from archaeological_operations import models + +class Command(BaseCommand): + args = '' + help = 'Clean duplicated act_types' + + def handle(self, *args, **options): + duplicates_lst = [] + known = [] + for act_type in models.ActType.objects.order_by('label').all(): + if act_type.label in known: + if duplicates_lst and \ + duplicates_lst[-1][0].label == act_type.label: + duplicates_lst[-1].append(act_type) + else: + duplicates_lst.append([act_type]) + known.append(act_type.label) + + nb = 0 + for duplicates in duplicates_lst: + ref = duplicates[0] + for duplicate in duplicates[1:]: + nb += 1 + models.AdministrativeAct.objects.filter(act_type=duplicate + ).update(act_type=ref) + duplicate.delete() + print("* %d acttypes merged" % nb) + diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index c6e55f03b..f6ac43239 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -447,7 +447,7 @@ class OperationSource(Source): return self.operation class ActType(GeneralType): - TYPE = (('F', _(u'Archaelogical file')), + TYPE = (('F', _(u'Archaeological file')), ('O', _(u'Operation')), ) intented_to = models.CharField(_(u"Intended to"), max_length=1, |