diff options
| author | Étienne Loks <etienne.loks@peacefrogs.net> | 2014-03-02 19:12:07 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2014-03-02 19:12:07 +0100 | 
| commit | af42287a7a113da28f1f9aab54cfc2e96c9a6d90 (patch) | |
| tree | e2ef8db4d09dddaf2d6e7500575a1ee1fa87d2e1 | |
| parent | 9bafeee09b680bc599bfb1664ead9b69a5fd451e (diff) | |
| download | Ishtar-af42287a7a113da28f1f9aab54cfc2e96c9a6d90.tar.bz2 Ishtar-af42287a7a113da28f1f9aab54cfc2e96c9a6d90.zip  | |
Specific form for research archaeology (refs #1682)
| -rw-r--r-- | archaeological_files/forms.py | 55 | ||||
| -rw-r--r-- | archaeological_files/migrations/0014_auto__add_field_file_requested_operation_type__add_field_file_organiza.py | 405 | ||||
| -rw-r--r-- | archaeological_files/models.py | 27 | ||||
| -rw-r--r-- | archaeological_files/templates/ishtar/sheet_file.html | 17 | ||||
| -rw-r--r-- | archaeological_files/views.py | 29 | ||||
| -rw-r--r-- | archaeological_operations/ishtar_menu.py | 7 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 37 | ||||
| -rw-r--r-- | archaeological_operations/wizards.py | 7 | ||||
| -rw-r--r-- | ishtar_common/models.py | 2 | ||||
| -rw-r--r-- | ishtar_common/urls.py | 4 | ||||
| -rw-r--r-- | ishtar_common/views.py | 17 | 
11 files changed, 569 insertions, 38 deletions
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py index 87f86d0d0..cf775bf08 100644 --- a/archaeological_files/forms.py +++ b/archaeological_files/forms.py @@ -1,6 +1,6 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- -# Copyright (C) 2010-2013  Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2010-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 @@ -33,8 +33,9 @@ from django.utils.translation import ugettext_lazy as _  from django.utils.safestring import mark_safe  from ishtar_common.models import Person, PersonType, Town, Organization, \ -                         OrganizationType, valid_id, is_unique -from archaeological_operations.models import ActType, AdministrativeAct +                         OrganizationType, valid_id, is_unique, Department +from archaeological_operations.models import ActType, AdministrativeAct, \ +                                             OperationType  import models  from ishtar_common.forms import FinalForm, FormSet, ClosingDateFormSelection, \      formset_factory, get_now, reverse_lazy, TableSelect @@ -205,6 +206,54 @@ class FileFormPreventive(forms.Form):                                                                default='NP')          self.fields['permit_type'].help_text = models.PermitType.get_help() +class FileFormResearch(forms.Form): +    form_label = _("Research informations") +    base_model = 'department' +    associated_models = {'scientist':Person, +                         'requested_operation_type':OperationType, +                         'organization':Organization, +                         'department':Department} +    department = widgets.MultipleAutocompleteField( +                                model=Department, +                                label=_("Departments"), +                                required=False) +    scientist = forms.IntegerField( +        widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person', +          args=["_".join( +         [unicode(PersonType.objects.get(txt_idx='head_scientist').pk), +          unicode(PersonType.objects.get(txt_idx='sra_agent').pk)])]), +        associated_model=Person), label=_(u"Scientist in charge")) +    requested_operation_type = forms.ChoiceField( +                    label=_(u"Requested operation type"), +                    choices=[]) +    organization = forms.IntegerField(label=_(u"Lead organization"), +            widget=widgets.JQueryAutoComplete( +                reverse_lazy('autocomplete-organization'), +                associated_model=Organization), +            validators=[valid_id(Organization)], required=False) +    if settings.COUNTRY == 'fr': +        cira_advised = forms.NullBooleanField(label=u"Passage en CIRA", +                                              required=False) +    research_comment = forms.CharField(label=_(u"Comment"), +                        widget=forms.Textarea, required=False) +    if settings.COUNTRY == 'fr': +        mh_register = forms.NullBooleanField( +                            label=u"Sur Monument Historique classé", +                            required=False) +        mh_listing = forms.NullBooleanField( +                            label=u"Sur Monument Historique inscrit", +                            required=False) +    classified_area = forms.NullBooleanField(label=_(u"Classified area"), +                                             required=False) +    protected_area = forms.NullBooleanField(label=_(u"Protected area"), +                                            required=False) +    def __init__(self, *args, **kwargs): +        super(FileFormResearch, self).__init__(*args, **kwargs) +        self.fields['requested_operation_type'].choices = \ +                    OperationType.get_types(dct={"preventive":False}) +        self.fields['requested_operation_type'].help_text = \ +                    OperationType.get_help() +  class FinalFileClosingForm(FinalForm):      confirm_msg = " "      confirm_end_msg = _(u"Would you like to close this archaeological file?") diff --git a/archaeological_files/migrations/0014_auto__add_field_file_requested_operation_type__add_field_file_organiza.py b/archaeological_files/migrations/0014_auto__add_field_file_requested_operation_type__add_field_file_organiza.py new file mode 100644 index 000000000..6855d8198 --- /dev/null +++ b/archaeological_files/migrations/0014_auto__add_field_file_requested_operation_type__add_field_file_organiza.py @@ -0,0 +1,405 @@ +# -*- 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.requested_operation_type' +        db.add_column('archaeological_files_file', 'requested_operation_type', +                      self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='+', null=True, to=orm['archaeological_operations.OperationType']), +                      keep_default=False) + +        # Adding field 'File.organization' +        db.add_column('archaeological_files_file', 'organization', +                      self.gf('django.db.models.fields.related.ForeignKey')(to=orm['ishtar_common.Organization'], null=True, blank=True), +                      keep_default=False) + +        # Adding field 'File.scientist' +        db.add_column('archaeological_files_file', 'scientist', +                      self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='+', null=True, to=orm['ishtar_common.Person']), +                      keep_default=False) + +        # Adding field 'File.research_comment' +        db.add_column('archaeological_files_file', 'research_comment', +                      self.gf('django.db.models.fields.TextField')(null=True, blank=True), +                      keep_default=False) + +        # Adding field 'File.classified_area' +        db.add_column('archaeological_files_file', 'classified_area', +                      self.gf('django.db.models.fields.NullBooleanField')(null=True, blank=True), +                      keep_default=False) + +        # Adding field 'File.protected_area' +        db.add_column('archaeological_files_file', 'protected_area', +                      self.gf('django.db.models.fields.NullBooleanField')(null=True, blank=True), +                      keep_default=False) + +        # Adding field 'File.cira_advised' +        db.add_column('archaeological_files_file', 'cira_advised', +                      self.gf('django.db.models.fields.NullBooleanField')(null=True, blank=True), +                      keep_default=False) + +        # Adding field 'File.mh_register' +        db.add_column('archaeological_files_file', 'mh_register', +                      self.gf('django.db.models.fields.NullBooleanField')(null=True, blank=True), +                      keep_default=False) + +        # Adding field 'File.mh_listing' +        db.add_column('archaeological_files_file', 'mh_listing', +                      self.gf('django.db.models.fields.NullBooleanField')(null=True, blank=True), +                      keep_default=False) + +        # Adding M2M table for field departments on 'File' +        db.create_table('archaeological_files_file_departments', ( +            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), +            ('file', models.ForeignKey(orm['archaeological_files.file'], null=False)), +            ('department', models.ForeignKey(orm['ishtar_common.department'], null=False)) +        )) +        db.create_unique('archaeological_files_file_departments', ['file_id', 'department_id']) + +        # Adding field 'HistoricalFile.requested_operation_type_id' +        db.add_column('archaeological_files_historicalfile', 'requested_operation_type_id', +                      self.gf('django.db.models.fields.IntegerField')(db_index=True, null=True, blank=True), +                      keep_default=False) + +        # Adding field 'HistoricalFile.organization_id' +        db.add_column('archaeological_files_historicalfile', 'organization_id', +                      self.gf('django.db.models.fields.IntegerField')(db_index=True, null=True, blank=True), +                      keep_default=False) + +        # Adding field 'HistoricalFile.scientist_id' +        db.add_column('archaeological_files_historicalfile', 'scientist_id', +                      self.gf('django.db.models.fields.IntegerField')(db_index=True, null=True, blank=True), +                      keep_default=False) + +        # Adding field 'HistoricalFile.research_comment' +        db.add_column('archaeological_files_historicalfile', 'research_comment', +                      self.gf('django.db.models.fields.TextField')(null=True, blank=True), +                      keep_default=False) + +        # Adding field 'HistoricalFile.classified_area' +        db.add_column('archaeological_files_historicalfile', 'classified_area', +                      self.gf('django.db.models.fields.NullBooleanField')(null=True, blank=True), +                      keep_default=False) + +        # Adding field 'HistoricalFile.protected_area' +        db.add_column('archaeological_files_historicalfile', 'protected_area', +                      self.gf('django.db.models.fields.NullBooleanField')(null=True, blank=True), +                      keep_default=False) + +        # Adding field 'HistoricalFile.cira_advised' +        db.add_column('archaeological_files_historicalfile', 'cira_advised', +                      self.gf('django.db.models.fields.NullBooleanField')(null=True, blank=True), +                      keep_default=False) + +        # Adding field 'HistoricalFile.mh_register' +        db.add_column('archaeological_files_historicalfile', 'mh_register', +                      self.gf('django.db.models.fields.NullBooleanField')(null=True, blank=True), +                      keep_default=False) + +        # Adding field 'HistoricalFile.mh_listing' +        db.add_column('archaeological_files_historicalfile', 'mh_listing', +                      self.gf('django.db.models.fields.NullBooleanField')(null=True, blank=True), +                      keep_default=False) + + +    def backwards(self, orm): +        # Deleting field 'File.requested_operation_type' +        db.delete_column('archaeological_files_file', 'requested_operation_type_id') + +        # Deleting field 'File.organization' +        db.delete_column('archaeological_files_file', 'organization_id') + +        # Deleting field 'File.scientist' +        db.delete_column('archaeological_files_file', 'scientist_id') + +        # Deleting field 'File.research_comment' +        db.delete_column('archaeological_files_file', 'research_comment') + +        # Deleting field 'File.classified_area' +        db.delete_column('archaeological_files_file', 'classified_area') + +        # Deleting field 'File.protected_area' +        db.delete_column('archaeological_files_file', 'protected_area') + +        # Deleting field 'File.cira_advised' +        db.delete_column('archaeological_files_file', 'cira_advised') + +        # Deleting field 'File.mh_register' +        db.delete_column('archaeological_files_file', 'mh_register') + +        # Deleting field 'File.mh_listing' +        db.delete_column('archaeological_files_file', 'mh_listing') + +        # Removing M2M table for field departments on 'File' +        db.delete_table('archaeological_files_file_departments') + +        # Deleting field 'HistoricalFile.requested_operation_type_id' +        db.delete_column('archaeological_files_historicalfile', 'requested_operation_type_id') + +        # Deleting field 'HistoricalFile.organization_id' +        db.delete_column('archaeological_files_historicalfile', 'organization_id') + +        # Deleting field 'HistoricalFile.scientist_id' +        db.delete_column('archaeological_files_historicalfile', 'scientist_id') + +        # Deleting field 'HistoricalFile.research_comment' +        db.delete_column('archaeological_files_historicalfile', 'research_comment') + +        # Deleting field 'HistoricalFile.classified_area' +        db.delete_column('archaeological_files_historicalfile', 'classified_area') + +        # Deleting field 'HistoricalFile.protected_area' +        db.delete_column('archaeological_files_historicalfile', 'protected_area') + +        # Deleting field 'HistoricalFile.cira_advised' +        db.delete_column('archaeological_files_historicalfile', 'cira_advised') + +        # Deleting field 'HistoricalFile.mh_register' +        db.delete_column('archaeological_files_historicalfile', 'mh_register') + +        # Deleting field 'HistoricalFile.mh_listing' +        db.delete_column('archaeological_files_historicalfile', 'mh_listing') + + +    models = { +        'archaeological_files.file': { +            'Meta': {'ordering': "['-year', '-numeric_reference']", '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': "'+'", 'null': 'True', 'to': "orm['ishtar_common.Person']"}), +            'history_modifier': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['auth.User']"}), +            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), +            'in_charge': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'file_responsability'", 'null': 'True', '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', [], {'to': "orm['ishtar_common.Organization']", 'null': 'True', 'blank': 'True'}), +            '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': "'+'", 'null': 'True', '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': "'+'", 'null': 'True', '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_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'}), +            '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': "['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'}), +            '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'}), +            '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', 'to': "orm['ishtar_common.Organization']"}), +            'country': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}), +            'email': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}), +            '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': '30'}), +            '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': '20', '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 a94e4be86..9a42170c1 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -107,6 +107,33 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter):      postal_code = models.CharField(_(u"Main address - postal code"),                                     max_length=10, null=True, blank=True)      comment = models.TextField(_(u"Comment"), null=True, blank=True) +    # research archaeology --> +    departments = models.ManyToManyField(Department, +                          verbose_name=_(u"Departments"), +                          null=True, blank=True) +    requested_operation_type = models.ForeignKey( +                          'archaeological_operations.OperationType', +                          related_name='+', null=True, blank=True, +                          verbose_name=_(u"Requested operation type")) +    organization = models.ForeignKey(Organization, blank=True, null=True, +                          verbose_name=_(u"Organization")) +    scientist = models.ForeignKey(Person, blank=True, null=True, +                    related_name='+', +                    verbose_name=_(u"Scientist in charge")) +    research_comment = models.TextField(_(u"Research archaeology comment"), +                                        null=True, blank=True) +    classified_area = models.NullBooleanField( +                      _(u"Classified area"), blank=True, null=True) +    protected_area = models.NullBooleanField( +                      _(u"Protected area"), blank=True, null=True) +    if settings.COUNTRY == 'fr': +        cira_advised = models.NullBooleanField( +                     u"Passage en CIRA", blank=True, null=True) +        mh_register = models.NullBooleanField( +                     u"Sur Monument Historique classé", blank=True, null=True) +        mh_listing = models.NullBooleanField( +                     u"Sur Monument Historique inscrit", blank=True, null=True) +    # <-- research archaeology      cached_label = models.CharField(_(u"Cached name"), max_length=500,                                      null=True, blank=True)      history = HistoricalRecords() diff --git a/archaeological_files/templates/ishtar/sheet_file.html b/archaeological_files/templates/ishtar/sheet_file.html index b329e8279..b9bf51490 100644 --- a/archaeological_files/templates/ishtar/sheet_file.html +++ b/archaeological_files/templates/ishtar/sheet_file.html @@ -59,8 +59,8 @@  {% if item.total_surface %}<p><label>{%trans "Surface:"%}</label> <span class='value'>{{ item.total_surface }} m<sup>2</sup> ({{ item.total_surface_ha }} ha)</span></p>{%endif%} -  {% if item.is_preventive %} +  <h3>{% trans "Preventive archaelogical file"%}</h3>  <p><label>{%trans "Developed surface:"%}</label> <span class='value'>{{ item.total_developed_surface }} m<sup>2</sup> ({{ item.total_developed_surface_ha }} ha)</span></p>  <p><label>{%trans "Saisine type:"%}</label> <span class='value'>{{ item.saisine_type }}</span></p> @@ -69,6 +69,21 @@  {% if item.permit_reference %}<p><label>{%trans "Permit reference:"%}</label> <span class='value'>{{ item.permit_reference }}</span></p>{% endif %}  {% if item.general_contractor.attached_to %}<p><label>{%trans "General contractor organisation:"%}</label> <span class='value'>{{ item.general_contractor.attached_to }}</span></p>{% endif %} <!-- Contractor's organisation displayed as concat of Name/Adress/postal_code/city -->  {% if item.general_contractor %}<p><label>{%trans "General contractor:"%}</label> <span class='value'>{{ item.general_contractor.full_label }}</span></p>{% endif %} + +{%else%} + +<h3>{% trans "Research archaelogy"%}</h3> +{% if item.departments.count %}<p><label>{%trans "Departments"%}{%trans ":"%}</label> <span class='value'>{% for department in item.departments.all %}{% if forloop.counter0 %}, {% endif %}{{ department }}{% endfor %}</span></p>{% endif %} +{% if item.scientist %}<p><label>{%trans "Head scientist"%}{%trans ":"%}</label> <span class='value'>{{ item.scientist }}</span></p>{% endif %} +{% if item.requested_operation_type %}<p><label>{%trans "Requested operation type"%}{%trans ":"%}</label> <span class='value'>{{ item.requested_operation_type }}</span></p>{% endif %} +{% if item.organization %}<p><label>{%trans "Organization"%}{%trans ":"%}</label> <span class='value'>{{ item.organization }}</span></p>{% endif %} +{% if item.cira_advised != None %}<p><label>Passage en CIRA</label> <span class='value'>{{ item.cira_advised|yesno }}</span></p>{% endif %} +{% if item.mh_register != None %}<p><label>Sur Monument Historique classé</label> <span class='value'>{{ item.mh_register|yesno }}</span></p>{% endif %} +{% if item.mh_listing != None %}<p><label>Sur Monument Historique inscrit</label> <span class='value'>{{ item.mh_listing|yesno }}</span></p>{% endif %} +{% if item.classified_area != None %}<p><label>{% trans "Classified area"  %}</label> <span class='value'>{{ item.classified_area|yesno }}</span></p>{% endif %} +{% if item.protected_area != None %}<p><label>{% trans "Protected area"  %}</label> <span class='value'>{{ item.protected_area|yesno }}</span></p>{% endif %} +{% if item.research_comment %}<p><label>{%trans "Comment"%}{%trans ":"%}</label> <span class='value'>{{ item.research_comment }}</span></p>{% endif %} +  {% endif %}  <table> diff --git a/archaeological_files/views.py b/archaeological_files/views.py index eeae4fa78..71494c8f5 100644 --- a/archaeological_files/views.py +++ b/archaeological_files/views.py @@ -1,6 +1,6 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- -# Copyright (C) 2010-2013  Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2010-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 @@ -28,11 +28,10 @@ from django.utils.translation import ugettext_lazy as _  from ishtar_common.views import get_item, show_item, revert_item  from ishtar_common.models import Person -from archaeological_operations.models import AdministrativeAct  import models  from ishtar_common.wizards import SearchWizard -from archaeological_operations.wizards import is_preventive +from archaeological_operations.wizards import is_preventive, is_not_preventive  from wizards import *  from ishtar_common.forms_common import TownFormset @@ -115,12 +114,17 @@ file_creation_wizard = FileWizard.as_view([                              ('towns-file_creation', TownFormset),                              ('parcels-file_creation', ParcelFormSet),                              ('preventive-file_creation', FileFormPreventive), +                            ('research-file_creation', FileFormResearch),                              ('final-file_creation', FinalForm)],               label=_(u"New file"), -             condition_dict={'preventive-file_creation':is_preventive( -                                         'general-file_creation', -                                         models.FileType, type_key='file_type') -                            }, +             condition_dict={ +        'preventive-file_creation':\ +            is_preventive( 'general-file_creation', models.FileType, +                          type_key='file_type'), +        'research-operation_creation':\ +            is_not_preventive('general-file_creation', models.FileType, +                              type_key='file_type'), +             },               url_name='file_creation',)  file_modification_wizard = FileModificationWizard.as_view([ @@ -129,11 +133,16 @@ file_modification_wizard = FileModificationWizard.as_view([                            ('towns-file_modification', TownFormset),                            ('parcels-file_modification', ParcelFormSet),                            ('preventive-file_modification', FileFormPreventive), +                          ('research-file_modification', FileFormResearch),                            ('final-file_modification', FinalForm)],               label=_(u"File modification"), -             condition_dict={'preventive-file_modification':is_preventive( -                                         'general-file_modification', -                                         models.FileType, type_key='file_type') +             condition_dict={ +                'preventive-file_modification':\ +                    is_preventive('general-file_modification', +                                  models.FileType, type_key='file_type'), +                'research-file_modification':\ +                    is_not_preventive('general-file_modification', +                                  models.FileType, type_key='file_type'),                              },               url_name='file_modification',) diff --git a/archaeological_operations/ishtar_menu.py b/archaeological_operations/ishtar_menu.py index 143d77f05..830a0ed09 100644 --- a/archaeological_operations/ishtar_menu.py +++ b/archaeological_operations/ishtar_menu.py @@ -100,12 +100,11 @@ MENU_SECTIONS = [      (102, SectionItem('dashboard', _(u"Dashboard"),          childs=[                  MenuItem('dashboard_main', _(u"General informations"), -                    model=models.File, -                    access_controls=['change_file', 'change_own_file']), +                    model=models.Operation, +                    access_controls=['change_operation']),                  MenuItem('dashboard_operation', _(u"Operations"),                      model=models.Operation, -                    access_controls=['change_operation', -                                     'change_own_operation']), +                    access_controls=['change_operation']),          ]),      ),  ] diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 54e06b05c..855d7c8e4 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -35,8 +35,6 @@ from ishtar_common.models import GeneralType, BaseHistorizedItem, \       Person, Organization, Town, Dashboard, IshtarUser, ValueGetter, \       DocumentTemplate  FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS -if FILES_AVAILABLE: -    from archaeological_files.models import File  class OperationType(GeneralType):      preventive = models.BooleanField(_(u"Is preventive"), default=True) @@ -122,21 +120,23 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter):      operation_code = models.IntegerField(_(u"Operation code"), null=True,                                           blank=True)      if FILES_AVAILABLE: -        associated_file = models.ForeignKey(File, related_name='operations', -                                 verbose_name=_(u"File"), blank=True, null=True) +        associated_file = models.ForeignKey('archaeological_files.File', +            related_name='operations', verbose_name=_(u"File"), +            blank=True, null=True)      operation_type = models.ForeignKey(OperationType, related_name='+',                                         verbose_name=_(u"Operation type"))      surface = models.IntegerField(_(u"Surface (m²)"), blank=True, null=True)      remains = models.ManyToManyField("RemainType", verbose_name=_(u'Remains'))      towns = models.ManyToManyField(Town, verbose_name=_(u"Towns")) -    cost = models.IntegerField(_(u"Cost (€)"), blank=True, null=True) +    cost = models.IntegerField(_(u"Cost (€)"), +                               blank=True, null=True) # preventive      periods = models.ManyToManyField(Period, verbose_name=_(u"Periods"))      scheduled_man_days = models.IntegerField(_(u"Scheduled man-days"), -                                             blank=True, null=True) +                                             blank=True, null=True) # preventive      optional_man_days = models.IntegerField(_(u"Optional man-days"), -                                             blank=True, null=True) +                                             blank=True, null=True) # preventive      effective_man_days = models.IntegerField(_(u"Effective man-days"), -                                             blank=True, null=True) +                                             blank=True, null=True) # preventive      if settings.COUNTRY == 'fr':          code_patriarche = models.IntegerField(u"Code PATRIARCHE", null=True,                                                blank=True) @@ -144,15 +144,18 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter):          code_dracar = models.CharField(u"Code DRACAR", max_length=10, null=True,                                         blank=True)          fnap_financing = models.FloatField(u"Financement FNAP (%)", -                                             blank=True, null=True) +                                             blank=True, null=True) # preventive          fnap_cost = models.IntegerField(u"Financement FNAP (€)", -                                             blank=True, null=True) +                                             blank=True, null=True) # preventive          zoning_prescription = models.NullBooleanField( -                            _(u"Prescription on zoning"), blank=True, null=True) +                            _(u"Prescription on zoning"), +                            blank=True, null=True) # preventive diag          large_area_prescription = models.NullBooleanField( -                        _(u"Prescription on large area"), blank=True, null=True) +                            _(u"Prescription on large area"), +                            blank=True, null=True) # preventive diag          geoarchaeological_context_prescription = models.NullBooleanField( -         _(u"Prescription on geoarchaeological context"), blank=True, null=True) +                            _(u"Prescription on geoarchaeological context"), +                            blank=True, null=True) # preventive diag          cira_rapporteur = models.ForeignKey(Person, related_name='+', null=True,                                      blank=True, verbose_name=u"Rapporteur CIRA")          negative_result = models.NullBooleanField( @@ -435,7 +438,8 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):      operation = models.ForeignKey(Operation, blank=True, null=True,                  related_name='administrative_act', verbose_name=_(u"Operation"))      if FILES_AVAILABLE: -        associated_file = models.ForeignKey(File, blank=True, null=True, +        associated_file = models.ForeignKey('archaeological_files.File', +            blank=True, null=True,              related_name='administrative_act',              verbose_name=_(u"Archaelogical file"))      signature_date = models.DateField(_(u"Signature date"), blank=True, @@ -546,8 +550,9 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):  class Parcel(LightHistorizedItem):      if FILES_AVAILABLE: -        associated_file = models.ForeignKey(File, related_name='parcels', -                                blank=True, null=True, verbose_name=_(u"File")) +        associated_file = models.ForeignKey('archaeological_files.File', +            related_name='parcels', verbose_name=_(u"File"), +            blank=True, null=True)      operation = models.ForeignKey(Operation, related_name='parcels', blank=True,                                    null=True, verbose_name=_(u"Operation"))      year = models.IntegerField(_(u"Year"), blank=True, null=True) diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index a14924301..cacc44da1 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -1,6 +1,6 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- -# Copyright (C) 2012-2013  Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2012-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 @@ -372,6 +372,11 @@ def is_preventive(form_name, model, type_key='operation_type', key=''):              return False      return func +def is_not_preventive(form_name, model, type_key='operation_type', key=''): +    def func(self): +        return not is_preventive(form_name, model, type_key, key)(self) +    return func +  def has_associated_file(form_name, file_key='associated_file', negate=False):      def func(self):          request = self.request diff --git a/ishtar_common/models.py b/ishtar_common/models.py index d91d62995..5bebaa59e 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -689,7 +689,7 @@ class Department(models.Model):          ordering = ['number']      def __unicode__(self): -        return unicode(self.number) + settings.JOINT + self.label +        return u"%s (%s)" % (self.label, self.number)  class Address(BaseHistorizedItem):      address = models.TextField(_(u"Address"), null=True, blank=True) diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index 6afd8073d..ab47e82b7 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -1,6 +1,6 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- -# Copyright (C) 2010-2013 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2010-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 @@ -71,6 +71,8 @@ urlpatterns += patterns('ishtar_common.views',             'show_person', name='show-person'),       url(r'autocomplete-town/?$', 'autocomplete_town',             name='autocomplete-town'), +     url(r'autocomplete-department/?$', 'autocomplete_department', +           name='autocomplete-department'),       url(r'new-author/(?P<parent_name>.+)?/$',             'new_author', name='new-author'),       url(r'autocomplete-author/$', 'autocomplete_author', diff --git a/ishtar_common/views.py b/ishtar_common/views.py index ba583438c..7440e0170 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1,6 +1,6 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- -# Copyright (C) 2010-2013  Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2010-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 @@ -152,6 +152,21 @@ def autocomplete_person(request, person_types=None):                                  for person in persons if person])      return HttpResponse(data, mimetype='text/plain') +def autocomplete_department(request): +    if not request.GET.get('term'): +        return HttpResponse(mimetype='text/plain') +    q = request.GET.get('term') +    q = unicodedata.normalize("NFKD", q).encode('ascii','ignore') +    query = Q() +    for q in q.split(' '): +        extra = (Q(label__icontains=q) | Q(number__istartswith=q)) +        query = query & extra +    limit = 20 +    departments = models.Department.objects.filter(query)[:limit] +    data = json.dumps([{'id':department.pk, 'value':unicode(department)} +                                          for department in departments]) +    return HttpResponse(data, mimetype='text/plain') +  def autocomplete_town(request):      if not request.GET.get('term'):          return HttpResponse(mimetype='text/plain')  | 
