diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-01 15:50:52 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-12 09:57:24 +0200 |
commit | 7343c9f1bbc28be270b2093dcd9e713a7bdcdb89 (patch) | |
tree | 0ed9392291c50980c7dbff14c9a05edc601076de /archaeological_operations | |
parent | 10b603af68689ea3b251006b7ec05855b9616811 (diff) | |
download | Ishtar-7343c9f1bbc28be270b2093dcd9e713a7bdcdb89.tar.bz2 Ishtar-7343c9f1bbc28be270b2093dcd9e713a7bdcdb89.zip |
Adapt forms, wizards, views, urls for new management of documents (refs #4107)
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/admin.py | 14 | ||||
-rw-r--r-- | archaeological_operations/forms.py | 122 | ||||
-rw-r--r-- | archaeological_operations/ishtar_menu.py | 24 | ||||
-rw-r--r-- | archaeological_operations/models.py | 120 | ||||
-rw-r--r-- | archaeological_operations/templates/ishtar/sheet_operation.html | 6 | ||||
-rw-r--r-- | archaeological_operations/urls.py | 25 | ||||
-rw-r--r-- | archaeological_operations/views.py | 71 | ||||
-rw-r--r-- | archaeological_operations/wizards.py | 48 |
8 files changed, 45 insertions, 385 deletions
diff --git a/archaeological_operations/admin.py b/archaeological_operations/admin.py index d906b9faf..e10c962ca 100644 --- a/archaeological_operations/admin.py +++ b/archaeological_operations/admin.py @@ -122,20 +122,6 @@ class OperationAdmin(HistorizedObjectAdmin): admin_site.register(models.Operation, OperationAdmin) -class OperationSourceAdmin(admin.ModelAdmin): - list_display = ('operation', 'title', 'source_type',) - list_filter = ('source_type',) - search_fields = ('title', 'operation__common_name') - model = models.OperationSource - form = make_ajax_form( - model, {'operation': 'operation', - 'authors': 'author'} - ) - - -admin_site.register(models.OperationSource, OperationSourceAdmin) - - class ParcelAdmin(HistorizedObjectAdmin): list_display = ['section', 'parcel_number', 'operation', 'associated_file'] search_fields = ('operation__cached_label', diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 6aa1da77b..cbaa37310 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -20,41 +20,34 @@ """ Operations forms definitions """ -from collections import OrderedDict import datetime +from collections import OrderedDict from itertools import groupby from django import forms from django.conf import settings from django.core import validators from django.db.models import Max - from django.forms.formsets import formset_factory, DELETION_FIELD_NAME, \ TOTAL_FORM_COUNT -from django.utils.translation import ugettext_lazy as _, pgettext_lazy from django.utils.safestring import mark_safe +from django.utils.translation import ugettext_lazy as _, pgettext_lazy +import models +from archaeological_files.models import File +from archaeological_operations.utils import parse_parcels +from bootstrap_datepicker.widgets import DateField +from ishtar_common import widgets +from ishtar_common.forms import FinalForm, FormSet, get_now, \ + reverse_lazy, TableSelect, get_data_from_formset, \ + ManageOldType, IshtarForm, CustomForm, FieldType +from ishtar_common.forms_common import TownFormSet, get_town_field, TownForm from ishtar_common.models import valid_id, Person, Town, \ DocumentTemplate, Organization, get_current_profile, \ person_type_pks_lazy, person_type_pk_lazy, organization_type_pks_lazy, \ organization_type_pk_lazy - from ishtar_common.wizards import MultiValueDict -from bootstrap_datepicker.widgets import DateField - -from archaeological_files.models import File -import models - from widgets import ParcelWidget, SelectParcelWidget, OAWidget -from ishtar_common import widgets - -from ishtar_common.forms import FinalForm, FormSet, get_now, \ - reverse_lazy, get_form_selection, TableSelect, get_data_from_formset, \ - ManageOldType, IshtarForm, CustomForm, FieldType, FormSetWithDeleteSwitches -from ishtar_common.forms_common import TownFormSet, SourceForm, SourceSelect, \ - get_town_field, TownForm, BaseImageForm, BaseImageFormset - -from archaeological_operations.utils import parse_parcels class ParcelField(forms.MultiValueField): @@ -1022,14 +1015,6 @@ class CollaboratorForm(CustomForm, IshtarForm): self.fields['collaborator'].widget.attrs['full-width'] = True -ImagesFormset = formset_factory(BaseImageForm, can_delete=True, - formset=BaseImageFormset) -ImagesFormset.file_upload = True -ImagesFormset.form_label = _(u"Images") -ImagesFormset.form_admin_name = _(u"Operation - 025 - Images") -ImagesFormset.form_slug = "operation-025-images" - - class OperationFormPreventive(CustomForm, IshtarForm): form_label = _(u"Preventive informations - excavation") form_admin_name = _(u"Operation - 033 - Preventive - Excavation") @@ -1348,14 +1333,6 @@ SiteTownFormset.form_admin_name = _(u"Archaeological site - 020 - Towns") SiteTownFormset.form_slug = u"archaeological_site-020-towns" -SiteImagesFormset = formset_factory(BaseImageForm, can_delete=True, - formset=BaseImageFormset) -SiteImagesFormset.file_upload = True -SiteImagesFormset.form_label = _(u"Images") -SiteImagesFormset.form_admin_name = _(u"Archaeological site - 025 - Images") -SiteImagesFormset.form_slug = "archaeological_site-025-images" - - def check_underwater_module(self): return get_current_profile().underwater @@ -1379,83 +1356,6 @@ class SiteUnderwaterForm(ManageOldType): ) -#################################### -# Source management for operations # -#################################### - - -class OperationSourceForm(SourceForm): - form_slug = "operationsource-general" - pk = forms.IntegerField(required=False, widget=forms.HiddenInput) - index = forms.IntegerField(label=_(u"Index")) - hidden_operation_id = forms.IntegerField(label="", - widget=forms.HiddenInput) - - def __init__(self, *args, **kwargs): - super(OperationSourceForm, self).__init__(*args, **kwargs) - fields = OrderedDict() - idx = self.fields.pop('index') - for key, value in self.fields.items(): - fields[key] = value - if key == 'source_type': - fields['index'] = idx - self.fields = fields - - def clean(self): - # manage unique operation ID - cleaned_data = self.cleaned_data - operation_id = cleaned_data.get("hidden_operation_id") - index = cleaned_data.get("index") - srcs = models.OperationSource.objects\ - .filter(index=index, - operation__pk=operation_id) - if 'pk' in cleaned_data and cleaned_data['pk']: - srcs = srcs.exclude(pk=cleaned_data['pk']) - if srcs.count(): - max_val = models.OperationSource.objects\ - .filter(operation__pk=operation_id)\ - .aggregate(Max('index'))["index__max"] - operation = models.Operation.objects.get(pk=operation_id) - raise forms.ValidationError( - _(u"Index already exists for operation: %(operation)s - use a " - u"value bigger than %(last_val)d") % { - "operation": unicode(operation), 'last_val': max_val}) - return cleaned_data - - -SourceOperationFormSelection = get_form_selection( - 'SourceOperationFormSelection', _(u"Operation search"), 'operation', - models.Operation, OperationSelect, 'get-operation', - _(u"You should select an operation.")) - - -class OperationSourceSelect(SourceSelect): - operation__year = forms.IntegerField(label=_(u"Operation's year")) - operation__operation_code = forms.IntegerField( - label=_(u"Numeric reference")) - if settings.COUNTRY == 'fr': - operation__code_patriarche = forms.CharField( - max_length=500, - widget=OAWidget, - label="Code PATRIARCHE") - operation__towns = get_town_field(label=_(u"Operation's town")) - operation__operation_type = forms.ChoiceField(label=_(u"Operation type"), - choices=[]) - - def __init__(self, *args, **kwargs): - super(OperationSourceSelect, self).__init__(*args, **kwargs) - self.fields['operation__operation_type'].choices = \ - models.OperationType.get_types() - self.fields['operation__operation_type'].help_text = \ - models.OperationType.get_help() - - -OperationSourceFormSelection = get_form_selection( - 'OperationSourceFormSelection', _(u"Documentation search"), 'pk', - models.OperationSource, OperationSourceSelect, 'get-operationsource', - _(u"You should select a document."), - get_full_url='get-operationsource-full') - ################################################ # Administrative act management for operations # ################################################ diff --git a/archaeological_operations/ishtar_menu.py b/archaeological_operations/ishtar_menu.py index 2e1c7ac9c..e8815cbb8 100644 --- a/archaeological_operations/ishtar_menu.py +++ b/archaeological_operations/ishtar_menu.py @@ -161,30 +161,6 @@ MENU_SECTIONS = [ model=models.AdministrativeAct, access_controls=['change_administrativeact']), ],), - SectionItem( - 'operation_source', _(u"Documentation"), - childs=[ - MenuItem('operation_source_search', - _(u"Search"), - model=models.OperationSource, - access_controls=['view_operation', - 'view_own_operation']), - MenuItem('operation_source_creation', - _(u"Creation"), - model=models.OperationSource, - access_controls=['change_operation', - 'change_own_operation']), - MenuItem('operation_source_modification', - _(u"Modification"), - model=models.OperationSource, - access_controls=['change_operation', - 'change_own_operation']), - MenuItem('operation_source_deletion', - _(u"Deletion"), - model=models.OperationSource, - access_controls=['change_operation', - 'change_own_operation']), - ]) ]), ), ( diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index de58e0da7..e2e3422fa 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -27,15 +27,15 @@ from django.db import IntegrityError, transaction from django.db.models import Q, Count, Sum, Max, Avg from django.db.models.signals import post_save, m2m_changed, post_delete from django.forms import ValidationError -from django.utils.translation import ugettext_lazy as _, ugettext +from django.utils.translation import ugettext_lazy as _ -from ishtar_common.models import BaseHistorizedItem, BaseSource, Dashboard, \ +from ishtar_common.models import BaseHistorizedItem, Dashboard, \ DashboardFormItem, Department, Document, DocumentTemplate, \ GeneralRecordRelations, GeneralRelationType, GeneralType, \ - HistoricalRecords, IshtarImage, IshtarUser, LightHistorizedItem, \ + HistoricalRecords, IshtarUser, LightHistorizedItem, \ OperationType, Organization, OwnPerms, Person, PersonType, \ post_delete_record_relation, post_save_cache, RelationItem, \ - ShortMenuItem, SourceType, ThroughImage, Town, ValueGetter + ShortMenuItem, SourceType, Town, ValueGetter from ishtar_common.utils import cached_label_changed, \ force_cached_label_changed, mode @@ -131,8 +131,6 @@ class ArchaeologicalSite(BaseHistorizedItem): documents = models.ManyToManyField( Document, related_name="sites", verbose_name=_(u"Documents"), blank=True) - images = models.ManyToManyField(IshtarImage, verbose_name=_(u"Images"), - through='SiteImage', blank=True) class Meta: verbose_name = _(u"Archaeological site") @@ -221,11 +219,6 @@ class ArchaeologicalSite(BaseHistorizedItem): ) -class SiteImage(ThroughImage): - item = models.ForeignKey(ArchaeologicalSite, on_delete=models.CASCADE, - related_name='associated_images') - - def get_values_town_related(item, prefix, values): values[prefix + 'parcellist'] = item.render_parcels() values[prefix + 'towns'] = '' @@ -464,8 +457,6 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, documents = models.ManyToManyField( Document, related_name='operations', verbose_name=_(u"Documents"), blank=True) - images = models.ManyToManyField(IshtarImage, verbose_name=_(u"Images"), - blank=True, through='OperationImage') cached_label = models.CharField(_(u"Cached name"), max_length=500, null=True, blank=True, db_index=True) archaeological_sites = models.ManyToManyField( @@ -642,14 +633,12 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, return CRRL.objects.filter(left_record__operation=self) def context_record_docs_q(self): - from archaeological_context_records.models import ContextRecordSource - return ContextRecordSource.objects.filter( - context_record__operation=self) + return Document.objects.filter( + context_records__operation=self) def find_docs_q(self): - from archaeological_finds.models import FindSource - return FindSource.objects.filter( - find__base_finds__context_record__operation=self) + return Document.objects.filter( + finds__base_finds__context_record__operation=self) def containers_q(self): from archaeological_warehouse.models import Container @@ -885,13 +874,11 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, return self._get_or_set_stats('_nb_documents', update) def _nb_documents(self): - from archaeological_context_records.models import ContextRecordSource - from archaeological_finds.models import FindSource - nbs = self.source.count() + \ - ContextRecordSource.objects.filter( - context_record__operation=self).count() + \ - FindSource.objects.filter( - find__base_finds__context_record__operation=self).count() + nbs = self.documents.count() + \ + Document.objects.filter( + context_records__operation=self).count() + \ + Document.objects.filter( + finds__base_finds__context_record__operation=self).count() return nbs @property @@ -899,16 +886,14 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, return self._get_or_set_stats('_nb_documents_by_types', update) def _nb_documents_by_types(self): - from archaeological_context_records.models import ContextRecordSource - from archaeological_finds.models import FindSource docs = {} qs = [ - self.source, - ContextRecordSource.objects.filter(context_record__operation=self), - FindSource.objects.filter( - find__upstream_treatment_id__isnull=True, - find__base_finds__context_record__operation=self)] + self.documents, + Document.objects.filter(context_records__operation=self), + Document.objects.filter( + finds__upstream_treatment_id__isnull=True, + finds__base_finds__context_record__operation=self)] for q in qs: for res in q.values('source_type').distinct(): st = res['source_type'] @@ -982,11 +967,6 @@ def operation_post_save(sender, **kwargs): post_save.connect(operation_post_save, sender=Operation) -class OperationImage(ThroughImage): - item = models.ForeignKey(Operation, on_delete=models.CASCADE, - related_name='associated_images') - - class RelationType(GeneralRelationType): class Meta: @@ -1044,70 +1024,6 @@ class OperationByDepartment(models.Model): db_table = 'operation_department' -class OperationSource(BaseSource): - SHOW_URL = 'show-operationsource' - MODIFY_URL = 'operation_source_modify' - TABLE_COLS = ['operation__code_patriarche', 'operation__year', - 'operation__operation_code', 'code'] + BaseSource.TABLE_COLS - - # search parameters - BOOL_FIELDS = ['duplicate'] - EXTRA_REQUEST_KEYS = { - 'title': 'title__icontains', - 'description': 'description__icontains', - 'comment': 'comment__icontains', - 'additional_information': 'additional_information__icontains', - 'person': 'authors__person__pk', - 'operation__towns': 'operation__towns__pk', - 'operation__operation_code': 'operation__operation_code', - 'operation__code_patriarche': 'operation__code_patriarche', - 'operation__operation_type': 'operation__operation_type__pk', - 'operation__year': 'operation__year'} - COL_LABELS = { - 'operation__year': _(u"Operation year"), - 'operation__operation_code': _(u"Operation code"), - 'code': _(u"Document code") - } - PARENT_SEARCH_VECTORS = BaseSource.PARENT_SEARCH_VECTORS + ['operation'] - - # fields - operation = models.ForeignKey(Operation, verbose_name=_(u"Operation"), - related_name="source") - - class Meta: - verbose_name = _(u"Operation documentation") - verbose_name_plural = _(u"Operation documentations") - permissions = ( - ("view_operationsource", - ugettext(u"Can view all Operation sources")), - ("view_own_operationsource", - ugettext(u"Can view own Operation source")), - ("add_own_operationsource", - ugettext(u"Can add own Operation source")), - ("change_own_operationsource", - ugettext(u"Can change own Operation source")), - ("delete_own_operationsource", - ugettext(u"Can delete own Operation source")), - ) - - @property - def owner(self): - return self.operation - - @property - def code(self): - if not self.index: - return u"{}-".format(self.operation.code_patriarche or '') - return u"{}-{:04d}".format(self.operation.code_patriarche or '', - self.index) - - @classmethod - def get_query_owns(cls, ishtaruser): - return cls._construct_query_own( - 'operation__', Operation._get_query_owns_dicts(ishtaruser) - ) - - class ActType(GeneralType): TYPE = (('F', _(u'Archaeological file')), ('O', _(u'Operation')), diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html index f3014eaf4..7a6c36a11 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation.html +++ b/archaeological_operations/templates/ishtar/sheet_operation.html @@ -189,10 +189,12 @@ {% table_administrativact "" item.administrative_act.all %} {% endif %} +{% comment %} {% trans "Document from this operation" as operation_docs %} {% if item.source.count %} {% dynamic_table_document operation_docs 'operation_docs' 'operation' item.pk '' output %} {% endif %} +{% endcomment %} {% if item.context_record.count %} {% trans "Context records" as cr_lab %} @@ -204,20 +206,24 @@ {% dynamic_table_document cr_rels 'context_records_relations_detail' 'left_record__operation' item.pk '' output %} {% endif %} +{% comment %} {% if item.context_record_docs_q.count %} {% trans "Documents from associated context records" as cr_docs %} {% dynamic_table_document cr_docs 'context_records_docs' 'context_record__operation' item.pk '' output %} {% endif %} +{% endcomment %} {% if item.finds %} {% trans "Finds" as finds %} {% dynamic_table_document finds 'finds_for_ope' 'base_finds__context_record__operation' item.pk 'TABLE_COLS_FOR_OPE' output %} {% endif %} +{% comment %} {% if item.find_docs_q.count %} {% trans "Documents from associated finds" as finds_docs %} {% dynamic_table_document finds_docs 'finds_docs' 'find__base_finds__context_record__operation' item.pk '' output %} {% endif %} +{% endcomment %} {% if item.containers_q.count %} {% trans "Associated containers" as containers_lbl %} diff --git a/archaeological_operations/urls.py b/archaeological_operations/urls.py index f904d58b7..6b9a980b4 100644 --- a/archaeological_operations/urls.py +++ b/archaeological_operations/urls.py @@ -46,24 +46,6 @@ urlpatterns = [ check_rights(['change_administrativeact'])( views.operation_administrativeactop_deletion_wizard), name='operation_administrativeactop_deletion'), - url(r'operation_source_search/(?P<step>.+)?$', - check_rights(['view_operation', 'view_own_operation'])( - views.operation_source_search_wizard), - name='operation_source_search'), - url(r'operation_source_creation/(?P<step>.+)?$', - check_rights(['change_operation', 'change_own_operation'])( - views.operation_source_creation_wizard), - name='operation_source_creation'), - url(r'operation_source_modification/(?P<step>.+)?$', - check_rights(['change_operation', 'change_own_operation'])( - views.operation_source_modification_wizard), - name='operation_source_modification'), - url(r'operation_source_modify/(?P<pk>.+)/$', - views.operation_source_modify, name='operation_source_modify'), - url(r'operation_source_deletion/(?P<step>.+)?$', - check_rights(['change_operation', 'change_own_operation'])( - views.operation_source_deletion_wizard), - name='operation_source_deletion'), url(r'operation_search/(?P<step>.+)?$', check_rights(['view_operation', 'view_own_operation'])( views.operation_search_wizard), name='operation_search'), @@ -137,13 +119,6 @@ urlpatterns = [ url(r'generatedoc-administrativeactop/(?P<pk>.+)?/(?P<template_pk>.+)?$', views.generatedoc_administrativeactop, name='generatedoc-administrativeactop'), - url(r'show-operationsource(?:/(?P<pk>.+))?/(?P<type>.+)?$', - views.show_operationsource, name=models.OperationSource.SHOW_URL), - url(r'get-operationsource/(?P<type>.+)?$', - views.get_operationsource, name='get-operationsource'), - url(r'get-operationsource-full/(?P<type>.+)?$', - views.get_operationsource, name='get-operationsource-full', - kwargs={'full': True}), url(r'dashboard_operation/$', views.dashboard_operation, name='dashboard-operation'), diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index ea863bb36..97824843f 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -26,12 +26,7 @@ from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render, redirect from django.utils.translation import ugettext_lazy as _, pgettext_lazy -from ishtar_common.models import get_current_profile, IshtarSiteProfile from archaeological_operations import models - -from ishtar_common.forms import ClosingDateFormSelection, FinalForm, \ - FinalDeleteForm -from ishtar_common.forms_common import AuthorFormset, SourceDeletionForm from archaeological_operations.forms import ArchaeologicalSiteForm, \ OperationFormSelection, OperationFormFileChoice, OperationFormGeneral, \ OperationFormModifGeneral, FinalOperationClosingForm, \ @@ -39,26 +34,24 @@ from archaeological_operations.forms import ArchaeologicalSiteForm, \ OperationFormPreventiveDiag, TownFormset, SelectedTownFormset, \ SelectedParcelGeneralFormSet, SelectedParcelFormSet, RemainForm, \ PeriodForm, RecordRelationsFormSet, OperationFormAbstract, \ - OperationDeletionForm, SiteFormSelection, OperationSourceFormSelection, \ - SourceOperationFormSelection, OperationSourceForm, \ + OperationDeletionForm, SiteFormSelection, \ AdministrativeActOpeFormSelection, AdministrativeActOpeForm, \ AdministrativeActOpeModifForm, FinalAdministrativeActDeleteForm, \ AdministrativeActRegisterFormSelection, DocumentGenerationAdminActForm, \ SiteForm, SiteTownFormset, SiteUnderwaterForm, check_underwater_module, \ - CourtOrderedSeizureForm, ImagesFormset, SiteImagesFormset - -from ishtar_common.views import get_item, show_item, revert_item, new_item - -from ishtar_common.wizards import SearchWizard, check_rights_condition + CourtOrderedSeizureForm from archaeological_operations.wizards import has_associated_file, \ is_preventive, is_judiciary, OperationWizard, OperationModificationWizard, \ OperationClosingWizard, OperationDeletionWizard, SiteSearch, \ - OperationSourceWizard, OperationSourceDeletionWizard, \ OperationAdministrativeActWizard, OperationEditAdministrativeActWizard, \ AdministrativeActDeletionWizard, SiteWizard, SiteModificationWizard, \ SiteDeletionWizard - +from ishtar_common.forms import ClosingDateFormSelection, FinalForm, \ + FinalDeleteForm +from ishtar_common.models import get_current_profile, IshtarSiteProfile from ishtar_common.utils import put_session_message +from ishtar_common.views import get_item, show_item, revert_item, new_item +from ishtar_common.wizards import SearchWizard, check_rights_condition def autocomplete_patriarche(request): @@ -164,10 +157,6 @@ get_operation = get_item(models.Operation, 'get_operation', 'operation') show_operation = show_item(models.Operation, 'operation') revert_operation = revert_item(models.Operation) -show_operationsource = show_item(models.OperationSource, 'operationsource') -get_operationsource = get_item(models.OperationSource, 'get_operationsource', - 'operationsource') - get_administrativeactop = get_item( models.AdministrativeAct, 'get_administrativeactop', 'administrativeactop') @@ -197,7 +186,6 @@ wizard_steps = [ ('general-operation_creation', OperationFormGeneral), ('judiciary-operation_creation', CourtOrderedSeizureForm), ('collaborators-operation_creation', CollaboratorForm), - ('images-operation_creation', ImagesFormset), ('archaeologicalsite-operation_creation', ArchaeologicalSiteFormSet), ('preventive-operation_creation', OperationFormPreventive), ('preventivediag-operation_creation', OperationFormPreventiveDiag), @@ -260,7 +248,6 @@ operation_modif_wizard_steps = [ ('general-operation_modification', OperationFormModifGeneral), ('judiciary-operation_modification', CourtOrderedSeizureForm), ('collaborators-operation_modification', CollaboratorForm), - ('images-operation_modification', ImagesFormset), ('archaeologicalsite-operation_modification', ArchaeologicalSiteFormSet), ('preventive-operation_modification', OperationFormPreventive), ('preventivediag-operation_modification', OperationFormPreventiveDiag), @@ -373,7 +360,6 @@ site_search_wizard = SiteSearch.as_view( site_creation_steps = [ ('general-site_creation', SiteForm), ('towns-site_creation', SiteTownFormset), - ('images-site_creation', SiteImagesFormset), ('underwater-site_creation', SiteUnderwaterForm), ('final-site_creation', FinalForm) ] @@ -388,7 +374,6 @@ site_modification_steps = [ ('selec-site_modification', SiteFormSelection), ('general-site_modification', SiteForm), ('towns-site_modification', SiteTownFormset), - ('images-site_modification', SiteImagesFormset), ('underwater-site_modification', SiteUnderwaterForm), ('final-site_modification', FinalForm) ] @@ -418,48 +403,6 @@ site_deletion_wizard = SiteDeletionWizard.as_view( label=_(u"Site deletion"), url_name='site_deletion',) -# operation sources - -operation_source_search_wizard = SearchWizard.as_view([ - ('selec-operation_source_search', OperationSourceFormSelection)], - label=_(u"Operation: source search"), - url_name='operation_source_search',) - -operation_source_creation_wizard = OperationSourceWizard.as_view([ - ('selec-operation_source_creation', SourceOperationFormSelection), - ('source-operation_source_creation', OperationSourceForm), - ('authors-operation_source_creation', AuthorFormset), - ('final-operation_source_creation', FinalForm)], - label=_(u"Operation: source creation"), - url_name='operation_source_creation',) - -operation_source_modification_steps = [ - ('selec-operation_source_modification', OperationSourceFormSelection), - ('source-operation_source_modification', OperationSourceForm), - ('authors-operation_source_modification', AuthorFormset), - ('final-operation_source_modification', FinalForm) -] - -operation_source_modification_wizard = OperationSourceWizard.as_view( - operation_source_modification_steps, - label=_(u"Operation: source modification"), - url_name='operation_source_modification',) - - -def operation_source_modify(request, pk): - operation_source_modification_wizard(request) - OperationSourceWizard.session_set_value( - request, 'selec-operation_source_modification', 'pk', pk, reset=True) - return redirect(reverse( - 'operation_source_modification', - kwargs={'step': 'source-operation_source_modification'})) - -operation_source_deletion_wizard = OperationSourceDeletionWizard.as_view([ - ('selec-operation_source_deletion', OperationSourceFormSelection), - ('final-operation_source_deletion', SourceDeletionForm)], - label=_(u"Operation: source deletion"), - url_name='operation_source_deletion',) - operation_administrativeactop_search_wizard = SearchWizard.as_view([ ('general-operation_administrativeactop_search', AdministrativeActOpeFormSelection)], diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index d4830a2e7..a8f8ef80b 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -22,21 +22,17 @@ import logging from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse -from django.db.models import Max from django.http import Http404 from django.shortcuts import render from django.utils.translation import ugettext_lazy as _ -from ishtar_common.models import get_current_profile from archaeological_files.models import File from archaeological_operations import models - -from ishtar_common.forms import reverse_lazy from forms import GenerateDocForm - +from ishtar_common.forms import reverse_lazy +from ishtar_common.models import get_current_profile from ishtar_common.wizards import Wizard, ClosingWizard, DeletionWizard, \ - SourceWizard, SearchWizard - + SearchWizard logger = logging.getLogger(__name__) @@ -303,44 +299,6 @@ class OperationDeletionWizard(DeletionWizard): filter_owns = {'selec-operation_deletion': ['pk']} -class OperationSourceWizard(SourceWizard): - model = models.OperationSource - wizard_done_window = reverse_lazy('show-operationsource') - - def get_form_initial(self, step, data=None): - 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-'): - operation_id = None - if self.session_has_key(general_form_key, 'operation'): - try: - operation_id = int(self.session_get_value(general_form_key, - "operation")) - except ValueError: - pass - elif self.session_has_key(general_form_key, "pk"): - try: - pk = self.session_get_value(general_form_key, "pk") - source = models.OperationSource.objects.get(pk=pk) - operation_id = source.operation.pk - except (ValueError, ObjectDoesNotExist): - pass - if operation_id: - initial['hidden_operation_id'] = operation_id - if 'index' not in initial: - max_val = models.OperationSource.objects.filter( - operation__pk=operation_id).aggregate( - Max('index'))["index__max"] - initial['index'] = max_val and (max_val + 1) or 1 - return initial - - -class OperationSourceDeletionWizard(DeletionWizard): - model = models.OperationSource - fields = ['operation', 'title', 'source_type', 'authors'] - - class OperationAdministrativeActWizard(OperationWizard): edit = False wizard_done_window = reverse_lazy('show-administrativeact') |