diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-10-21 15:04:28 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-10-21 15:04:28 +0200 |
commit | f31f0f269a68b2dfc5c834ce420bb5a02a3ecd0c (patch) | |
tree | a8d881b59447269f2e92578cf5924759bad17704 | |
parent | 48eb91979705f9999b724c8e2f960fd7931775c1 (diff) | |
download | Ishtar-f31f0f269a68b2dfc5c834ce420bb5a02a3ecd0c.tar.bz2 Ishtar-f31f0f269a68b2dfc5c834ce420bb5a02a3ecd0c.zip |
Djangoization - Major refactoring (step 8)
* clean-up on request and storage args in methods
* view creation now managed by South
* clean some mess in session values by using MultiValueDict
-rw-r--r-- | archaeological_context_records/wizards.py | 30 | ||||
-rw-r--r-- | archaeological_files/migrations/0002_views.py | 245 | ||||
-rw-r--r-- | archaeological_files/models.py | 12 | ||||
-rw-r--r-- | archaeological_files/wizards.py | 10 | ||||
-rw-r--r-- | archaeological_finds/wizards.py | 36 | ||||
-rw-r--r-- | archaeological_operations/migrations/0002_views.py | 407 | ||||
-rw-r--r-- | archaeological_operations/models.py | 10 | ||||
-rw-r--r-- | archaeological_operations/wizards.py | 89 | ||||
-rw-r--r-- | archaeological_warehouse/wizards.py | 12 | ||||
-rw-r--r-- | ishtar_common/models.py | 8 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/wizard/towns_wizard.html (renamed from ishtar_common/templates/towns_wizard.html) | 0 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 48 |
12 files changed, 772 insertions, 135 deletions
diff --git a/archaeological_context_records/wizards.py b/archaeological_context_records/wizards.py index 1fd657bcc..86ce3bd30 100644 --- a/archaeological_context_records/wizards.py +++ b/archaeological_context_records/wizards.py @@ -30,30 +30,29 @@ class RecordWizard(Wizard): model = models.ContextRecord edit = False - def get_current_operation(self, request, storage): - step = storage.get_current_step() + def get_current_operation(self): + step = self.steps.current if not step: return if step.endswith('_creation'): # an operation has been selected main_form_key = 'selec-' + self.url_name try: - idx = int(self.session_get_value(request, storage, - main_form_key, 'operation_id')) + idx = int(self.session_get_value(main_form_key, 'operation_id')) current_ope = models.Operation.objects.get(pk=idx) return current_ope except(TypeError, ValueError, ObjectDoesNotExist): pass - current_cr = self.get_current_object(request, storage) + current_cr = self.get_current_object() if current_cr: return current_cr.parcel.operation - def get_template_context(self, request, storage, form=None): + # get_template_context + def get_context_data(self, form, **kwargs): """ Get the operation "reminder" on top of wizard forms """ - context = super(RecordWizard, self).get_template_context(request, - storage, form) - operation = self.get_current_operation(request, storage) + context = super(RecordWizard, self).get_context_data(form) + operation = self.get_current_operation() if not operation: return context items = [] @@ -64,7 +63,7 @@ class RecordWizard(Wizard): context['reminder'] = _("Current operation: ") + " - ".join(items) return context - def get_form(self, request, storage, step=None, data=None, files=None): + def get_form(self, step=None, data=None, files=None): """ Get associated operation """ @@ -75,24 +74,23 @@ class RecordWizard(Wizard): if not step: step = self.steps.current #step = self.determine_step(request, storage) - form = self.get_form_list(request, storage)[step] + form = self.get_form_list()[step] general_form_key = 'general-' + self.url_name if step.startswith('general-'): if step.endswith('_creation'): # an operation has been selected main_form_key = 'selec-' + self.url_name try: - idx = int(self.session_get_value(request, storage, - main_form_key, 'operation_id')) + idx = int(self.session_get_value(main_form_key, + 'operation_id')) current_obj = models.Operation.objects.get(pk=idx) data['operation'] = current_obj except(TypeError, ValueError, ObjectDoesNotExist): pass else: - current_object = self.get_current_object(request, storage) + current_object = self.get_current_object() data['context_record'] = current_object - form = super(RecordWizard, self).get_form(request, storage, step, data, - files) + form = super(RecordWizard, self).get_form(step, data, files) return form class RecordModifWizard(RecordWizard): diff --git a/archaeological_files/migrations/0002_views.py b/archaeological_files/migrations/0002_views.py new file mode 100644 index 000000000..dfbb466ec --- /dev/null +++ b/archaeological_files/migrations/0002_views.py @@ -0,0 +1,245 @@ +# -*- 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): + # dashboard view initialisation + sql = """ + create view file_department (id, department_id, file_id) as + select town."id", town."departement_id", file_towns."file_id" + from ishtar_common_town town + inner join archaeological_files_file_towns file_towns + on file_towns."town_id"=town."id" + order by town."departement_id"; + CREATE RULE file_department_delete + AS ON DELETE TO file_department DO INSTEAD(); + """ + db.execute(sql) + + def backwards(self, orm): + sql = "drop view file_department;" + db.execute(sql) + + 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'}), + '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': ('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', [], {'related_name': "'+'", 'to': "orm['ishtar_common.Person']"}), + 'internal_reference': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '60'}), + 'numeric_reference': ('django.db.models.fields.IntegerField', [], {}), + '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'}), + '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'}), + 'saisine_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archaeological_files.SaisineType']", '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'}), + 'town_planning_service': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'to': "orm['ishtar_common.Organization']"}), + 'towns': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'file'", 'symmetrical': 'False', 'to': "orm['ishtar_common.Town']"}), + 'year': ('django.db.models.fields.IntegerField', [], {'default': '2012'}) + }, + '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': {'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'}), + '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', 'db_index': 'True'}), + 'numeric_reference': ('django.db.models.fields.IntegerField', [], {}), + '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'}), + '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'}), + 'saisine_type_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'}), + 'town_planning_service_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'year': ('django.db.models.fields.IntegerField', [], {'default': '2012'}) + }, + 'archaeological_files.permittype': { + 'Meta': {'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': {'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'}) + }, + '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': '100'}), + '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': {'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', [], {'to': "orm['ishtar_common.Organization']", 'null': 'True', 'blank': 'True'}), + '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_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.PersonType']"}), + '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'}), + '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': {'object_name': 'PersonType'}, + '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'}), + 'rights': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['ishtar_common.WizardStep']", 'symmetrical': 'False'}), + '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'}) + }, + 'ishtar_common.wizard': { + 'Meta': {'ordering': "['url_name']", 'object_name': 'Wizard'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'url_name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'}) + }, + 'ishtar_common.wizardstep': { + 'Meta': {'ordering': "['wizard', 'order']", 'object_name': 'WizardStep'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'order': ('django.db.models.fields.IntegerField', [], {}), + 'url_name': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'wizard': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Wizard']"}) + } + } + + complete_apps = ['archaeological_files'] diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 0bc9a9566..0b95c021a 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -26,7 +26,7 @@ from django.utils.translation import ugettext_lazy as _, ugettext from ishtar_common.models import GeneralType, BaseHistorizedItem, \ HistoricalRecords, OwnPerms, Person, Organization, Department, Town, \ - Dashboard + Dashboard, IshtarUser class FileType(GeneralType): class Meta: @@ -169,15 +169,7 @@ class File(BaseHistorizedItem, OwnPerms): class FileByDepartment(models.Model): ''' - Database view: don't forget to create it - - create view file_department (id, department_id, file_id) as - select town."id", town."departement_id", file_towns."file_id" - from ishtar_base_town town - inner join ishtar_base_file_towns file_towns on - file_towns."town_id"=town."id" order by town."departement_id"; - CREATE RULE file_department_delete - AS ON DELETE TO file_department DO INSTEAD(); + Database view for dashboard ''' file = models.ForeignKey(File, verbose_name=_(u"File")) department = models.ForeignKey(Department, verbose_name=_(u"Department"), diff --git a/archaeological_files/wizards.py b/archaeological_files/wizards.py index e98248965..0cc34ebcc 100644 --- a/archaeological_files/wizards.py +++ b/archaeological_files/wizards.py @@ -28,7 +28,8 @@ from ishtar_common.wizards import Wizard, ClosingWizard from archaeological_operations.wizards import OperationAdministrativeActWizard,\ AdministrativeActDeletionWizard from ishtar_common.models import Town -from archaeological_operations.models import AdministrativeAct, Parcel +from archaeological_operations.models import AdministrativeAct, Parcel, \ + Operation import models class FileWizard(Wizard): @@ -50,7 +51,7 @@ class FileWizard(Wizard): form = self.get_form_list()[step] town_form_key = 'towns-' + self.url_name if step.startswith('parcels-') and hasattr(form, 'management_form') \ - and self.session_has_key(self.request, self.storage, town_form_key): + and self.session_has_key(town_form_key): towns = [] qdict = self.request.session[self.storage.prefix]['step_data']\ [town_form_key] @@ -132,7 +133,7 @@ class FileDeletionWizard(FileClosingWizard): def get_formated_datas(self, forms): datas = super(FileDeletionWizard, self).get_formated_datas(forms) datas.append((_("Associated operations"), [])) - for operation in models.Operation.objects.filter( + for operation in Operation.objects.filter( associated_file=self.current_obj).all(): if operation.end_date: datas[-1][1].append(('', unicode(operation))) @@ -140,8 +141,7 @@ class FileDeletionWizard(FileClosingWizard): def done(self, form_list, **kwargs): obj = self.get_current_object() - for operation in models.Operation.objects.filter( - associated_file=obj).all(): + for operation in Operation.objects.filter(associated_file=obj).all(): operation.delete() obj.delete() return render_to_response('wizard_done.html', {}, diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py index 2352863eb..4d2a54f73 100644 --- a/archaeological_finds/wizards.py +++ b/archaeological_finds/wizards.py @@ -26,35 +26,34 @@ from django.utils.translation import ugettext_lazy as _ from ishtar_common.wizards import Wizard, DeletionWizard, SourceWizard import models -class ItemWizard(Wizard): - model = models.Item +class FindWizard(Wizard): + model = models.Find - def get_current_contextrecord(self, request, storage): - step = storage.get_current_step() + def get_current_contextrecord(self): + step = self.steps.current if not step: return if step.endswith('_creation'): # a context record has been selected main_form_key = 'selecrecord-' + self.url_name try: - idx = int(self.session_get_value(request, storage, - main_form_key, 'pk')) + idx = int(self.session_get_value(main_form_key, 'pk')) current_cr = models.ContextRecord.objects.get(pk=idx) return current_cr except(TypeError, ValueError, ObjectDoesNotExist): pass - current_item = self.get_current_object(request, storage) + current_item = self.get_current_object() if current_item: base_finds = current_item.base_finds.all() if base_finds: return base_finds[0].context_record - def get_template_context(self, request, storage, form=None): + #def get_template_context(self, request, storage, form=None): + def get_context_data(self, form, **kwargs): """ Get the operation and context record "reminder" on top of wizard forms """ - context = super(ItemWizard, self).get_template_context(request, - storage, form) - current_cr = self.get_current_contextrecord(request, storage) + context = super(FindWizard, self).get_context_data(form, **kwargs) + current_cr = self.get_current_contextrecord() if not current_cr: return context operation = current_cr.operation @@ -69,25 +68,24 @@ class ItemWizard(Wizard): context['reminder'] = mark_safe(reminder) return context - def get_extra_model(self, dct, request, storage, form_list): - dct = super(ItemWizard, self).get_extra_model(dct, request, storage, - form_list) + def get_extra_model(self, dct, form_list): + dct = super(FindWizard, self).get_extra_model(dct, form_list) dct['order'] = 1 if 'pk' in dct and type(dct['pk']) == models.ContextRecord: dct['base_finds__context_record'] = dct.pop('pk') return dct -class ItemModificationWizard(ItemWizard): +class FindModificationWizard(FindWizard): modification = True class TreatmentWizard(Wizard): model = models.Treatment -class ItemSourceWizard(SourceWizard): - model = models.ItemSource +class FindSourceWizard(SourceWizard): + model = models.FindSource -class ItemSourceDeletionWizard(DeletionWizard): - model = models.ItemSource +class FindSourceDeletionWizard(DeletionWizard): + model = models.FindSource fields = ['item', 'title', 'source_type', 'authors',] class TreatmentSourceWizard(SourceWizard): diff --git a/archaeological_operations/migrations/0002_views.py b/archaeological_operations/migrations/0002_views.py new file mode 100644 index 000000000..a9d4e3665 --- /dev/null +++ b/archaeological_operations/migrations/0002_views.py @@ -0,0 +1,407 @@ +# -*- 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): + pass + sql = """ + create view operation_department (id, department_id, operation_id) as + select town."id", town."departement_id", + operation_towns."operation_id" + from ishtar_common_town town + inner join archaeological_operations_operation_towns + operation_towns + on operation_towns."town_id"=town."id" + order by town."departement_id"; + CREATE RULE operation_department_delete + AS ON DELETE TO operation_department DO INSTEAD(); + """ + db.execute(sql) + + def backwards(self, orm): + sql = "drop view operation_department;" + db.execute(sql) + + 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'}), + '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': ('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', [], {'related_name': "'+'", 'to': "orm['ishtar_common.Person']"}), + 'internal_reference': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '60'}), + 'numeric_reference': ('django.db.models.fields.IntegerField', [], {}), + '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'}), + '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'}), + 'saisine_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archaeological_files.SaisineType']", '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'}), + 'town_planning_service': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'to': "orm['ishtar_common.Organization']"}), + 'towns': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'file'", 'symmetrical': 'False', 'to': "orm['ishtar_common.Town']"}), + 'year': ('django.db.models.fields.IntegerField', [], {'default': '2012'}) + }, + 'archaeological_files.filetype': { + 'Meta': {'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.permittype': { + 'Meta': {'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': {'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.acttype': { + 'Meta': {'object_name': 'ActType'}, + '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'}), + 'intented_to': ('django.db.models.fields.CharField', [], {'max_length': '1'}), + 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'archaeological_operations.administrativeact': { + 'Meta': {'object_name': 'AdministrativeAct'}, + 'act_object': ('django.db.models.fields.CharField', [], {'max_length': '200'}), + 'act_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archaeological_operations.ActType']"}), + 'associated_file': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'administrative_act'", 'null': 'True', 'to': "orm['archaeological_files.File']"}), + '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': "'+'", 'null': 'True', 'to': "orm['ishtar_common.Person']"}), + 'operation': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'administrative_act'", 'null': 'True', 'to': "orm['archaeological_operations.Operation']"}), + 'operator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Organization']", 'null': 'True', 'blank': 'True'}), + 'ref_sra': ('django.db.models.fields.CharField', [], {'max_length': '15'}), + 'scientific': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'to': "orm['ishtar_common.Person']"}), + 'signatory': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'to': "orm['ishtar_common.Person']"}), + 'signature_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}) + }, + 'archaeological_operations.historicaladministrativeact': { + 'Meta': {'ordering': "('-history_date', '-history_id')", 'object_name': 'HistoricalAdministrativeAct'}, + 'act_object': ('django.db.models.fields.CharField', [], {'max_length': '200'}), + 'act_type_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'associated_file_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'}), + 'operation_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'operator_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'ref_sra': ('django.db.models.fields.CharField', [], {'max_length': '15'}), + 'scientific_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'signatory_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'signature_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}) + }, + 'archaeological_operations.historicaloperation': { + 'Meta': {'ordering': "('-history_date', '-history_id')", 'object_name': 'HistoricalOperation'}, + 'associated_file_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'code_dracar': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}), + 'code_patriarche': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'common_name': ('django.db.models.fields.CharField', [], {'max_length': '120', 'null': 'True', 'blank': 'True'}), + 'cost': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'effective_man_days': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'end_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'excavation_end_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'fnap_cost': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'fnap_financing': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}), + 'geoarchaeological_context_prescription': ('django.db.models.fields.NullBooleanField', [], {'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'}), + 'large_area_prescription': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}), + 'operation_code': ('django.db.models.fields.IntegerField', [], {}), + 'operation_type_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'operator_reference': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}), + 'optional_man_days': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'scheduled_man_days': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'start_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'surface': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'year': ('django.db.models.fields.IntegerField', [], {}), + 'zoning_prescription': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}) + }, + 'archaeological_operations.operation': { + 'Meta': {'object_name': 'Operation'}, + 'associated_file': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'operations'", 'null': 'True', 'to': "orm['archaeological_files.File']"}), + 'code_dracar': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}), + 'code_patriarche': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'common_name': ('django.db.models.fields.CharField', [], {'max_length': '120', 'null': 'True', 'blank': 'True'}), + 'cost': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'effective_man_days': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'end_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'excavation_end_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'fnap_cost': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'fnap_financing': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}), + 'geoarchaeological_context_prescription': ('django.db.models.fields.NullBooleanField', [], {'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'}), + 'in_charge': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'to': "orm['ishtar_common.Person']"}), + 'large_area_prescription': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}), + 'operation_code': ('django.db.models.fields.IntegerField', [], {}), + 'operation_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['archaeological_operations.OperationType']"}), + 'operator_reference': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}), + 'optional_man_days': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'periods': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['archaeological_operations.Period']", 'symmetrical': 'False'}), + 'remains': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['archaeological_operations.RemainType']", 'symmetrical': 'False'}), + 'scheduled_man_days': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'start_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'surface': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'towns': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['ishtar_common.Town']", 'symmetrical': 'False'}), + 'year': ('django.db.models.fields.IntegerField', [], {}), + 'zoning_prescription': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}) + }, + 'archaeological_operations.operationbydepartment': { + 'Meta': {'object_name': 'OperationByDepartment', 'db_table': "'operation_department'", 'managed': 'False'}, + 'department': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Department']", 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'operation': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archaeological_operations.Operation']"}) + }, + 'archaeological_operations.operationsource': { + 'Meta': {'object_name': 'OperationSource'}, + 'associated_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'authors': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['ishtar_common.Author']", 'symmetrical': 'False'}), + 'creation_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'index': ('django.db.models.fields.IntegerField', [], {}), + 'operation': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'source'", 'to': "orm['archaeological_operations.Operation']"}), + 'receipt_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'source_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.SourceType']"}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '200'}) + }, + 'archaeological_operations.operationtype': { + 'Meta': {'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'}), + 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'archaeological_operations.parcel': { + 'Meta': {'object_name': 'Parcel'}, + 'associated_file': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'parcels'", 'null': 'True', 'to': "orm['archaeological_files.File']"}), + 'history_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'history_modifier': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['auth.User']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'operation': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'parcels'", 'null': 'True', 'to': "orm['archaeological_operations.Operation']"}), + 'parcel_number': ('django.db.models.fields.CharField', [], {'max_length': '6'}), + 'section': ('django.db.models.fields.CharField', [], {'max_length': '4'}), + 'town': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'parcels'", 'to': "orm['ishtar_common.Town']"}), + 'year': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}) + }, + 'archaeological_operations.parcelowner': { + 'Meta': {'object_name': 'ParcelOwner'}, + 'end_date': ('django.db.models.fields.DateField', [], {}), + 'history_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'history_modifier': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['auth.User']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Person']"}), + 'parcel': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archaeological_operations.Parcel']"}), + 'start_date': ('django.db.models.fields.DateField', [], {}) + }, + 'archaeological_operations.period': { + 'Meta': {'object_name': 'Period'}, + 'available': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'end_date': ('django.db.models.fields.IntegerField', [], {}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'order': ('django.db.models.fields.IntegerField', [], {}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archaeological_operations.Period']", 'null': 'True', 'blank': 'True'}), + 'start_date': ('django.db.models.fields.IntegerField', [], {}), + 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'archaeological_operations.remaintype': { + 'Meta': {'object_name': 'RemainType'}, + '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'}) + }, + '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.author': { + 'Meta': {'object_name': 'Author'}, + 'author_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.AuthorType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'person': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Person']"}) + }, + 'ishtar_common.authortype': { + 'Meta': {'object_name': 'AuthorType'}, + '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.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': '100'}), + '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': {'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', [], {'to': "orm['ishtar_common.Organization']", 'null': 'True', 'blank': 'True'}), + '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_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.PersonType']"}), + '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'}), + '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': {'object_name': 'PersonType'}, + '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'}), + 'rights': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['ishtar_common.WizardStep']", 'symmetrical': 'False'}), + 'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'ishtar_common.sourcetype': { + 'Meta': {'object_name': 'SourceType'}, + '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.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'}) + }, + 'ishtar_common.wizard': { + 'Meta': {'ordering': "['url_name']", 'object_name': 'Wizard'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'url_name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'}) + }, + 'ishtar_common.wizardstep': { + 'Meta': {'ordering': "['wizard', 'order']", 'object_name': 'WizardStep'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'order': ('django.db.models.fields.IntegerField', [], {}), + 'url_name': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'wizard': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Wizard']"}) + } + } + + complete_apps = ['archaeological_operations'] diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 60de936d2..42026eebe 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -222,15 +222,7 @@ post_save.connect(operation_post_save, sender=Operation) class OperationByDepartment(models.Model): ''' - Database view: don't forget to create it - - create view operation_department (id, department_id, operation_id) as - select town."id", town."departement_id", operation_towns."operation_id" - from ishtar_base_town town - inner join ishtar_base_operation_towns operation_towns on - operation_towns."town_id"=town."id" order by town."departement_id"; - CREATE RULE operation_department_delete - AS ON DELETE TO operation_department DO INSTEAD(); + Database view for dashboard ''' operation = models.ForeignKey(Operation, verbose_name=_(u"Operation")) department = models.ForeignKey(Department, verbose_name=_(u"Department"), diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index 542d0118b..2dae72aad 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -31,35 +31,36 @@ class OperationWizard(Wizard): model = models.Operation object_parcel_type = 'operation' - def get_template(self, request, storage): - templates = super(OperationWizard, self).get_template(request, storage) + def get_template_names(self): + templates = super(OperationWizard, self).get_template_names() current_step = storage.get_current_step() or self.get_first_step( request, storage) if current_step.startswith('towns-'): - templates = ['towns_wizard.html'] + templates + # vérifier que le context_data est bien chargé + #templates = ['ishtar/wizard/towns_wizard.html'] + templates + templates = ['ishtar/wizar/towns_wizard.html'] + templates return templates - def get_extra_context(self, request, storage): + def get_context_data(self, form, **kwargs): """ Return extra context for templates """ - context = super(OperationWizard, self).get_extra_context(request, - storage) + context = super(OperationWizard, self).get_context_data(forms, + **kwargs) #step = self.determine_step(request, storage) step = self.steps.current if not step.startswith('towns-'): return context - context['TOWNS'] = self.get_towns(request, storage) + context['TOWNS'] = self.get_towns() return context - def get_towns(self, request, storage): + def get_towns(self): """ Obtention des villes disponibles """ general_form_key = 'general-' + self.url_name towns = [] - file_id = self.session_get_value(request, storage, general_form_key, - "associated_file") + file_id = self.session_get_value(general_form_key, "associated_file") if file_id: try: for town in models.File.objects.get(pk=int(file_id) @@ -71,7 +72,7 @@ class OperationWizard(Wizard): else: return -1 - def get_form(self, request, storage, step=None, data=None, files=None): + def get_form(self, step=None, data=None, files=None): """ Manage specifics fields """ @@ -82,13 +83,13 @@ class OperationWizard(Wizard): if not step: #step = self.determine_step(request, storage) step = self.steps.current - form = self.get_form_list(request, storage)[step] + form = self.get_form_list()[step] general_form_key = 'general-' + self.url_name # manage the dynamic choice of towns if step.startswith('towns-') and hasattr(form, 'management_form'): - data['TOWNS'] = self.get_towns(request, storage) + data['TOWNS'] = self.get_towns() elif step.startswith('parcels') and hasattr(form, 'management_form'): - file_id = self.session_get_value(request, storage, general_form_key, + file_id = self.session_get_value(general_form_key, "associated_file") if file_id: parcels = [] @@ -103,8 +104,8 @@ class OperationWizard(Wizard): town_form_key = step.startswith('parcelsgeneral') \ and 'townsgeneral-' or 'towns-' town_form_key += self.url_name - town_ids = self.session_get_value(request, storage, - town_form_key, 'town', multi=True) or [] + town_ids = self.session_get_value(town_form_key, 'town', + multi=True) or [] towns = [] for town_id in town_ids: try: @@ -114,8 +115,7 @@ class OperationWizard(Wizard): pass data['TOWNS'] = sorted(towns, key=lambda x:x[1]) data = data or None - form = super(OperationWizard, self).get_form(request, storage, step, - data, files) + form = super(OperationWizard, self).get_form(step, data, files) return form def get_formated_datas(self, forms): @@ -138,7 +138,8 @@ class OperationModificationWizard(OperationWizard): class OperationClosingWizard(ClosingWizard): model = models.Operation fields = ['year', 'operation_code', 'operation_type', 'associated_file', -'in_charge', 'start_date', 'excavation_end_date', 'comment', 'towns', 'remains'] + 'in_charge', 'start_date', 'excavation_end_date', 'comment', + 'towns', 'remains'] class OperationDeletionWizard(DeletionWizard): model = models.Operation @@ -146,15 +147,14 @@ class OperationDeletionWizard(DeletionWizard): class OperationSourceWizard(SourceWizard): model = models.OperationSource - def get_form_initial(self, request, storage, step): - initial = super(OperationSourceWizard, self).get_form_initial(request, - storage, step) + def get_form_initial(self, step): + initial = super(OperationSourceWizard, self).get_form_initial(step) # put default index and operation_id field in the main source form general_form_key = 'selec-' + self.url_name if step.startswith('source-') \ - and self.session_has_key(request, storage, general_form_key): - gen_storage = request.session[storage.prefix]['step_data']\ - [general_form_key] + and self.session_has_key(general_form_key): + gen_storage = self.request.session[storage.prefix]['step_data']\ + [general_form_key] if general_form_key+"-operation" in gen_storage: operation_id = int(gen_storage[general_form_key+"-operation"]) elif general_form_key+"-pk" in gen_storage: @@ -180,27 +180,27 @@ class OperationSourceDeletionWizard(DeletionWizard): class OperationAdministrativeActWizard(OperationWizard): edit = False - def get_extra_model(self, dct, request, storage, form_list): - dct['history_modifier'] = request.user + def get_extra_model(self, dct, form_list): + dct['history_modifier'] = self.request.user return dct - def get_associated_item(self, request, storage, dct): - return self.get_current_object(request, storage) + def get_associated_item(self, dct): + return self.get_current_object() - def save_model(self, dct, m2m, whole_associated_models, request, storage, - form_list, return_object): - associated_item = self.get_associated_item(request, storage, dct) + def save_model(self, dct, m2m, whole_associated_models, form_list, + return_object): + associated_item = self.get_associated_item(dct) if not associated_item: - return self.render(request, storage, form_list[-1]) + return self.render(form_list[-1]) if isinstance(associated_item, models.File): dct['associated_file'] = associated_item elif isinstance(associated_item, models.Operation): dct['operation'] = associated_item - dct['history_modifier'] = request.user + dct['history_modifier'] = self.request.user if 'pk' in dct: dct.pop('pk') if self.edit: - admact = self.get_current_object(request, storage) + admact = self.get_current_object() for k in dct: if hasattr(admact, k): setattr(admact, k, dct[k]) @@ -208,14 +208,14 @@ class OperationAdministrativeActWizard(OperationWizard): admact = models.AdministrativeAct(**dct) admact.save() res = render_to_response('wizard_done.html', {}, - context_instance=RequestContext(request)) + context_instance=RequestContext(self.request)) return res class OperationEditAdministrativeActWizard(OperationAdministrativeActWizard): model = models.AdministrativeAct edit = True - def get_associated_item(self, request, storage, dct): - return self.get_current_object(request, storage).operation + def get_associated_item(self, dct): + return self.get_current_object().operation class AdministrativeActDeletionWizard(ClosingWizard): model = models.AdministrativeAct @@ -224,11 +224,11 @@ class AdministrativeActDeletionWizard(ClosingWizard): if settings.COUNTRY == 'fr': fields += ['ref_sra'] - def done(self, request, storage, form_list, **kwargs): - obj = self.get_current_object(request, storage) + def done(self, form_list, **kwargs): + obj = self.get_current_object() obj.delete() return render_to_response('wizard_done.html', {}, - context_instance=RequestContext(request)) + context_instance=RequestContext(self.request)) def is_preventive(form_name, model, type_key='operation_type', key=''): def func(self): @@ -241,8 +241,11 @@ def is_preventive(form_name, model, type_key='operation_type', key=''): request.session[storage.prefix]['step_data'][form_name]: return False try: - typ = int(request.session[storage.prefix]['step_data']\ - [form_name][form_name+'-'+type_key][0]) + typ = request.session[storage.prefix]['step_data']\ + [form_name][form_name+'-'+type_key] + if type(typ) in (list, tuple): + typ = typ[0] + typ = int(typ) return model.is_preventive(typ, key) except ValueError: return False diff --git a/archaeological_warehouse/wizards.py b/archaeological_warehouse/wizards.py index 1e8455b94..06d3ec887 100644 --- a/archaeological_warehouse/wizards.py +++ b/archaeological_warehouse/wizards.py @@ -26,10 +26,10 @@ from archaeological_finds.models import Treatment class PackagingWizard(TreatmentWizard): - def save_model(self, dct, m2m, whole_associated_models, request, storage, - form_list, return_object): - dct = self.get_extra_model(dct, request, storage, form_list) - obj = self.get_current_saved_object(request, storage) + def save_model(self, dct, m2m, whole_associated_models, form_list, + return_object): + dct = self.get_extra_model(dct, form_list) + obj = self.get_current_saved_object() dct['location'] = dct['container'].location items = dct.pop('items') treatment = Treatment(**dct) @@ -37,12 +37,12 @@ class PackagingWizard(TreatmentWizard): if not hasattr(items, '__iter__'): items = [items] for item in items: - new = item.duplicate(request.user) + new = item.duplicate(self.request.user) item.downstream_treatment = treatment item.save() new.upstream_treatment = treatment new.container = dct['container'] new.save() res = render_to_response('wizard_done.html', {}, - context_instance=RequestContext(request)) + context_instance=RequestContext(self.request)) return return_object and (obj, res) or res diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 3ca830aa3..d8d3c3213 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -579,9 +579,11 @@ class Person(Address, OwnPerms) : return lbl def full_label(self): - return u" ".join([unicode(getattr(self, attr)) - for attr in ('title', 'surname', 'name', 'attached_to') - if getattr(self, attr)]) + values = [unicode(_(self.title))] + values += [unicode(getattr(self, attr)) + for attr in ('surname', 'name', 'attached_to') + if getattr(self, attr)] + return u" ".join(values) class IshtarUser(User): person = models.ForeignKey(Person, verbose_name=_(u"Person"), unique=True) diff --git a/ishtar_common/templates/towns_wizard.html b/ishtar_common/templates/ishtar/wizard/towns_wizard.html index 115ac9838..115ac9838 100644 --- a/ishtar_common/templates/towns_wizard.html +++ b/ishtar_common/templates/ishtar/wizard/towns_wizard.html diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 7895d98e3..e423b834e 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -24,8 +24,8 @@ from django.contrib.formtools.wizard.views import NamedUrlWizardView from django.core.exceptions import ObjectDoesNotExist from django.shortcuts import render_to_response from django.template import RequestContext +from django.utils.datastructures import MultiValueDict from django.utils.translation import ugettext_lazy as _ - import models class Wizard(NamedUrlWizardView): @@ -134,7 +134,7 @@ class Wizard(NamedUrlWizardView): # check if the form is initialized otherwise initialize it if not storage.get_step_data(next_step): values = self.get_form_initial(next_step) - prefixed_values = {} + prefixed_values = MultiValueDict() if not isinstance(values, list): for key in values: form_key = next_step + '-' + key @@ -525,12 +525,13 @@ class Wizard(NamedUrlWizardView): request.POST = post_data return super(Wizard, self).post(*args, **kwargs) - @classmethod - def session_has_key(cls, request, storage, form_key, key=None, multi=None): + def session_has_key(self, form_key, key=None, multi=None): """Check if the session has value of a specific form and (if provided) of a key """ print "17" + request = self.request + storage = self.storage test = storage.prefix in request.session \ and 'step_data' in request.session[storage.prefix] \ and form_key in request.session[storage.prefix]['step_data'] @@ -541,12 +542,13 @@ class Wizard(NamedUrlWizardView): form_key + '-0-' + key #only check if the first field is available return key in request.session[storage.prefix]['step_data'][form_key] - @classmethod - def session_get_value(cls, request, storage, form_key, key, multi=False): + def session_get_value(self, form_key, key, multi=False): """Get the value of a specific form""" print "18" - if not cls.session_has_key(request, storage, form_key, key, multi): + if not self.session_has_key(form_key, key, multi): return + request = self.request + storage = self.storage if not multi: key = key.startswith(form_key) and key or form_key + '-' + key return request.session[storage.prefix]['step_data'][form_key][key] @@ -564,8 +566,7 @@ class Wizard(NamedUrlWizardView): current_obj = None main_form_key = 'selec-' + self.url_name try: - idx = self.session_get_value(self.request, self.storage, - main_form_key, 'pk') + idx = self.session_get_value(main_form_key, 'pk') if type(idx) in (tuple, list): idx = idx[0] idx = int(idx) @@ -588,12 +589,12 @@ class Wizard(NamedUrlWizardView): self.storage.reset() val = model_name in request.session and request.session[model_name] if val: - return {'pk':val} + return MultiValueDict({'pk':val}) elif current_obj: return self.get_instanced_init(current_obj, step) current_form = self.form_list[current_step] if hasattr(current_form, 'currents'): - initial = {} + initial = MultiValueDict() for key in current_form.currents: model_name = current_form.currents[key].__name__.lower() val = model_name in request.session and \ @@ -616,11 +617,11 @@ class Wizard(NamedUrlWizardView): if len(prefixes) > 1 and prefixes[-2].startswith(obj_name): obj_name = prefixes[-2] self.request.session[obj_name] = unicode(obj.pk) - initial = {} + initial = MultiValueDict() if self.request.POST or \ (step in self.request.session[self.storage.prefix] and\ self.request.session[self.storage.prefix]['step_data'][step]): - return {} + return initial if hasattr(c_form, 'base_fields'): for base_field in c_form.base_fields.keys(): fields = base_field.split('__') @@ -723,11 +724,11 @@ class DeletionWizard(Wizard): datas[0][1].append(res[field]) return datas - def done(self, request, storage, form_list, **kwargs): - obj = self.get_current_object(request, storage) + def done(self, form_list, **kwargs): + obj = self.get_current_object() obj.delete() return render_to_response('wizard_delete_done.html', {}, - context_instance=RequestContext(request)) + context_instance=RequestContext(self.request)) class ClosingWizard(Wizard): # "close" an item @@ -769,15 +770,15 @@ class ClosingWizard(Wizard): datas[0][1].append(res[field]) return datas - def done(self, request, storage, form_list, **kwargs): - obj = self.get_current_object(request, storage) + def done(self, form_list, **kwargs): + obj = self.get_current_object() for form in form_list: if form.is_valid(): if 'end_date' in form.cleaned_data and hasattr(obj, 'end_date'): obj.end_date = form.cleaned_data['end_date'] obj.save() return render_to_response('wizard_closing_done.html', {}, - context_instance=RequestContext(request)) + context_instance=RequestContext(self.request)) class PersonWizard(Wizard): model = models.Person @@ -863,16 +864,15 @@ class AccountWizard(Wizard): form = super(AccountWizard, self).get_form(step, data, files) if not hasattr(form, 'is_hidden'): return form - if self.session_get_value(self.request, self.storage, - 'account-account_management', 'hidden_password'): + if self.session_get_value('account-account_management', + 'hidden_password'): form.is_hidden = False return form class SourceWizard(Wizard): model = None - def get_extra_model(self, dct, request, storage, form_list): - dct = super(SourceWizard, self).get_extra_model(dct, request, storage, - form_list) + def get_extra_model(self, dct, form_list): + dct = super(SourceWizard, self).get_extra_model(dct, form_list) if 'history_modifier' in dct: dct.pop('history_modifier') return dct |