diff options
42 files changed, 370 insertions, 1588 deletions
diff --git a/archaeological_context_records/admin.py b/archaeological_context_records/admin.py index c06927f37..1f08bc505 100644 --- a/archaeological_context_records/admin.py +++ b/archaeological_context_records/admin.py @@ -65,20 +65,8 @@ class ContextRecordAdmin(HistorizedObjectAdmin): 'cached_label', 'datings' ] -admin_site.register(models.ContextRecord, ContextRecordAdmin) - - -class ContextRecordSourceAdmin(admin.ModelAdmin): - list_display = ('context_record', 'title', 'source_type',) - list_filter = ('source_type',) - search_fields = ('title', ) - model = models.ContextRecordSource - form = make_ajax_form(model, { - "context_record": 'context_record', - 'authors': 'author' - }) -admin_site.register(models.ContextRecordSource, ContextRecordSourceAdmin) +admin_site.register(models.ContextRecord, ContextRecordAdmin) class RecordRelationsAdmin(admin.ModelAdmin): diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 0d68d6aa3..3238eb771 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -28,21 +28,19 @@ from django.core import validators from django.forms.formsets import formset_factory from django.utils.translation import ugettext_lazy as _ -from ishtar_common.models import valid_id, IshtarSiteProfile, Town +import models +from archaeological_operations.forms import OperationSelect, ParcelField, \ + RecordRelationsForm as OpeRecordRelationsForm, RecordRelationsFormSetBase from archaeological_operations.models import Period, Parcel, Operation, \ ArchaeologicalSite, RelationType as OpeRelationType -import models - -from ishtar_common import widgets -from bootstrap_datepicker.widgets import DatePicker from archaeological_operations.widgets import OAWidget +from bootstrap_datepicker.widgets import DatePicker +from ishtar_common import widgets from ishtar_common.forms import FinalForm, FormSet, \ reverse_lazy, get_form_selection, TableSelect, ManageOldType, CustomForm, \ FieldType -from ishtar_common.forms_common import get_town_field, SourceSelect, \ - BaseImageForm, BaseImageFormset, SourceForm -from archaeological_operations.forms import OperationSelect, ParcelField,\ - RecordRelationsForm as OpeRecordRelationsForm, RecordRelationsFormSetBase +from ishtar_common.forms_common import get_town_field +from ishtar_common.models import valid_id, IshtarSiteProfile, Town class OperationFormSelection(CustomForm, forms.Form): @@ -282,14 +280,6 @@ class RecordFormGeneral(CustomForm, ManageOldType): return cleaned_data -ImagesFormset = formset_factory(BaseImageForm, can_delete=True, - formset=BaseImageFormset) -ImagesFormset.file_upload = True -ImagesFormset.form_label = _(u"Images") -ImagesFormset.form_admin_name = _(u"Context record - 025 - Images") -ImagesFormset.form_slug = "contextrecord-025-images" - - class DatingForm(ManageOldType, forms.Form): form_label = _("Dating") base_model = 'dating' @@ -385,50 +375,3 @@ class RecordDeletionForm(FinalForm): confirm_msg = " " confirm_end_msg = _(u"Would you like to delete this context record?") -######################################### -# Source management for context records # -######################################### - - -SourceRecordFormSelection = get_form_selection( - 'SourceRecordFormSelection', _(u"Context record search"), - 'context_record', models.ContextRecord, RecordSelect, 'get-contextrecord', - _(u"You should select a context record.")) - - -class RecordSourceSelect(SourceSelect): - context_record__operation__year = forms.IntegerField( - label=_(u"Year of the operation")) - context_record__operation__operation_code = forms.IntegerField( - label=_(u"Numeric reference")) - if settings.COUNTRY == 'fr': - context_record__operation__code_patriarche = forms.CharField( - max_length=500, - widget=OAWidget, - label="Code PATRIARCHE") - context_record__town = get_town_field( - label=_(u"Town")) - context_record__datings__period = forms.ChoiceField( - label=_(u"Period of the context record"), choices=[]) - context_record__unit = forms.ChoiceField( - label=_(u"Context record type"), choices=[]) - - def __init__(self, *args, **kwargs): - super(RecordSourceSelect, self).__init__(*args, **kwargs) - self.fields['context_record__datings__period'].choices = \ - Period.get_types() - self.fields['context_record__datings__period'].help_text = \ - Period.get_help() - self.fields['context_record__unit'].choices = models.Unit.get_types() - self.fields['context_record__unit'].help_text = models.Unit.get_help() - - -RecordSourceFormSelection = get_form_selection( - 'RecordSourceFormSelection', _(u"Documentation search"), 'pk', - models.ContextRecordSource, RecordSourceSelect, 'get-contextrecordsource', - _(u"You should select a document."), - get_full_url='get-contextrecordsource-full') - - -class ContextRecordSourceForm(SourceForm): - form_slug = "contextrecordsource-general" diff --git a/archaeological_context_records/ishtar_menu.py b/archaeological_context_records/ishtar_menu.py index 469f473e7..437b28fdd 100644 --- a/archaeological_context_records/ishtar_menu.py +++ b/archaeological_context_records/ishtar_menu.py @@ -45,32 +45,6 @@ MENU_SECTIONS = [ model=models.ContextRecord, access_controls=['delete_contextrecord', 'delete_own_contextrecord']), - SectionItem('record_source', _(u"Documentation"), - childs=[ - MenuItem('record_source_search', - _(u"Search"), - model=models.ContextRecordSource, - access_controls=['view_contextrecord', - 'view_own_contextrecord']), - MenuItem('record_source_creation', - _(u"Creation"), - model=models.ContextRecordSource, - access_controls=[ - 'change_contextrecord', - 'change_own_contextrecord']), - MenuItem('record_source_modification', - _(u"Modification"), - model=models.ContextRecordSource, - access_controls=[ - 'change_contextrecord', - 'change_own_contextrecord']), - MenuItem('record_source_deletion', - _(u"Deletion"), - model=models.ContextRecordSource, - access_controls=[ - 'change_contextrecord', - 'change_own_contextrecord']), - ]) ]) ) ] diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index b12a31516..11b7732f8 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -30,11 +30,11 @@ from django.utils.text import slugify from ishtar_common.utils import cached_label_changed -from ishtar_common.models import BaseSource, Document, GeneralType, \ +from ishtar_common.models import Document, GeneralType, \ BaseHistorizedItem, HistoricalRecords, OwnPerms, ShortMenuItem, \ GeneralRelationType, GeneralRecordRelations, post_delete_record_relation,\ - get_image_path, post_save_cache, ValueGetter, BulkUpdatedItem, \ - IshtarImage, RelationItem, ThroughImage, Town + post_save_cache, ValueGetter, BulkUpdatedItem, \ + RelationItem, Town from archaeological_operations.models import Operation, Period, Parcel, \ ArchaeologicalSite @@ -329,8 +329,6 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem, documents = models.ManyToManyField( Document, related_name='context_records', verbose_name=_(u"Documents"), blank=True) - images = models.ManyToManyField(IshtarImage, verbose_name=_(u"Images"), - blank=True, through='ContextRecordImage') cached_label = models.TextField(_(u"Cached name"), null=True, blank=True, db_index=True) PARENT_SEARCH_VECTORS = ['operation'] @@ -554,8 +552,7 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem, return u" ; ".join(crs) def find_docs_q(self): - from archaeological_finds.models import FindSource - return FindSource.objects.filter(find__base_finds__context_record=self) + return Document.objects.filter(finds__base_finds__context_record=self) def fix(self): """ @@ -575,11 +572,6 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem, post_save.connect(cached_label_changed, sender=ContextRecord) -class ContextRecordImage(ThroughImage): - item = models.ForeignKey(ContextRecord, on_delete=models.CASCADE, - related_name='associated_images') - - class RelationType(GeneralRelationType): class Meta: verbose_name = _(u"Relation type") @@ -679,72 +671,3 @@ class RecordRelationView(models.Model): def __unicode__(self): return u"{} \"{}\"".format(self.relation_type, self.right_record) - - -class ContextRecordSource(BaseSource): - SHOW_URL = 'show-contextrecordsource' - MODIFY_URL = 'record_source_modify' - TABLE_COLS = ['context_record__operation__cached_label', 'context_record']\ - + BaseSource.TABLE_COLS - COL_LABELS = {'context_record__operation__cached_label': _(u"Operation")} - - # search parameters - RELATIVE_SESSION_NAMES = [ - ('contextrecord', 'context_record__pk'), - ('operation', 'context_record__operation__pk'), - ('file', 'context_record__operation__associated_file__pk')] - BOOL_FIELDS = ['duplicate'] - EXTRA_REQUEST_KEYS = { - 'title': 'title__icontains', - 'description': 'description__icontains', - 'comment': 'comment__icontains', - 'person': 'authors__person__pk', - 'additional_information': 'additional_information__icontains', - 'context_record__town': 'context_record__town__pk', - 'context_record__operation__year': 'context_record__operation__year', - 'context_record__operation__operation_code': - 'context_record__operation__operation_code', - 'context_record__operation__code_patriarche': - 'context_record__operation__code_patriarche', - 'context_record__operation': 'context_record__operation__pk', - 'context_record__datings__period': - 'context_record__datings__period__pk', - 'context_record__unit': 'context_record__unit__pk', - } - PARENT_SEARCH_VECTORS = BaseSource.PARENT_SEARCH_VECTORS + [ - 'context_record'] - - class Meta: - verbose_name = _(u"Context record documentation") - verbose_name_plural = _(u"Context record documentations") - permissions = ( - ("view_contextrecordsource", - u"Can view all Context record sources"), - ("view_own_contextrecordsource", - u"Can view own Context record source"), - ("add_own_contextrecordsource", - u"Can add own Context record source"), - ("change_own_contextrecordsource", - u"Can change own Context record source"), - ("delete_own_contextrecordsource", - u"Can delete own Context record source"), - ) - context_record = models.ForeignKey( - ContextRecord, verbose_name=_(u"Context record"), - related_name="source") - - @property - def owner(self): - return self.context_record - - @classmethod - def get_query_owns(cls, ishtaruser): - q = cls._construct_query_own( - 'context_record__operation__', - Operation._get_query_owns_dicts(ishtaruser) - ) | cls._construct_query_own('', [ - {'context_record__history_creator': ishtaruser.user_ptr}, - {'context_record__operation__end_date__isnull': True} - ]) - return q - diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html index d8d89e3c2..c2666d615 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html @@ -158,19 +158,23 @@ </div> {% endif %} +{% comment %} {% trans "Document from this context record" as cr_docs %} {% if item.source.count %} {% dynamic_table_document cr_docs 'context_records_docs' 'context_record' item.pk '' output %} {% endif %} +{% endcomment %} {% trans "Finds" as finds %} {% if item.base_finds.count %} {% dynamic_table_document finds 'finds_for_ope' 'base_finds__context_record' item.pk 'TABLE_COLS_FOR_OPE' output %} {% endif %} +{% comment %} {% trans "Documents from associated finds" as finds_docs %} {% if item.find_docs_q.count %} {% dynamic_table_document finds_docs 'finds_docs' 'find__base_finds__context_record' item.pk '' output %} {% endif %} +{% endcomment %} {% endblock %} diff --git a/archaeological_context_records/urls.py b/archaeological_context_records/urls.py index 513e58543..5610150f1 100644 --- a/archaeological_context_records/urls.py +++ b/archaeological_context_records/urls.py @@ -42,24 +42,6 @@ urlpatterns = [ url(r'record_deletion/(?P<step>.+)?$', check_rights(['change_contextrecord', 'change_own_contextrecord'])( views.record_deletion_wizard), name='record_deletion'), - url(r'record_source_search/(?P<step>.+)?$', - check_rights(['view_contextrecord', 'view_own_contextrecord'])( - views.record_source_search_wizard), - name='record_source_search'), - url(r'record_source_creation/(?P<step>.+)?$', - check_rights(['change_contextrecord', 'change_own_contextrecord'])( - views.record_source_creation_wizard), - name='record_source_creation'), - url(r'record_source_modification/(?P<step>.+)?$', - check_rights(['change_contextrecord', 'change_own_contextrecord'])( - views.record_source_modification_wizard), - name='record_source_modification'), - url(r'record_source_modify/(?P<pk>.+)/$', - views.record_source_modify, name='record_source_modify'), - url(r'record_source_deletion/(?P<step>.+)?$', - check_rights(['change_contextrecord', 'change_own_contextrecord'])( - views.record_source_deletion_wizard), - name='record_source_deletion'), url(r'autocomplete-contextrecord/$', views.autocomplete_contextrecord, name='autocomplete-contextrecord'), url(r'show-contextrecord(?:/(?P<pk>.+))?/(?P<type>.+)?$', @@ -100,12 +82,4 @@ urlpatterns = [ url(r'get-contextrecordrelationdetail/(?P<type>.+)?$', views.get_contextrecordrelationdetail, name='get-contextrecordrelationdetail'), - url(r'show-contextrecordsource(?:/(?P<pk>.+))?/(?P<type>.+)?$', - views.show_contextrecordsource, - name=models.ContextRecordSource.SHOW_URL), - url(r'get-contexrecordsource/(?P<type>.+)?$', - views.get_contextrecordsource, name='get-contextrecordsource'), - url(r'get-contexrecordsource-full/(?P<type>.+)?$', - views.get_contextrecordsource, name='get-contextrecordsource-full', - kwargs={'full': True}), ] diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py index f1c3913c7..787b76b31 100644 --- a/archaeological_context_records/views.py +++ b/archaeological_context_records/views.py @@ -23,20 +23,17 @@ from django.core.urlresolvers import reverse from django.db.models import Q from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.shortcuts import redirect -from django.views.generic import RedirectView from django.utils.translation import ugettext_lazy as _ +from django.views.generic import RedirectView -from ishtar_common.forms_common import AuthorFormset +import models +from archaeological_operations.views import site_extra_context +from forms import * +from ishtar_common.utils import put_session_message from ishtar_common.views import get_item, show_item, revert_item, \ IshtarMixin, LoginRequiredMixin, display_item -from archaeological_operations.views import site_extra_context from ishtar_common.wizards import SearchWizard - -from ishtar_common.utils import put_session_message - from wizards import * -from forms import * -import models show_contextrecord = show_item( models.ContextRecord, 'contextrecord', @@ -83,13 +80,6 @@ get_contextrecord_for_ope = get_item( 'get_contextrecord', 'contextrecord', own_table_cols=models.ContextRecord.TABLE_COLS_FOR_OPE) -show_contextrecordsource = show_item(models.ContextRecordSource, - 'contextrecordsource') - -get_contextrecordsource = get_item( - models.ContextRecordSource, - 'get_contextrecordsource', 'contextrecordsource') - get_contextrecordrelation = get_item( models.RecordRelationView, 'get_contextrecordrelation', 'contextrecordrelation', specific_perms=['view_recordrelation'], @@ -108,7 +98,6 @@ record_search_wizard = SearchWizard.as_view([ record_creation_steps = [ ('selec-record_creation', OperationRecordFormSelection), ('general-record_creation', RecordFormGeneral), - ('images-record_creation', ImagesFormset), ('datings-record_creation', DatingFormSet), ('interpretation-record_creation', RecordFormInterpretation), ('relations-record_creation', RecordRelationsFormSet), @@ -125,7 +114,6 @@ record_modification_steps = [ ('selec-record_modification', RecordFormSelection), ('operation-record_modification', OperationFormSelection), ('general-record_modification', RecordFormGeneral), - ('images-record_modification', ImagesFormset), ('datings-record_modification', DatingFormSet), ('interpretation-record_modification', RecordFormInterpretation), ('relations-record_modification', RecordRelationsFormSet), @@ -161,51 +149,12 @@ record_deletion_wizard = RecordDeletionWizard.as_view([ label=_(u"Context record deletion"), url_name='record_deletion',) -record_source_search_wizard = SearchWizard.as_view([ - ('selec-record_source_search', RecordSourceFormSelection)], - label=_(u"Context record: source search"), - url_name='record_source_search',) - -record_source_creation_wizard = RecordSourceWizard.as_view([ - ('selec-record_source_creation', SourceRecordFormSelection), - ('source-record_source_creation', ContextRecordSourceForm), - ('authors-record_source_creation', AuthorFormset), - ('final-record_source_creation', FinalForm)], - label=_(u"Context record: new source"), - url_name='record_source_creation',) - -record_source_modification_wizard = RecordSourceWizard.as_view([ - ('selec-record_source_modification', RecordSourceFormSelection), - ('source-record_source_modification', ContextRecordSourceForm), - ('authors-record_source_modification', AuthorFormset), - ('final-record_source_modification', FinalForm)], - label=_(u"Context record: source modification"), - url_name='record_source_modification',) - - -def record_source_modify(request, pk): - record_source_modification_wizard(request) - RecordSourceWizard.session_set_value( - request, 'selec-record_source_modification', 'pk', pk, reset=True) - return redirect(reverse( - 'record_source_modification', - kwargs={'step': 'source-record_source_modification'})) - -record_source_deletion_wizard = RecordSourceDeletionWizard.as_view([ - ('selec-record_source_deletion', RecordSourceFormSelection), - ('final-record_source_deletion', RecordDeletionForm)], - label=_(u"Context record: source deletion"), - url_name='record_source_deletion',) - def reset_wizards(request): for wizard_class, url_name in ( (RecordWizard, 'record_creation'), (RecordModifWizard, 'record_modification'), - (RecordDeletionWizard, 'record_deletion'), - (RecordSourceWizard, 'record_source_creation'), - (RecordSourceWizard, 'record_source_modification'), - (RecordSourceDeletionWizard, 'record_source_deletion')): + (RecordDeletionWizard, 'record_deletion')): wizard_class.session_reset(request, url_name) diff --git a/archaeological_context_records/wizards.py b/archaeological_context_records/wizards.py index cbeb1c1d2..89750794c 100644 --- a/archaeological_context_records/wizards.py +++ b/archaeological_context_records/wizards.py @@ -20,9 +20,9 @@ from django.core.exceptions import ObjectDoesNotExist from django.utils.translation import ugettext_lazy as _ -from ishtar_common.forms import reverse_lazy -from ishtar_common.wizards import Wizard, DeletionWizard, SourceWizard import models +from ishtar_common.forms import reverse_lazy +from ishtar_common.wizards import Wizard, DeletionWizard class RecordWizard(Wizard): @@ -150,13 +150,3 @@ class RecordDeletionWizard(DeletionWizard): 'filling', 'interpretation', 'taq', 'taq_estimated', 'tpq', 'tpq_estimated'] filter_owns = {'selec-record_deletion': ['pk']} - - -class RecordSourceWizard(SourceWizard): - model = models.ContextRecordSource - wizard_done_window = reverse_lazy('show-contextrecordsource') - - -class RecordSourceDeletionWizard(DeletionWizard): - model = models.ContextRecordSource - fields = ['context_record', 'title', 'source_type', 'authors', ] diff --git a/archaeological_finds/admin.py b/archaeological_finds/admin.py index 970cd8845..0e2b31b20 100644 --- a/archaeological_finds/admin.py +++ b/archaeological_finds/admin.py @@ -72,20 +72,8 @@ class FindAdmin(HistorizedObjectAdmin): 'datings', 'cached_label' ] -admin_site.register(models.Find, FindAdmin) - -class FindSourceAdmin(admin.ModelAdmin): - list_display = ('find', 'title', 'source_type',) - list_filter = ('source_type',) - search_fields = ('title', ) - model = models.FindSource - form = make_ajax_form(model, { - 'authors': 'author', - 'find': 'find' - }) - -admin_site.register(models.FindSource, FindSourceAdmin) +admin_site.register(models.Find, FindAdmin) class PropertyAdmin(HistorizedObjectAdmin): @@ -102,6 +90,7 @@ class PropertyAdmin(HistorizedObjectAdmin): def has_add_permission(self, request): return False + admin_site.register(models.Property, PropertyAdmin) @@ -144,20 +133,8 @@ class TreatmentFileAdmin(HistorizedObjectAdmin): 'cached_label', ] -admin_site.register(models.TreatmentFile, TreatmentFileAdmin) - - -class TreatmentSourceAdmin(admin.ModelAdmin): - list_display = ('title', 'treatment', 'source_type',) - list_filter = ('source_type',) - search_fields = ('title', 'treatment__cached_label') - model = models.TreatmentSource - form = make_ajax_form(model, { - 'treatment': 'treatment', - 'authors': 'author' - }) -admin_site.register(models.TreatmentSource, TreatmentSourceAdmin) +admin_site.register(models.TreatmentFile, TreatmentFileAdmin) class HierarchicalTypeAdmin(GeneralTypeAdmin): diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index 6107b744e..1636c7897 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -24,33 +24,14 @@ Finds forms definitions import logging from django import forms -from django.conf import settings from django.core import validators from django.core.exceptions import PermissionDenied from django.forms.formsets import formset_factory from django.utils.translation import ugettext_lazy as _ -from ishtar_common.models import valid_id, valid_ids, get_current_profile, \ - SpatialReferenceSystem -from archaeological_operations.models import Period, ArchaeologicalSite, \ - RelationType as OpeRelationType +import models from archaeological_context_records.models import DatingType, DatingQuality, \ ContextRecord, RelationType as CRRelationType -import models - -from ishtar_common.forms import FormSet, FloatField, \ - get_form_selection, reverse_lazy, TableSelect, get_now, FinalForm, \ - ManageOldType, FieldType, IshtarForm, FormHeader - -from ishtar_common.forms_common import get_town_field, \ - SourceSelect, CustomForm, BaseImageForm, BaseImageFormset, SourceForm -from ishtar_common.utils import convert_coordinates_to_point -from ishtar_common import widgets -from bootstrap_datepicker.widgets import DatePicker -from archaeological_operations.widgets import OAWidget - -from archaeological_warehouse.models import Warehouse - from archaeological_finds.forms_treatments import TreatmentSelect, \ TreatmentFormSelection, BaseTreatmentForm, TreatmentModifyForm, \ AdministrativeActTreatmentForm, TreatmentFormFileChoice, \ @@ -60,11 +41,23 @@ from archaeological_finds.forms_treatments import TreatmentSelect, \ AdministrativeActTreatmentModifForm, \ AdministrativeActTreatmentFileForm, \ AdministrativeActTreatmentFileFormSelection, \ - AdministrativeActTreatmentFileModifForm, SourceTreatmentFormSelection, \ - SourceTreatmentFileFormSelection, TreatmentSourceFormSelection, \ - TreatmentFileSourceFormSelection, DashboardForm as DashboardTreatmentForm, \ - DashboardTreatmentFileForm, TreatmentImagesFormset, \ - TreatmentFileSourceForm, TreatmentSourceForm + AdministrativeActTreatmentFileModifForm, \ + DashboardForm as DashboardTreatmentForm, \ + DashboardTreatmentFileForm +from archaeological_operations.models import Period, ArchaeologicalSite, \ + RelationType as OpeRelationType +from archaeological_operations.widgets import OAWidget +from archaeological_warehouse.models import Warehouse +from bootstrap_datepicker.widgets import DatePicker +from ishtar_common import widgets +from ishtar_common.forms import FormSet, FloatField, \ + reverse_lazy, TableSelect, get_now, FinalForm, \ + ManageOldType, FieldType, IshtarForm, FormHeader +from ishtar_common.forms_common import get_town_field, \ + CustomForm +from ishtar_common.models import valid_id, valid_ids, get_current_profile, \ + SpatialReferenceSystem +from ishtar_common.utils import convert_coordinates_to_point __all__ = [ 'TreatmentSelect', 'TreatmentFormSelection', 'BaseTreatmentForm', @@ -76,22 +69,17 @@ __all__ = [ 'AdministrativeActTreatmentFileForm', 'AdministrativeActTreatmentFileFormSelection', 'AdministrativeActTreatmentFormSelection', - 'AdministrativeActTreatmentFileModifForm', 'SourceTreatmentFormSelection', - 'SourceTreatmentFileFormSelection', 'TreatmentSourceFormSelection', - 'TreatmentFileSourceFormSelection', 'DashboardTreatmentForm', - 'DashboardTreatmentFileForm', 'TreatmentSourceForm', - 'TreatmentFileSourceForm', + 'AdministrativeActTreatmentFileModifForm', + 'DashboardTreatmentForm', 'DashboardTreatmentFileForm', 'RecordFormSelection', 'FindForm', 'DateForm', 'DatingFormSet', - 'PreservationForm', 'ImagesFormset', + 'PreservationForm', 'FindSelect', 'FindFormSelection', 'FindFormSelectionWarehouseModule', 'MultipleFindFormSelection', 'MultipleFindFormSelectionWarehouseModule', 'FindMultipleFormSelection', 'check_form', 'check_exist', 'check_not_exist', 'check_value', 'check_type_field', 'check_type_not_field', 'check_treatment', 'ResultFindForm', 'ResultFindFormSet', - 'FindDeletionForm', 'UpstreamFindFormSelection', 'SourceFindFormSelection', - 'FindSourceSelect', 'FindSourceFormSelection', 'NewFindBasketForm', + 'FindDeletionForm', 'UpstreamFindFormSelection', 'NewFindBasketForm', 'SelectFindBasketForm', 'DeleteFindBasketForm', 'FindBasketAddItemForm', - 'TreatmentImagesFormset', 'FindSourceForm' ] logger = logging.getLogger(__name__) @@ -327,14 +315,6 @@ class FindForm(CustomForm, ManageOldType): return self.cleaned_data -ImagesFormset = formset_factory(BaseImageForm, can_delete=True, - formset=BaseImageFormset) -ImagesFormset.file_upload = True -ImagesFormset.form_label = _(u"Images") -ImagesFormset.form_admin_name = _(u"Find - 025 - Images") -ImagesFormset.form_slug = "find-025-images" - - class PreservationForm(CustomForm, ManageOldType): form_label = _("Preservation") form_admin_name = _(u"Find - 030 - Preservation") @@ -747,49 +727,6 @@ class UpstreamFindFormSelection(FindFormSelection): self.fields['resulting_pk'] = self.fields.pop('pk') -############################################## -# Source management for archaeological finds # -############################################## - -SourceFindFormSelection = get_form_selection( - 'SourceFindFormSelection', _(u"Archaeological find search"), 'find', - models.Find, FindSelect, 'get-find', - _(u"You should select an archaeological find.")) - - -class FindSourceSelect(SourceSelect): - find__base_finds__context_record__operation__year = forms.IntegerField( - label=_(u"Year of the operation")) - find__base_finds__context_record__operation__operation_code = \ - forms.IntegerField(label=_(u"Numeric reference")) - if settings.COUNTRY == 'fr': - find__base_finds__context_record__operation__code_patriarche = \ - forms.IntegerField( - widget=OAWidget, - label="Code PATRIARCHE") - find__datings__period = forms.ChoiceField( - label=_(u"Period of the archaeological find"), choices=[]) - find__material_type = forms.ChoiceField( - label=_("Material type of the archaeological find"), choices=[]) - find__description = forms.CharField( - label=_(u"Description of the archaeological find")) - - def __init__(self, *args, **kwargs): - super(FindSourceSelect, self).__init__(*args, **kwargs) - self.fields['find__datings__period'].choices = Period.get_types() - self.fields['find__datings__period'].help_text = Period.get_help() - self.fields['find__material_type'].choices = \ - models.MaterialType.get_types() - self.fields['find__material_type'].help_text = \ - models.MaterialType.get_help() - -FindSourceFormSelection = get_form_selection( - 'FindSourceFormSelection', _(u"Documentation search"), 'pk', - models.FindSource, FindSourceSelect, 'get-findsource', - _(u"You should select a document."), - get_full_url='get-findsource-full') - - class NewFindBasketForm(forms.ModelForm): class Meta: model = models.FindBasket @@ -867,7 +804,3 @@ class FindBasketAddItemForm(forms.Form): raise PermissionDenied basket.items.add(item) return basket - - -class FindSourceForm(SourceForm): - form_slug = "findsource-general" diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py index a61e56f5e..f2a47e727 100644 --- a/archaeological_finds/forms_treatments.py +++ b/archaeological_finds/forms_treatments.py @@ -17,31 +17,26 @@ # See the file COPYING for details. -from collections import OrderedDict import datetime import logging +from collections import OrderedDict from django import forms from django.core import validators from django.forms.formsets import formset_factory from django.utils.translation import ugettext_lazy as _ -from ishtar_common.models import Person, valid_id, Organization, \ - get_current_profile -from archaeological_operations.models import ActType, AdministrativeAct -from archaeological_warehouse.models import Warehouse, Container import models - from archaeological_operations.forms import AdministrativeActForm, \ AdministrativeActOpeFormSelection, AdministrativeActModifForm - -from ishtar_common.forms import reverse_lazy, TableSelect, FinalForm, \ - ManageOldType, get_form_selection, CustomForm, FieldType, IshtarForm -from ishtar_common.forms_common import SourceSelect, BaseImageForm, \ - BaseImageFormset, SourceForm - -from ishtar_common import widgets +from archaeological_operations.models import ActType, AdministrativeAct +from archaeological_warehouse.models import Warehouse, Container from bootstrap_datepicker.widgets import DatePicker +from ishtar_common import widgets +from ishtar_common.forms import reverse_lazy, TableSelect, FinalForm, \ + ManageOldType, CustomForm, FieldType, IshtarForm +from ishtar_common.models import Person, valid_id, Organization, \ + get_current_profile logger = logging.getLogger(__name__) @@ -258,14 +253,6 @@ class TreatmentModifyForm(BaseTreatmentForm): return cleaned_data -TreatmentImagesFormset = formset_factory(BaseImageForm, can_delete=True, - formset=BaseImageFormset) -TreatmentImagesFormset.file_upload = True -TreatmentImagesFormset.form_label = _(u"Images") -TreatmentImagesFormset.form_admin_name = _(u"Treatment - 025 - Images") -TreatmentImagesFormset.form_slug = "treatment-025-images" - - class TreatmentFormFileChoice(CustomForm, forms.Form): form_label = _(u"Associated request") form_admin_name = _(u"Treatment - 010 - Request choice") @@ -662,73 +649,3 @@ class AdministrativeActTreatmentFileModifForm( AdministrativeActModifForm, AdministrativeActTreatmentFileForm): pk = forms.IntegerField(required=False, widget=forms.HiddenInput) index = forms.IntegerField(label=_("Index"), required=False) - - -SourceTreatmentFormSelection = get_form_selection( - 'SourceTreatmentFormSelection', _(u"Treatment search"), 'treatment', - models.Treatment, TreatmentSelect, 'get-treatment', - _(u"You should select a treatment.")) - -SourceTreatmentFileFormSelection = get_form_selection( - 'SourceTreatmentFileFormSelection', _(u"Treatment request search"), - 'treatment_file', - models.TreatmentFile, TreatmentFileSelect, 'get-treatmentfile', - _(u"You should select a treatment request.")) - - -class TreatmentSourceSelect(SourceSelect): - treatment__name = forms.CharField( - label=_(u"Treatment name"), max_length=200) - treatment__year = forms.IntegerField(label=_(u"Treatment year")) - treatment__index = forms.IntegerField(label=_(u"Treatment index")) - treatment__internal_reference = forms.CharField( - max_length=200, label=_(u"Treatment internal reference")) - treatment__treatment_types = forms.ChoiceField(label=_(u"Treatment type"), - choices=[]) - - def __init__(self, *args, **kwargs): - super(TreatmentSourceSelect, self).__init__(*args, **kwargs) - self.fields['treatment__treatment_types'].choices = \ - models.TreatmentType.get_types() - self.fields['treatment__treatment_types'].help_text = \ - models.TreatmentType.get_help() - - -TreatmentSourceFormSelection = get_form_selection( - 'TreatmentSourceFormSelection', _(u"Documentation search"), 'pk', - models.TreatmentSource, TreatmentSourceSelect, 'get-treatmentsource', - _(u"You should select a document.")) - - -class TreatmentSourceForm(SourceForm): - form_slug = "treatmentsource-general" - - -class TreatmentFileSourceSelect(SourceSelect): - treatment_file__name = forms.CharField( - label=_(u"Treatment request name"), max_length=200) - treatment_file__year = forms.IntegerField( - label=_(u"Treatment request year")) - treatment_file__index = forms.IntegerField( - label=_(u"Treatment request index")) - treatment_file__internal_reference = forms.CharField( - max_length=200, label=_(u"Treatment request internal reference")) - treatment_file__type = forms.ChoiceField( - label=_(u"Treatment request type"), choices=[]) - - def __init__(self, *args, **kwargs): - super(TreatmentFileSourceSelect, self).__init__(*args, **kwargs) - self.fields['treatment_file__type'].choices = \ - models.TreatmentFileType.get_types() - self.fields['treatment_file__type'].help_text = \ - models.TreatmentFileType.get_help() - - -TreatmentFileSourceFormSelection = get_form_selection( - 'TreatmentFileSourceFormSelection', _(u"Documentation search"), 'pk', - models.TreatmentFileSource, TreatmentFileSourceSelect, - 'get-treatmentfilesource', _(u"You should select a document.")) - - -class TreatmentFileSourceForm(SourceForm): - form_slug = "treatmentfilesource-general" diff --git a/archaeological_finds/ishtar_menu.py b/archaeological_finds/ishtar_menu.py index 4877e442c..715644b61 100644 --- a/archaeological_finds/ishtar_menu.py +++ b/archaeological_finds/ishtar_menu.py @@ -73,30 +73,6 @@ MENU_SECTIONS = [ access_controls=['change_find', 'change_own_find']), ]), - SectionItem( - 'find_source', _(u"Documentation"), - childs=[ - MenuItem('find_source_search', - _(u"Search"), - model=models.FindSource, - access_controls=['view_find', - 'view_own_find']), - MenuItem('find_source_creation', - _(u"Creation"), - model=models.FindSource, - access_controls=['change_find', - 'change_own_find']), - MenuItem('find_source_modification', - _(u"Modification"), - model=models.FindSource, - access_controls=['change_find', - 'change_own_find']), - MenuItem('find_source_deletion', - _(u"Deletion"), - model=models.FindSource, - access_controls=['change_find', - 'change_own_find']), - ]), # MenuItem( # 'treatment_creation', _(u"Add a treatment"), # model=models.Treatment, @@ -153,31 +129,6 @@ MENU_SECTIONS = [ access_controls=['change_administrativeact']), ] ), - SectionItem( - 'treatmentfile_source', _(u"Source"), - childs=[ - MenuItem('treatmentfile_source_search', - _(u"Search"), - model=models.TreatmentFileSource, - access_controls=['view_treatmentfile', - 'view_own_treatmentfile']), - MenuItem('treatmentfile_source_creation', - _(u"Creation"), - model=models.TreatmentFileSource, - access_controls=['change_treatmentfile', - 'change_own_treatmentfile']), - MenuItem('treatmentfile_source_modification', - _(u"Modification"), - model=models.TreatmentFileSource, - access_controls=['change_treatmentfile', - 'change_own_treatmentfile']), - MenuItem('treatmentfile_source_deletion', - _(u"Deletion"), - model=models.TreatmentFileSource, - access_controls=['change_treatmentfile', - 'change_own_treatmentfile']), - ] - ), ] )), (70, @@ -234,31 +185,6 @@ MENU_SECTIONS = [ model=AdministrativeAct, access_controls=['change_administrativeact']), ]), - SectionItem( - 'treatment_source', _(u"Source"), - childs=[ - MenuItem('treatment_source_search', - _(u"Search"), - model=models.TreatmentSource, - access_controls=['view_treatment', - 'view_own_treatment']), - MenuItem('treatment_source_creation', - _(u"Creation"), - model=models.TreatmentSource, - access_controls=['change_treatment', - 'change_own_treatment']), - MenuItem('treatment_source_modification', - _(u"Modification"), - model=models.TreatmentSource, - access_controls=['change_treatment', - 'change_own_treatment']), - MenuItem('treatment_source_deletion', - _(u"Deletion"), - model=models.TreatmentSource, - access_controls=['change_treatment', - 'change_own_treatment']), - ] - ), ] )), ] diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index 7e53b514d..1052edb19 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -1,23 +1,20 @@ -from archaeological_finds.models_finds import MaterialType, ConservatoryState,\ +from archaeological_finds.models_finds import MaterialType, ConservatoryState, \ IntegrityType, RemarkabilityType, ObjectType, BaseFind, \ - FindBasket, Find, FindSource, Property, CHECK_CHOICES, BatchType, \ + FindBasket, Find, Property, CHECK_CHOICES, BatchType, \ BFBulkView, FBulkView, FirstBaseFindView, AlterationType, \ AlterationCauseType, TreatmentEmergencyType, TreatmentType, \ - CommunicabilityType, MaterialTypeQualityType, ObjectTypeQualityType, \ - FindImage + CommunicabilityType, MaterialTypeQualityType, ObjectTypeQualityType from archaeological_finds.models_treatments import Treatment, \ AbsFindTreatments, FindUpstreamTreatments, FindDownstreamTreatments, \ - FindTreatments, TreatmentSource, TreatmentFile, TreatmentFileType, \ - TreatmentFileSource, TreatmentState, TreatmentImage + FindTreatments, TreatmentFile, TreatmentFileType, \ + TreatmentState -__all__ = ['MaterialType', 'ConservatoryState', - 'IntegrityType', 'RemarkabilityType', 'ObjectType', - 'BaseFind', 'FindBasket', 'Find', 'FindSource', 'Property', - 'BFBulkView', 'FBulkView', 'FirstBaseFindView', 'AlterationType', - 'AlterationCauseType', 'TreatmentEmergencyType', +__all__ = ['MaterialType', 'ConservatoryState', 'IntegrityType', + 'RemarkabilityType', 'ObjectType', 'BaseFind', 'FindBasket', 'Find', + 'Property', 'BFBulkView', 'FBulkView', 'FirstBaseFindView', + 'AlterationType', 'AlterationCauseType', 'TreatmentEmergencyType', 'CHECK_CHOICES', 'BatchType', 'TreatmentType', 'TreatmentState', 'Treatment', 'AbsFindTreatments', 'FindUpstreamTreatments', - 'FindDownstreamTreatments', 'FindTreatments', 'TreatmentSource', - 'TreatmentFile', 'TreatmentFileType', 'TreatmentFileSource', - 'CommunicabilityType', 'MaterialTypeQualityType', - 'ObjectTypeQualityType', 'TreatmentImage', 'FindImage'] + 'FindDownstreamTreatments', 'FindTreatments', 'TreatmentFile', + 'TreatmentFileType', 'CommunicabilityType', + 'MaterialTypeQualityType', 'ObjectTypeQualityType'] diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 0e36cf29a..72e4d8607 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -32,10 +32,10 @@ from django.utils.translation import ugettext_lazy as _ from ishtar_common.data_importer import post_importer_action, ImporterError from ishtar_common.utils import cached_label_changed, post_save_point -from ishtar_common.models import BaseSource, Document, GeneralType, \ +from ishtar_common.models import Document, GeneralType, \ HierarchicalType, BaseHistorizedItem, ShortMenuItem, LightHistorizedItem, \ HistoricalRecords, OwnPerms, Person, Basket, post_save_cache, \ - ValueGetter, get_current_profile, IshtarImage, ThroughImage + ValueGetter, get_current_profile from archaeological_operations.models import AdministrativeAct, Operation from archaeological_context_records.models import ContextRecord, Dating @@ -831,8 +831,6 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, documents = models.ManyToManyField( Document, related_name='finds', verbose_name=_(u"Documents"), blank=True) - images = models.ManyToManyField(IshtarImage, verbose_name=_(u"Images"), - blank=True, through='FindImage') cached_label = models.TextField(_(u"Cached name"), null=True, blank=True, db_index=True) history = HistoricalRecords() @@ -1441,80 +1439,6 @@ def base_find_find_changed(sender, **kwargs): m2m_changed.connect(base_find_find_changed, sender=Find.base_finds.through) -class FindImage(ThroughImage): - item = models.ForeignKey(Find, on_delete=models.CASCADE, - related_name='associated_images') - - -class FindSource(BaseSource): - SHOW_URL = 'show-findsource' - MODIFY_URL = 'find_source_modify' - TABLE_COLS = [ - 'find__base_finds__context_record__operation', - 'find__base_finds__context_record', 'find'] + \ - BaseSource.TABLE_COLS - - # search parameters - BOOL_FIELDS = ['duplicate'] - RELATIVE_SESSION_NAMES = [ - ('find', 'find__pk'), - ('contextrecord', 'find__base_finds__context_record__pk'), - ('operation', 'find__base_finds__context_record__operation__pk'), - ('file', - 'find__base_finds__context_record__operation__associated_file__pk') - ] - EXTRA_REQUEST_KEYS = { - 'title': 'title__icontains', - 'description': 'description__icontains', - 'comment': 'comment__icontains', - 'additional_information': 'additional_information__icontains', - 'person': 'authors__person__pk', - 'find__base_finds__context_record__operation__year': - 'find__base_finds__context_record__operation__year', - 'find__base_finds__context_record__operation__operation_code': - 'find__base_finds__context_record__operation__operation_code', - 'find__base_finds__context_record__operation__code_patriarche': - 'find__base_finds__context_record__operation__code_patriarche', - 'find__datings__period': 'find__datings__period__pk', - 'find__description': 'find__description__icontains', - } - PARENT_SEARCH_VECTORS = BaseSource.PARENT_SEARCH_VECTORS + ['find'] - - class Meta: - verbose_name = _(u"Find documentation") - verbose_name_plural = _(u"Find documentations") - permissions = ( - ("view_findsource", - u"Can view all Find sources"), - ("view_own_findsource", - u"Can view own Find source"), - ("add_own_findsource", - u"Can add own Find source"), - ("change_own_findsource", - u"Can change own Find source"), - ("delete_own_findsource", - u"Can delete own Find source"), - ) - find = models.ForeignKey(Find, verbose_name=_(u"Find"), - related_name="source") - - @property - def owner(self): - return self.find - - @classmethod - def get_query_owns(cls, ishtaruser): - q = cls._construct_query_own( - 'find__base_finds__context_record__operation__', - Operation._get_query_owns_dicts(ishtaruser) - ) | cls._construct_query_own('', [ - {'find__history_creator': ishtaruser.user_ptr}, - {'find__base_finds__context_record__operation__end_date__isnull': - True} - ]) - return q - - class Property(LightHistorizedItem): find = models.ForeignKey(Find, verbose_name=_(u"Find")) administrative_act = models.ForeignKey( diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index 19f00de1f..4ee5fe08b 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -29,10 +29,10 @@ from django.utils.translation import ugettext_lazy as _ from archaeological_finds.models_finds import Find, FindBasket, TreatmentType from archaeological_operations.models import ClosedItem, Operation from archaeological_warehouse.models import Warehouse, Container -from ishtar_common.models import BaseSource, Document, GeneralType, \ +from ishtar_common.models import Document, GeneralType, \ ImageModel, BaseHistorizedItem, OwnPerms, HistoricalRecords, Person, \ Organization, ValueGetter, post_save_cache, ShortMenuItem, \ - DashboardFormItem, IshtarImage, ThroughImage + DashboardFormItem from ishtar_common.utils import cached_label_changed, get_current_year @@ -127,8 +127,6 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem, documents = models.ManyToManyField( Document, related_name='treatments', verbose_name=_(u"Documents"), blank=True) - images = models.ManyToManyField(IshtarImage, verbose_name=_(u"Images"), - blank=True, through='TreatmentImage') cached_label = models.TextField(_(u"Cached name"), null=True, blank=True, db_index=True) history = HistoricalRecords() @@ -309,11 +307,6 @@ def pre_delete_treatment(sender, **kwargs): pre_delete.connect(pre_delete_treatment, sender=Treatment) -class TreatmentImage(ThroughImage): - item = models.ForeignKey(Treatment, on_delete=models.CASCADE, - related_name='associated_images') - - class AbsFindTreatments(models.Model): find = models.ForeignKey(Find, verbose_name=_(u"Find"), related_name='%(class)s_related') @@ -614,72 +607,3 @@ class TreatmentFile(DashboardFormItem, ClosedItem, BaseHistorizedItem, post_save.connect(cached_label_changed, sender=TreatmentFile) - - -class TreatmentSource(BaseSource): - treatment = models.ForeignKey( - Treatment, verbose_name=_(u"Treatment"), related_name="source") - BOOL_FIELDS = ['duplicate'] - TABLE_COLS = ['treatment__cached_label'] + BaseSource.TABLE_COLS - COL_LABELS = {'treatment__cached_label': _(u"Treatment")} - SHOW_URL = 'show-treatmentsource' - PARENT_SEARCH_VECTORS = BaseSource.PARENT_SEARCH_VECTORS + ['treatment'] - - class Meta: - verbose_name = _(u"Treatment documentation") - verbose_name_plural = _(u"Treament documentations") - permissions = ( - ("view_treatmentsource", - u"Can view all Treatment sources"), - ("view_own_treatmentsource", - u"Can view own Treatment source"), - ("add_own_treatmentsource", - u"Can add own Treatment source"), - ("change_own_treatmentsource", - u"Can change own Treatment source"), - ("delete_own_treatmentsource", - u"Can delete own Treatment source"), - ) - - @property - def owner(self): - return self.treatment - - def _get_base_image_path(self): - return u"{}/source".format(self.treatment._get_base_image_path()) - - -class TreatmentFileSource(BaseSource): - treatment_file = models.ForeignKey( - TreatmentFile, verbose_name=_(u"Treatment request"), - related_name="source") - BOOL_FIELDS = ['duplicate'] - TABLE_COLS = ['treatment_file__cached_label'] + BaseSource.TABLE_COLS - COL_LABELS = {'treatment_file__cached_label': _(u"Treatment file")} - SHOW_URL = 'show-treatmentfilesource' - PARENT_SEARCH_VECTORS = BaseSource.PARENT_SEARCH_VECTORS + [ - 'treatment_file'] - - class Meta: - verbose_name = _(u"Treatment request documentation") - verbose_name_plural = _(u"Treatment request documentations") - permissions = ( - ("view_filetreatmentsource", - u"Can view Treatment request source"), - ("view_own_filetreatmentsource", - u"Can view own Treatment request source"), - ("add_own_filetreatmentsource", - u"Can add own Treatment request source"), - ("change_own_filetreatmentsource", - u"Can change own Treatment request source"), - ("delete_own_filetreatmentsource", - u"Can delete own Treatment request source"), - ) - - @property - def owner(self): - return self.treatment_file - - def _get_base_image_path(self): - return u"treatmentfile/{}/{}/source".format( - self.treatment_file.year, self.treatment_file.index) diff --git a/archaeological_finds/templates/ishtar/sheet_treatment.html b/archaeological_finds/templates/ishtar/sheet_treatment.html index 21f0e5370..1a3bb931f 100644 --- a/archaeological_finds/templates/ishtar/sheet_treatment.html +++ b/archaeological_finds/templates/ishtar/sheet_treatment.html @@ -66,10 +66,12 @@ {% trans "Related operations" as related_operations %} {% dynamic_table_document related_operations 'operations' 'related_treatment' item.pk 'TABLE_COLS' output %} +{% comment %} {% if item.source.count %} {% trans "Associated documents" as associated_docs %} {% dynamic_table_document associated_docs 'treatments_docs' 'treatment' item.pk '' output %} {% endif %} +{% endcomment %} {% if item.administrative_act.count %} {% trans "Administrative acts" as admact_lbl %} diff --git a/archaeological_finds/templates/ishtar/sheet_treatmentfile.html b/archaeological_finds/templates/ishtar/sheet_treatmentfile.html index f474aab7c..08398a6c2 100644 --- a/archaeological_finds/templates/ishtar/sheet_treatmentfile.html +++ b/archaeological_finds/templates/ishtar/sheet_treatmentfile.html @@ -62,10 +62,12 @@ {% dynamic_table_document treatments 'treatments' 'file' item.pk '' output '' 'treatment' %} {% endif %} +{% comment %} {% if item.source.count %} {% trans "Associated documents" as associated_docs %} {% dynamic_table_document associated_docs 'treatmentfiles_docs' 'treatment_file' item.pk '' output %} {% endif %} +{% endcomment %} {% if item.administrative_act.count %} {% trans "Administrative acts" as admact_lbl %} diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py index c9aaae2a2..bd466a1af 100644 --- a/archaeological_finds/urls.py +++ b/archaeological_finds/urls.py @@ -43,24 +43,6 @@ urlpatterns = [ views.find_deletion_wizard), name='find_deletion'), url(r'find_modify/(?P<pk>.+)/$', views.find_modify, name='find_modify'), - url(r'find_source_search/(?P<step>.+)?$', - check_rights(['view_find', 'view_own_find'])( - views.find_source_search_wizard), - name='find_source_search'), - url(r'find_source_creation/(?P<step>.+)?$', - check_rights(['change_find', 'change_own_find'])( - views.find_source_creation_wizard), - name='find_source_creation'), - url(r'find_source_modification/(?P<step>.+)?$', - check_rights(['change_find', 'change_own_find'])( - views.find_source_modification_wizard), - name='find_source_modification'), - url(r'find_source_modify/(?P<pk>.+)/$', - views.find_source_modify, name='find_source_modify'), - url(r'find_source_deletion/(?P<step>.+)?$', - check_rights(['change_find', 'change_own_find'])( - views.find_source_deletion_wizard), - name='find_source_deletion'), url(r'^find_basket_creation/$', check_rights(['change_find', 'change_own_find'])( views.NewFindBasketView.as_view()), name='new_findbasket'), @@ -105,31 +87,6 @@ urlpatterns = [ check_rights(['change_find', 'change_own_find'])( views.treatment_deletion_wizard), name='treatment_deletion'), - url(r'^show-treatmentsource(?:/(?P<pk>.+))?/(?P<type>.+)?$', - views.show_treatmentsource, - name=models.TreatmentSource.SHOW_URL), - url(r'^get-treatmentsource/(?P<type>.+)?$', - views.get_treatmentsource, - name='get-treatmentsource'), - url(r'^treatment_source_search/(?P<step>.+)?$', - check_rights(['view_treatment', 'view_own_treatment'])( - views.treatment_source_search_wizard), - name='treatment_source_search'), - url(r'^treatment_source_creation/(?P<step>.+)?$', - check_rights(['change_treatment', 'change_own_treatment'])( - views.treatment_source_creation_wizard), - name='treatment_source_creation'), - url(r'^treatment_source_modification/(?P<step>.+)?$', - check_rights(['change_treatment', 'change_own_treatment'])( - views.treatment_source_modification_wizard), - name='treatment_source_modification'), - url(r'^treatment_source_modify/(?P<pk>.+)/$', - views.treatment_source_modify, name='treatment_source_modify'), - url(r'^treatment_source_deletion/(?P<step>.+)?$', - check_rights(['change_treatment', 'change_own_treatment'])( - views.treatment_source_deletion_wizard), - name='treatment_source_deletion'), - url(r'^treatment_admacttreatment_search/(?P<step>.+)?$', check_rights(['change_administrativeact'])( views.treatment_administrativeact_search_wizard), @@ -173,30 +130,6 @@ urlpatterns = [ views.treatmentfile_admacttreatmentfile_deletion_wizard), name='treatmentfle_admacttreatmentfle_deletion'), - url(r'^show-treatmentfilesource(?:/(?P<pk>.+))?/(?P<type>.+)?$', - views.show_treatmentfilesource, - name=models.TreatmentFileSource.SHOW_URL), - url(r'^get-treatmentfilesource/(?P<type>.+)?$', - views.get_treatmentfilesource, - name='get-treatmentfilesource'), - url(r'^treatmentfile_source_search/(?P<step>.+)?$', - check_rights(['view_treatmentfile', 'view_own_treatmentfile'])( - views.treatmentfile_source_search_wizard), - name='treatmentfile_source_search'), - url(r'^treatmentfile_source_creation/(?P<step>.+)?$', - check_rights(['change_treatmentfile', 'change_own_treatmentfile'])( - views.treatmentfile_source_creation_wizard), - name='treatmentfile_source_creation'), - url(r'^treatmentfile_source_modification/(?P<step>.+)?$', - check_rights(['change_treatmentfile', 'change_own_treatmentfile'])( - views.treatmentfile_source_modification_wizard), - name='treatmentfile_source_modification'), - url(r'^treatmentfile_source_modify/(?P<pk>.+)/$', - views.treatmentfile_source_modify, name='treatmentfile_source_modify'), - url(r'^treatmentfile_source_deletion/(?P<step>.+)?$', - check_rights(['change_treatmentfile', 'change_own_treatmentfile'])( - views.treatmentfile_source_deletion_wizard), - name='treatmentfile_source_deletion'), url(r'^treatmentfle_search/(?P<step>.+)?$', check_rights(['change_find', 'change_own_find'])( views.treatmentfile_search_wizard), @@ -253,14 +186,6 @@ urlpatterns = [ url(r'get-find-shortcut/(?P<type>.+)?$', views.get_find, name='get-find-shortcut', kwargs={'full': 'shortcut'}), - url(r'get-findsource/(?P<type>.+)?$', - views.get_findsource, name='get-findsource'), - url(r'get-findsource-full/(?P<type>.+)?$', - views.get_findsource, name='get-findsource-full', - kwargs={'full': True}), - url(r'^show-findsource(?:/(?P<pk>.+))?/(?P<type>.+)?$', - views.show_findsource, - name=models.FindSource.SHOW_URL), url(r'^show-find/basket-(?P<pk>.+)/(?P<type>.+)?$', views.show_findbasket, name='show-findbasket'), url(r'^display-find/basket-(?P<pk>.+)/$', views.display_findbasket, diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index 04264080e..2dc599807 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -19,7 +19,6 @@ import json -from django.core.exceptions import PermissionDenied from django.core.urlresolvers import reverse from django.db.models import Q from django.http import HttpResponseRedirect, HttpResponse @@ -28,25 +27,17 @@ from django.utils.translation import ugettext_lazy as _ from django.views.generic import TemplateView from django.views.generic.edit import CreateView, FormView -from ishtar_common.models import IshtarUser, get_current_profile -from archaeological_operations.models import AdministrativeAct - -from ishtar_common.forms import FinalForm -from ishtar_common.forms_common import SourceForm, AuthorFormset, \ - SourceDeletionForm -from archaeological_operations.forms import FinalAdministrativeActDeleteForm from archaeological_context_records.forms \ import RecordFormSelection as RecordFormSelectionTable - +from archaeological_operations.forms import FinalAdministrativeActDeleteForm +from archaeological_operations.wizards import AdministrativeActDeletionWizard +from forms import * +from ishtar_common.forms import FinalForm +from ishtar_common.models import IshtarUser, get_current_profile from ishtar_common.views import get_item, show_item, display_item, \ revert_item, get_autocomplete_generic, IshtarMixin, LoginRequiredMixin - from ishtar_common.wizards import SearchWizard -from archaeological_operations.wizards import AdministrativeActDeletionWizard - from wizards import * -from forms import * -import models get_find = get_item(models.Find, 'get_find', 'find') @@ -107,9 +98,6 @@ def autocomplete_treatmentfile(request): return HttpResponse(data, content_type='text/plain') -show_findsource = show_item(models.FindSource, 'findsource') - -get_findsource = get_item(models.FindSource, 'get_findsource', 'findsource') show_find = show_item(models.Find, 'find') display_find = display_item(models.Find) revert_find = revert_item(models.Find) @@ -134,7 +122,6 @@ def check_not_warehouse_module(self): find_creation_steps = [ ('selecrecord-find_creation', RecordFormSelectionTable), ('find-find_creation', FindForm), - ('images-find_creation', ImagesFormset), ('preservation-find_creation', PreservationForm), ('dating-find_creation', DatingFormSet), ('final-find_creation', FinalForm) @@ -174,7 +161,6 @@ find_modification_steps = [ ('selecw-find_modification', FindFormSelectionWarehouseModule), ('selecrecord-find_modification', RecordFormSelection), ('find-find_modification', FindForm), - ('images-find_modification', ImagesFormset), ('preservation-find_modification', PreservationForm), ('dating-find_modification', DatingFormSet), ('final-find_modification', FinalForm) @@ -215,42 +201,6 @@ find_deletion_wizard = FindDeletionWizard.as_view( label=_(u"Find deletion"), url_name='find_deletion',) -find_source_search_wizard = SearchWizard.as_view([ - ('selec-find_source_search', FindSourceFormSelection)], - label=_(u"Find: source search"), - url_name='find_source_search',) - -find_source_creation_wizard = FindSourceWizard.as_view([ - ('selec-find_source_creation', SourceFindFormSelection), - ('source-find_source_creation', FindSourceForm), - ('authors-find_source_creation', AuthorFormset), - ('final-find_source_creation', FinalForm)], - label=_(u"Find: new source"), - url_name='find_source_creation',) - -find_source_modification_wizard = FindSourceWizard.as_view([ - ('selec-find_source_modification', FindSourceFormSelection), - ('source-find_source_modification', FindSourceForm), - ('authors-find_source_modification', AuthorFormset), - ('final-find_source_modification', FinalForm)], - label=_(u"Find: source modification"), - url_name='find_source_modification',) - - -def find_source_modify(request, pk): - find_source_modification_wizard(request) - FindSourceWizard.session_set_value( - request, 'selec-find_source_modification', 'pk', pk, reset=True) - return redirect(reverse( - 'find_source_modification', - kwargs={'step': 'source-find_source_modification'})) - -find_source_deletion_wizard = FindSourceDeletionWizard.as_view([ - ('selec-find_source_deletion', FindSourceFormSelection), - ('final-find_source_deletion', SourceDeletionForm)], - label=_(u"Find: source deletion"), - url_name='find_source_deletion',) - autocomplete_objecttype = get_autocomplete_generic(models.ObjectType) autocomplete_materialtype = get_autocomplete_generic(models.MaterialType) autocomplete_treatmenttype = get_autocomplete_generic(models.TreatmentType) @@ -414,7 +364,6 @@ treatment_wizard_steps = [ ('basetreatment-treatment_creation', BaseTreatmentForm), ('selecfind-treatment_creation', UpstreamFindFormSelection), ('selecbasket-treatment_creation', SelectFindBasketForm), - ('images-treatment_creation', TreatmentImagesFormset), # ('resultfind-treatment_creation', ResultFindForm), # ('resultfinds-treatment_creation', ResultFindFormSet), ('final-treatment_creation', FinalForm) @@ -451,7 +400,6 @@ treatment_modification_wizard = TreatmentModificationWizard.as_view( [('selec-treatment_modification', TreatmentFormSelection), ('file-treatment_modification', TreatmentFormFileChoice), ('basetreatment-treatment_modification', TreatmentModifyForm), - ('images-treatment_creation', TreatmentImagesFormset), ('final-treatment_modification', FinalForm)], label=_(u"Treatment modification"), url_name='treatment_modification', @@ -615,106 +563,12 @@ def treatmentfile_administrativeacttreatmentfile_modify(request, pk): 'admact-treatmentfle_admacttreatmentfle_modification' })) -# sources - -show_treatmentsource = show_item(models.TreatmentSource, 'treatmentsource') -get_treatmentsource = get_item(models.TreatmentSource, 'get_treatmentsource', - 'treatmentsource') - -treatment_source_search_wizard = SearchWizard.as_view([ - ('selec-treatment_source_search', TreatmentSourceFormSelection)], - label=_(u"Treatment: source search"), - url_name='treatment_source_search',) - -treatment_source_creation_wizard = TreatmentSourceWizard.as_view([ - ('selec-treatment_source_creation', SourceTreatmentFormSelection), - ('source-treatment_source_creation', SourceForm), - ('authors-treatment_source_creation', AuthorFormset), - ('final-treatment_source_creation', FinalForm)], - label=_(u"Treatment: new source"), - url_name='treatment_source_creation',) - -treatment_source_modification_wizard = TreatmentSourceWizard.as_view([ - ('selec-treatment_source_modification', TreatmentSourceFormSelection), - ('source-treatment_source_modification', SourceForm), - ('authors-treatment_source_modification', AuthorFormset), - ('final-treatment_source_modification', FinalForm)], - label=_(u"Treatment: source modification"), - url_name='treatment_source_modification',) - - -def treatment_source_modify(request, pk): - treatment_source_modification_wizard(request) - TreatmentSourceWizard.session_set_value( - request, 'selec-treatment_source_modification', 'pk', pk, reset=True) - return redirect(reverse( - 'treatment_source_modification', - kwargs={'step': 'source-treatment_source_modification'})) - -treatment_source_deletion_wizard = TreatmentSourceDeletionWizard.as_view([ - ('selec-treatment_source_deletion', TreatmentSourceFormSelection), - ('final-treatment_source_deletion', SourceDeletionForm)], - label=_(u"Treatment: source deletion"), - url_name='treatment_source_deletion',) - -# treatment request sources - -show_treatmentfilesource = show_item(models.TreatmentFileSource, - 'treatmentfilesource') -get_treatmentfilesource = get_item( - models.TreatmentFileSource, 'get_treatmentfilesource', - 'treatmentfilesource') - -treatmentfile_source_search_wizard = SearchWizard.as_view([ - ('selec-treatmentfile_source_search', TreatmentFileSourceFormSelection)], - label=_(u"Treatment request: source search"), - url_name='treatmentfile_source_search',) - -treatmentfile_source_creation_wizard = TreatmentFileSourceWizard.as_view([ - ('selec-treatmentfile_source_creation', SourceTreatmentFileFormSelection), - ('source-treatmentfile_source_creation', SourceForm), - ('authors-treatmentfile_source_creation', AuthorFormset), - ('final-treatmentfile_source_creation', FinalForm)], - label=_(u"Treatment request: new source"), - url_name='treatmentfile_source_creation',) - -treatmentfile_source_modification_wizard = TreatmentFileSourceWizard.as_view([ - ('selec-treatmentfile_source_modification', - TreatmentFileSourceFormSelection), - ('source-treatmentfile_source_modification', SourceForm), - ('authors-treatmentfile_source_modification', AuthorFormset), - ('final-treatmentfile_source_modification', FinalForm)], - label=_(u"Treatment request: source modification"), - url_name='treatmentfile_source_modification',) - - -def treatmentfile_source_modify(request, pk): - treatmentfile_source_modification_wizard(request) - TreatmentFileSourceWizard.session_set_value( - request, 'selec-treatmentfile_source_modification', 'pk', pk, - reset=True) - return redirect(reverse( - 'treatmentfile_source_modification', - kwargs={'step': 'source-treatmentfile_source_modification'})) - - -treatmentfile_source_deletion_wizard = \ - TreatmentFileSourceDeletionWizard.as_view([ - ('selec-treatmentfile_source_deletion', - TreatmentFileSourceFormSelection), - ('final-treatmentfile_source_deletion', SourceDeletionForm)], - label=_(u"Treatment request: source deletion"), - url_name='treatmentfile_source_deletion',) - def reset_wizards(request): for wizard_class, url_name in ( (FindWizard, 'find_creation'), (FindModificationWizard, 'find_modification'), (FindDeletionWizard, 'find_deletion'), - (FindSourceWizard, 'find_source_creation'), - (FindSourceWizard, 'find_source_modification'), - (FindSourceDeletionWizard, 'find_source_deletion'), (TreatmentWizard, 'treatement_creation'), (TreatmentModificationWizard, 'treatment_modification'), (TreatmentDeletionWizard, 'treatment_deletion'), @@ -731,11 +585,5 @@ def reset_wizards(request): 'treatmentfle_admacttreatmentfle_modification'), (AdministrativeActDeletionWizard, 'treatmentfle_admacttreatmentfle_deletion'), - (TreatmentSourceWizard, 'treatment_source_creation'), - (TreatmentSourceWizard, 'treatment_source_modification'), - (TreatmentSourceDeletionWizard, 'treatment_source_deletion'), - (TreatmentFileSourceWizard, 'treatmentfile_source_creation'), - (TreatmentFileSourceWizard, 'treatmentfile_source_modification'), - (TreatmentFileSourceDeletionWizard, 'treatmentfile_source_deletion') ): wizard_class.session_reset(request, url_name) diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py index b244118cd..b15948dce 100644 --- a/archaeological_finds/wizards.py +++ b/archaeological_finds/wizards.py @@ -218,31 +218,3 @@ class TreatmentFileEditAdministrativeActWizard( def get_associated_item(self, dct): return self.get_current_object().treatment_file - - -class FindSourceWizard(SourceWizard): - wizard_done_window = reverse_lazy('show-findsource') - model = models.FindSource - - -class FindSourceDeletionWizard(DeletionWizard): - model = models.FindSource - fields = ['item', 'title', 'source_type', 'authors', ] - - -class TreatmentSourceWizard(SourceWizard): - model = models.TreatmentSource - - -class TreatmentSourceDeletionWizard(DeletionWizard): - model = models.TreatmentSource - fields = ['treatment', 'title', 'source_type', 'authors'] - - -class TreatmentFileSourceWizard(SourceWizard): - model = models.TreatmentFileSource - - -class TreatmentFileSourceDeletionWizard(DeletionWizard): - model = models.TreatmentFileSource - fields = ['treatment_file', 'title', 'source_type', 'authors'] 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') diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 27f03e752..e13255efc 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -33,8 +33,7 @@ from bootstrap_datepicker.widgets import DatePicker from ishtar_common.forms import name_validator, reverse_lazy, \ get_form_selection, TableSelect, ManageOldType, FinalForm, FormSet, \ CustomForm, FieldType -from ishtar_common.forms_common import get_image_help, BaseImageFormset, \ - BaseImageForm +from ishtar_common.forms_common import get_image_help from archaeological_finds.forms import FindMultipleFormSelection, \ SelectFindBasketForm @@ -161,14 +160,6 @@ class WarehouseForm(CustomForm, ManageOldType, forms.Form): return new_item -ImagesFormset = formset_factory(BaseImageForm, can_delete=True, - formset=BaseImageFormset) -ImagesFormset.file_upload = True -ImagesFormset.form_label = _(u"Images") -ImagesFormset.form_admin_name = _(u"Warehouse - 025 - Images") -ImagesFormset.form_slug = "warehouse-020-images" - - class WarehouseDeletionForm(FinalForm): confirm_msg = _(u"Would you like to delete this warehouse?") confirm_end_msg = _(u"Would you like to delete this warehouse?") diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 30c117fc2..48cc042f8 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -29,7 +29,7 @@ from django.utils.translation import ugettext_lazy as _ from ishtar_common.data_importer import post_importer_action from ishtar_common.models import Document, GeneralType, get_external_id, \ LightHistorizedItem, OwnPerms, Address, Person, post_save_cache, \ - ImageModel, DashboardFormItem, IshtarImage, ThroughImage + ImageModel, DashboardFormItem from ishtar_common.utils import cached_label_changed @@ -65,8 +65,6 @@ class Warehouse(Address, DashboardFormItem, OwnPerms): documents = models.ManyToManyField( Document, related_name='warehouses', verbose_name=_(u"Documents"), blank=True) - images = models.ManyToManyField(IshtarImage, verbose_name=_(u"Images"), - through='WarehouseImage', blank=True) external_id = models.TextField(_(u"External ID"), blank=True, null=True) auto_external_id = models.BooleanField( _(u"External ID is set automatically"), default=False) @@ -210,11 +208,6 @@ class Warehouse(Address, DashboardFormItem, OwnPerms): return -class WarehouseImage(ThroughImage): - item = models.ForeignKey(Warehouse, on_delete=models.CASCADE, - related_name='associated_images') - - class Collection(LightHistorizedItem): name = models.CharField(_(u"Name"), max_length=200, null=True, blank=True) diff --git a/archaeological_warehouse/views.py b/archaeological_warehouse/views.py index 913fbd3be..c801fbae6 100644 --- a/archaeological_warehouse/views.py +++ b/archaeological_warehouse/views.py @@ -22,16 +22,13 @@ import json from django.core.urlresolvers import reverse from django.db.models import Q from django.http import HttpResponse -from django.utils.translation import ugettext_lazy as _ from django.shortcuts import redirect +from django.utils.translation import ugettext_lazy as _ -import models - +from forms import * from ishtar_common.views import get_item, new_item, show_item from ishtar_common.wizards import SearchWizard from wizards import * -from ishtar_common.forms import FinalForm -from forms import * get_container = get_item(models.Container, 'get_container', 'container') show_container = show_item(models.Container, 'container') @@ -103,7 +100,6 @@ warehouse_search_wizard = SearchWizard.as_view([ warehouse_creation_steps = [ ("warehouse-warehouse_creation", WarehouseForm), - ('images-warehouse_creation', ImagesFormset), ('divisions-warehouse_creation', SelectedDivisionFormset), ('final-warehouse_creation', FinalForm)] @@ -117,7 +113,6 @@ warehouse_creation_wizard = WarehouseWizard.as_view( warehouse_modification_wizard = WarehouseModificationWizard.as_view([ ('selec-warehouse_modification', WarehouseFormSelection), ("warehouse-warehouse_modification", WarehouseForm), - ('images-warehouse_modifcation', ImagesFormset), ('divisions-warehouse_modification', SelectedDivisionFormset), ('final-warehouse_modification', FinalForm)], label=_(u"Warehouse modification"), diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py index 88583ad29..a6c79828d 100644 --- a/ishtar_common/admin.py +++ b/ishtar_common/admin.py @@ -961,14 +961,6 @@ class AdministrationScriptAdmin(admin.ModelAdmin): admin_site.register(models.AdministrationScript, AdministrationScriptAdmin) -class ImageAdmin(admin.ModelAdmin): - list_display = ('title', 'reference', 'internal_reference') - search_fields = ('name', 'reference', 'internal_reference') - - -admin_site.register(models.IshtarImage, ImageAdmin) - - class AdministrationTaskAdmin(admin.ModelAdmin): readonly_fields = ('state', 'creation_date', 'launch_date', 'finished_date', "result", ) diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 134e7ceb1..854fe2a71 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1184,61 +1184,3 @@ AuthorFormset = formset_factory(AuthorFormSelection, can_delete=True, AuthorFormset.form_label = _("Authors") AuthorFormset.form_admin_name = _(u"Authors") AuthorFormset.form_slug = "authors" - - -class BaseImageForm(ManageOldType): - form_label = _(u"Images") - base_model = 'image' - associated_models = {'licence': models.LicenseType, - 'authors': models.Author} - - pk = forms.IntegerField(label=" ", widget=forms.HiddenInput, - required=False) - image = forms.ImageField( - label=_(u"Image"), help_text=mark_safe(get_image_help()), - max_length=255, required=False, widget=widgets.ImageFileInput()) - name = forms.CharField(label=_(u"Name"), max_length=250, required=False) - authors = widgets.Select2MultipleField( - model=models.Author, remote=True, label=_(u"Authors"), - required=False, long_widget=True, new=True - ) - description = forms.CharField(label=_(u"Description"), required=False, - widget=forms.Textarea) - creation_date = forms.DateField( - label=_(u"Creation date"), required=False, widget=DatePicker) - licence = widgets.Select2MultipleField( - label=_(u"Licence"), required=False - ) - reference = forms.CharField(label=_(u"Ref."), max_length=250, - required=False) - internal_reference = forms.CharField(label=_(u"Internal ref."), - max_length=250, required=False) - is_main = forms.BooleanField(label=_(u"Main image"), required=False, - initial=False) - - TYPES = [ - FieldType('licence', models.LicenseType, True), - ] - - def count_valid_fields(self, data): - if not data: - return 0 - return len(get_data_from_formset(data)) - - -class BaseImageFormset(FormSet): - def clean(self): - """ - Verify that no two images are main image - """ - if any(self.errors): - return - have_main = False - for form in self.forms: - is_main = form.cleaned_data.get('is_main', False) - if not is_main: - continue - if is_main and have_main: - raise forms.ValidationError(_(u"Only one image can be a main " - u"image")) - have_main = True
\ No newline at end of file diff --git a/ishtar_common/ishtar_menu.py b/ishtar_common/ishtar_menu.py index 1b39ea3ca..6e61ede74 100644 --- a/ishtar_common/ishtar_menu.py +++ b/ishtar_common/ishtar_menu.py @@ -123,3 +123,29 @@ MENU_SECTIONS = [ access_controls=['change_import']), ])), ] +""" +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/ishtar_common/models.py b/ishtar_common/models.py index ef4ae63e2..995a2c136 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -51,7 +51,7 @@ from django.db.utils import DatabaseError from django.template.defaultfilters import slugify from django.utils.functional import lazy from django.utils.safestring import SafeUnicode, mark_safe -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _, ugettext from secretary import Renderer as SecretaryRenderer from simple_history.models import HistoricalRecords as BaseHistoricalRecords from unidecode import unidecode @@ -1244,7 +1244,14 @@ class FixAssociated(object): setattr(item, subkey, new_value) -class BaseHistorizedItem(FullSearch, Imported, JsonData, FixAssociated): +class DocumentItem(object): + @property + def images(self): + return self.documents.filter(image__isnull=False).exclude(image="") + + +class BaseHistorizedItem(FullSearch, Imported, JsonData, FixAssociated, + DocumentItem): """ Historized item with external ID management. All historized items are searcheable and have a data json field @@ -3079,7 +3086,18 @@ post_save.connect(post_save_cache, sender=LicenseType) post_delete.connect(post_save_cache, sender=LicenseType) -class BaseSource(OwnPerms, ImageModel, FullSearch): +class Document(OwnPerms, ImageModel, FullSearch): + # order is important: put the image in the first match found + # other will be symbolic links + RELATED_MODELS = [ + 'treatment_files', 'treatments', 'finds', 'context_records', + 'operations', 'sites', 'warehouses', + ] + + LINK_SPLIT = u"<||>" + + + title = models.TextField(_(u"Title"), blank=True, default='') index = models.IntegerField(verbose_name=_(u"Index"), blank=True, null=True) @@ -3125,21 +3143,51 @@ class BaseSource(OwnPerms, ImageModel, FullSearch): BASE_SEARCH_VECTORS = ['title', 'source_type__label', 'external_id', 'reference', 'description', 'comment', 'additional_information'] - PARENT_SEARCH_VECTORS = ['authors'] + PARENT_SEARCH_VECTORS = ['authors', ] class Meta: - abstract = True + verbose_name = _(u"Document") + verbose_name_plural = _(u"Documents") + ordering = ('title',) + permissions = ( + ("view_document", + ugettext(u"Can view all Documents")), + ("view_own_document", + ugettext(u"Can view own Document")), + ("add_own_document", + ugettext(u"Can add own Document")), + ("change_own_document", + ugettext(u"Can change own Document")), + ("delete_own_document", + ugettext(u"Can delete own Document")), + ) def __unicode__(self): return self.title + """ + @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): + Operation = cls.operations.rel.related_model + ArchaeologicalSite = cls.sites.rel.related_model + q = cls._construct_query_own( + 'operations__', Operation._get_query_owns_dicts(ishtaruser) + ) | cls._construct_query_own( + 'sites__', ArchaeologicalSite._get_query_owns_dicts(ishtaruser) + ) + return q + def get_associated_operation(self): raise NotImplementedError() - def _get_base_image_path(self): - base = self.owner._get_base_image_path() - return u"{}/sources".format(base) - @property def associated_filename(self): values = [unicode(getattr(self, attr)) @@ -3147,25 +3195,6 @@ class BaseSource(OwnPerms, ImageModel, FullSearch): if getattr(self, attr)] return slugify(u"-".join(values)) - -class Document(BaseSource): - pass - - -class IshtarImage(BaseSource): - # order is important: put the image in the first match found - # other will be symbolic links - RELATED_MODELS = [ - 'treatmentimage_set', 'findimage_set', 'contextrecordimage_set', - 'operationimage_set', 'siteimage_set', 'warehouseimage_set', - ] - LINK_SPLIT = u"<||>" - - class Meta: - verbose_name = _(u"Image") - verbose_name_plural = _(u"Images") - ordering = ('title',) - def _get_base_image_paths(self): for related_model in self.RELATED_MODELS: q = getattr(self, related_model).all() @@ -3269,8 +3298,7 @@ class IshtarImage(BaseSource): def save(self, *args, **kwargs): no_path_change = 'no_path_change' in kwargs \ and kwargs.pop('no_path_change') - - super(IshtarImage, self).save(*args, **kwargs) + super(Document, self).save(*args, **kwargs) if self.image and not no_path_change and \ not getattr(self, '_no_path_change', False): @@ -3281,24 +3309,6 @@ class IshtarImage(BaseSource): self.save(no_path_change=True) -class ThroughImage(models.Model): - image = models.ForeignKey( - IshtarImage, on_delete=models.CASCADE) - is_main = models.BooleanField(_(u"Main image"), default=False) - - class Meta: - ordering = ('-is_main', 'image__name') - abstract = True - - def save(self, force_insert=False, force_update=False, using=None, - update_fields=None): - super(ThroughImage, self).save( - force_insert=force_insert, force_update=force_update, using=using, - update_fields=update_fields) - # force relocation of image file and creation of symlinks - self.image.save() - - class Arrondissement(models.Model): name = models.CharField(u"Nom", max_length=30) department = models.ForeignKey(Department, verbose_name=u"Département") diff --git a/ishtar_common/templates/ishtar/blocks/window_image.html b/ishtar_common/templates/ishtar/blocks/window_image.html index 751fce377..092d224fe 100644 --- a/ishtar_common/templates/ishtar/blocks/window_image.html +++ b/ishtar_common/templates/ishtar/blocks/window_image.html @@ -1,10 +1,9 @@ {% load i18n %}{% if item.images.count %} <div class="lightgallery-captions"> - {% for associated_image in item.associated_images.all %} - {% with image=associated_image.image %} + {% for image in item.images.all %} <div id="lightgallery-{{window_id}}-caption-{{forloop.counter0}}"> <span class="close">×</span> - {% if image.name %}<h3>{{image.name}}</h3>{% endif %} + {% if image.title %}<h3>{{image.title}}</h3>{% endif %} {% if image.description %}<p class="raw-description"> {{image.description}} </p>{% endif %} @@ -78,17 +77,14 @@ </div> {% endif %} </div> - {% endwith %} {% endfor %} </div> <div id="lightgallery-{{window_id}}"> - {% for associated_image in item.associated_images.all %} - {% with image=associated_image.image %} + {% for image in item.images.all %} {% if output != "ODT" %}<a data-sub-html="#lightgallery-{{window_id}}-caption-{{forloop.counter0}}" href="{{image.image.url}}"{% if not forloop.first %} class="lightgallery-subimage"{% endif %}>{% endif %} <img{% if forloop.first %} class='card-img-top'{% endif %} src="{{BASE_URL}}{{image.thumbnail.url}}"> {% if output != "ODT" %}</a>{% endif %} - {% endwith %} {% endfor %} </div> {% endif%} diff --git a/ishtar_common/templates/ishtar/sheet_person.html b/ishtar_common/templates/ishtar/sheet_person.html index c1fe0504e..a37193572 100644 --- a/ishtar_common/templates/ishtar/sheet_person.html +++ b/ishtar_common/templates/ishtar/sheet_person.html @@ -103,6 +103,7 @@ {% dynamic_table_document af 'files' 'responsible_town_planning_service' item.pk '' output %} {% endif %} +{% comment %} {% if item.operation_docs_q.count %} {% trans "Documents associated to operations" as operation_docs %} {% dynamic_table_document operation_docs 'operation_docs' 'person' item.pk '' output %} @@ -117,6 +118,7 @@ {% trans "Documents associated to finds" as finds_docs %} {% dynamic_table_document finds_docs 'finds_docs' 'person' item.pk '' output %} {% endif %} +{% endcomment %} {% endblock %} diff --git a/ishtar_common/templatetags/window_tables.py b/ishtar_common/templatetags/window_tables.py index 9d83a554f..b442b4353 100644 --- a/ishtar_common/templatetags/window_tables.py +++ b/ishtar_common/templatetags/window_tables.py @@ -13,14 +13,11 @@ from ishtar_common.forms import reverse_lazy from ishtar_common.widgets import DataTable from archaeological_files.models import File -from archaeological_operations.models import OperationSource, Operation, \ - ArchaeologicalSite +from archaeological_operations.models import Operation, ArchaeologicalSite from archaeological_context_records.models import ContextRecord, \ - ContextRecordSource, RecordRelationView, \ - RecordRelations as CRRecordRelations -from archaeological_finds.models import Find, FindSource, \ - FindUpstreamTreatments, FindDownstreamTreatments, FindTreatments, \ - TreatmentSource, TreatmentFileSource + RecordRelationView, RecordRelations as CRRecordRelations +from archaeological_finds.models import Find, FindUpstreamTreatments, \ + FindDownstreamTreatments, FindTreatments from archaeological_warehouse.models import Container register = template.Library() @@ -33,17 +30,12 @@ def table_document(caption, data): ASSOCIATED_MODELS = {} ASSOCIATED_MODELS['files'] = (File, 'get-file', '') -ASSOCIATED_MODELS['operation_docs'] = ( - OperationSource, 'get-operationsource', 'get-operationsource-full') ASSOCIATED_MODELS['operations'] = (Operation, 'get-operation', '') ASSOCIATED_MODELS['context_records'] = (ContextRecord, 'get-contextrecord', 'get-contextrecord-full') ASSOCIATED_MODELS['context_records_for_ope'] = ( ContextRecord, 'get-contextrecord-for-ope', 'get-contextrecord-full') -ASSOCIATED_MODELS['context_records_docs'] = ( - ContextRecordSource, - 'get-contextrecordsource', 'get-contextrecordsource-full') ASSOCIATED_MODELS['context_records_relations'] = ( RecordRelationView, 'get-contextrecordrelation', '') ASSOCIATED_MODELS['context_records_relations_detail'] = ( @@ -55,18 +47,12 @@ ASSOCIATED_MODELS['finds_for_ope'] = ( Find, 'get-find-for-ope', 'get-find-full') ASSOCIATED_MODELS['finds_for_treatment'] = ( Find, 'get-find-for-treatment', 'get-find-full') -ASSOCIATED_MODELS['finds_docs'] = ( - FindSource, 'get-findsource', 'get-findsource-full') ASSOCIATED_MODELS['finds_upstreamtreatments'] = ( FindUpstreamTreatments, 'get-upstreamtreatment', '') ASSOCIATED_MODELS['finds_downstreamtreatments'] = ( FindDownstreamTreatments, 'get-downstreamtreatment', '') ASSOCIATED_MODELS['treatments'] = ( FindTreatments, 'get-treatment', '') -ASSOCIATED_MODELS['treatments_docs'] = ( - TreatmentSource, 'get-treatmentsource', '') -ASSOCIATED_MODELS['treatmentfiles_docs'] = ( - TreatmentFileSource, 'get-treatmentfilesource', '') ASSOCIATED_MODELS['containers'] = ( Container, 'get-container', '') diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index 5a3ed217d..a64e6ab24 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -225,6 +225,34 @@ urlpatterns += [ name='show-shortcut-menu'), url(r'(?P<action_slug>' + actions + r')/$', views.action, name='action'), ] +""" + 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'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}), +""" if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index ceaa7d27a..6c77563ef 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -34,7 +34,6 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.gis.geos import GEOSGeometry from django.contrib.sessions.backends.db import SessionStore from django.core.cache import cache -from django.core.exceptions import FieldDoesNotExist from django.core.files import File from django.core.urlresolvers import reverse from django.utils.datastructures import MultiValueDict as BaseMultiValueDict @@ -205,13 +204,22 @@ def disable_for_loaddata(signal_handler): return wrapper -def _get_image_link(rel): - item = rel.item - image = rel.image +def _get_image_link(doc): # manage missing images - if not image.thumbnail or not image.thumbnail.url or not image.image \ - or not image.image.url: + if not doc.thumbnail or not doc.thumbnail.url or not doc.image \ + or not doc.image.url: return "" + + item = None + for related_key in doc.__class__.RELATED_MODELS: + q = getattr(doc, related_key) + if q.count(): + item = q.all()[0] + break + if not item: + # image attached to nothing... + return "" + return mark_safe(u""" <div class="col col-lg-3"> <div class="card"> @@ -235,8 +243,8 @@ def _get_image_link(rel): <script type="text/javascript"> lightGallery(document.getElementById('lightgallery-rand-img')); </script>""".format( - image.image.url, - image.thumbnail.url, + doc.image.url, + doc.thumbnail.url, unicode(item.__class__._meta.verbose_name), unicode(item), reverse(item.SHOW_URL, args=[item.pk, '']), @@ -245,49 +253,22 @@ def _get_image_link(rel): def get_random_item_image_link(request): - from archaeological_operations.models import OperationImage, Operation - from archaeological_context_records.models import ContextRecordImage, \ - ContextRecord - from archaeological_finds.models import Find, FindImage, TreatmentImage - - ope_image_nb, cr_image_nb, find_image_nb = 0, 0, 0 - q_ope = OperationImage.objects.filter( - image__thumbnail__isnull=False, - image__image__isnull=False - ).exclude(image__thumbnail='').exclude(image__image='') - q_cr = ContextRecordImage.objects.filter( - image__thumbnail__isnull=False, - image__image__isnull=False - ).exclude(image__thumbnail='').exclude(image__image='') - q_find = FindImage.objects.filter( - image__thumbnail__isnull=False, - image__image__isnull=False - ).exclude(image__thumbnail='').exclude(image__image='') - if request.user.has_perm('archaeological_operations.view_operation', - Operation): - ope_image_nb = q_ope.count() - if request.user.has_perm( - 'archaeological_context_records.view_contextrecord', - ContextRecord): - cr_image_nb = q_cr.count() - if request.user.has_perm('archaeological_finds.view_find', - Find): - find_image_nb = q_find.count() - - image_total = ope_image_nb + cr_image_nb + find_image_nb - if not image_total: + from ishtar_common.models import Document + + if not request.user.has_perm('ishtar_common.view_document'): + return '' + + q = Document.objects.filter( + thumbnail__isnull=False, + image__isnull=False + ).exclude(thumbnail='').exclude(image='') + + total = q.count() + if not total: return '' - image_nb = random.randint(0, image_total - 1) - if image_nb >= 0 and image_nb < ope_image_nb: - return _get_image_link(q_ope.all()[image_nb]) - if image_nb >= ope_image_nb and image_nb < (cr_image_nb + ope_image_nb): - return _get_image_link(q_cr.all()[image_nb - ope_image_nb]) - if image_nb >= (cr_image_nb + ope_image_nb): - return _get_image_link(q_find.all()[ - image_nb - ope_image_nb - cr_image_nb]) - # should never happen except in case of deletion during the excution - return '' + image_nb = random.randint(0, total) + return _get_image_link(q.all()[image_nb]) def convert_coordinates_to_point(x, y, z=None, srid=4326): diff --git a/ishtar_common/views.py b/ishtar_common/views.py index c9a2d92dd..5d2b442bf 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -2482,3 +2482,52 @@ class OrganizationPersonEdit(LoginRequiredMixin, UpdateView): def get_success_url(self): return reverse('organization_person_edit', args=[self.object.pk]) + +""" + +show_operationsource = show_item(models.OperationSource, 'operationsource') +get_operationsource = get_item(models.OperationSource, 'get_operationsource', + 'operationsource') + +# 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',) +""" diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 3e153c9dd..b98c698ac 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -1781,3 +1781,42 @@ class SourceWizard(Wizard): if 'history_modifier' in dct: dct.pop('history_modifier') return dct + +""" +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'] +""" |