diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/admin.py | 8 | ||||
-rw-r--r-- | ishtar_common/forms_common.py | 58 | ||||
-rw-r--r-- | ishtar_common/ishtar_menu.py | 26 | ||||
-rw-r--r-- | ishtar_common/models.py | 106 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/blocks/window_image.html | 10 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/sheet_person.html | 2 | ||||
-rw-r--r-- | ishtar_common/templatetags/window_tables.py | 22 | ||||
-rw-r--r-- | ishtar_common/urls.py | 28 | ||||
-rw-r--r-- | ishtar_common/utils.py | 79 | ||||
-rw-r--r-- | ishtar_common/views.py | 49 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 39 |
11 files changed, 239 insertions, 188 deletions
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'] +""" |