summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-14 10:48:39 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-14 10:48:39 +0200
commit166c5c7ea1a433f8e901bfc04a8b0c75fde1c207 (patch)
tree693c0fb95c2fcd330a2fbad4224274ea30347451
parenteb58fad63f8f41b275303b3c3e9e5fc75c963d80 (diff)
downloadIshtar-166c5c7ea1a433f8e901bfc04a8b0c75fde1c207.tar.bz2
Ishtar-166c5c7ea1a433f8e901bfc04a8b0c75fde1c207.zip
Find - treatments: multi del - redirects
-rw-r--r--archaeological_finds/forms.py56
-rw-r--r--archaeological_finds/forms_treatments.py18
-rw-r--r--archaeological_finds/views.py10
-rw-r--r--archaeological_finds/wizards.py63
-rw-r--r--archaeological_operations/forms.py2
-rw-r--r--ishtar_common/wizards.py8
6 files changed, 106 insertions, 51 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index a08821d85..628b08161 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -38,6 +38,7 @@ from archaeological_finds.forms_treatments import TreatmentSelect, \
AdministrativeActTreatmentForm, TreatmentFormFileChoice, \
TreatmentDeletionForm, TreatmentFileSelect, TreatmentFileFormSelection, \
TreatmentFileForm, TreatmentFileModifyForm, TreatmentFileDeletionForm, \
+ TreatmentFileFormSelectionMultiple, \
AdministrativeActTreatmentFormSelection, \
AdministrativeActTreatmentModifForm, \
AdministrativeActTreatmentFileForm, \
@@ -54,7 +55,7 @@ from ishtar_common import widgets
from ishtar_common.forms import CustomForm, CustomFormSearch, FormSet, \
FloatField, reverse_lazy, TableSelect, get_now, FinalForm, \
ManageOldType, FieldType, IshtarForm, FormHeader, QAForm, HistorySelect, \
- MultiSearchForm
+ MultiSearchForm, LockForm
from ishtar_common.forms_common import get_town_field
from ishtar_common.models import valid_id, valid_ids, get_current_profile, \
SpatialReferenceSystem, Area, OperationType, IshtarUser
@@ -1234,7 +1235,7 @@ class FindSelectWarehouseModule(FindSelect):
container__reference = forms.CharField(label=_(u"Current container ref."))
-class FindFormSelection(CustomFormSearch):
+class FindFormSelection(LockForm, CustomFormSearch):
SEARCH_AND_SELECT = True
form_label = _("Find search")
associated_models = {'pk': models.Find}
@@ -1250,21 +1251,21 @@ class FindFormSelection(CustomFormSearch):
source_full=reverse_lazy('get-find-full')),
validators=[valid_id(models.Find)])
- def clean(self):
- pk = self.cleaned_data[self.pk_key]
- if "," in str(pk):
- pks = [k.strip() for k in pk.split(',')]
- else:
- pks = [pk]
- for pk in pks:
- try:
- find = models.Find.objects.get(pk=pk)
- except models.Find.DoesNotExist:
- raise forms.ValidationError(_("Invalid selection."))
- if find.locked:
- raise forms.ValidationError(
- _("This find is locked for edition."))
- return self.cleaned_data
+
+class FindFormMultiSelection(LockForm, MultiSearchForm):
+ form_label = _("Find search")
+ associated_models = {'pks': models.Find}
+ pk_key = 'pks'
+
+ pk = forms.CharField(
+ label="", required=False,
+ widget=widgets.DataTable(
+ reverse_lazy('get-find'),
+ FindSelect, models.Find,
+ gallery=True, map=True,
+ multiple_select=True,
+ source_full=reverse_lazy('get-find-full')),
+ validators=[valid_ids(models.Find)])
class FindFormSelectionWarehouseModule(FindFormSelection):
@@ -1279,7 +1280,21 @@ class FindFormSelectionWarehouseModule(FindFormSelection):
extra_form_modals = ["warehouse", "container"]
+class FindFormMultiSelectionWarehouseModule(FindFormMultiSelection):
+ pk = forms.CharField(
+ label="", required=False,
+ widget=widgets.DataTable(
+ reverse_lazy('get-find'),
+ FindSelectWarehouseModule, models.Find,
+ gallery=True, map=True,
+ multiple_select=True,
+ source_full=reverse_lazy('get-find-full')),
+ validators=[valid_ids(models.Find)])
+
+
class MultipleFindFormSelection(forms.Form):
+ # used for basket management
+ # TODO: could probably use FindFormMultiSelection
form_label = _("Find search")
associated_models = {'pk': models.Find}
currents = {'pk': models.Find}
@@ -1295,6 +1310,8 @@ class MultipleFindFormSelection(forms.Form):
class MultipleFindFormSelectionWarehouseModule(MultipleFindFormSelection):
+ # used for basket management
+ # TODO: could probably use FindFormMultiSelectionWarehouse
pk = forms.IntegerField(
label="", required=False,
widget=widgets.DataTable(
@@ -1456,6 +1473,7 @@ class UpstreamFindFormSelection(MultiSearchForm, FindFormSelection):
form_label = _(u"Upstream finds")
current_model = models.Find
pk_key = 'resulting_pk'
+ associated_models = {"resulting_pk": models.Find}
pk = forms.CharField(
label="", required=False,
@@ -1467,10 +1485,6 @@ class UpstreamFindFormSelection(MultiSearchForm, FindFormSelection):
source_full=reverse_lazy('get-find-full')),
validators=[valid_ids(current_model)])
- def __init__(self, *args, **kwargs):
- super(UpstreamFindFormSelection, self).__init__(*args, **kwargs)
- self.fields['pk'].required = True
- self.fields['resulting_pk'] = self.fields.pop('pk')
class SingleUpstreamFindFormSelection(UpstreamFindFormSelection):
diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py
index 08744ed0b..c9dcdea86 100644
--- a/archaeological_finds/forms_treatments.py
+++ b/archaeological_finds/forms_treatments.py
@@ -33,8 +33,9 @@ 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, HistorySelect
-from ishtar_common.models import Person, valid_id, Organization, \
+ ManageOldType, CustomForm, FieldType, IshtarForm, HistorySelect, \
+ MultiSearchForm
+from ishtar_common.models import Person, valid_id, valid_ids, Organization, \
get_current_profile
logger = logging.getLogger(__name__)
@@ -670,6 +671,19 @@ class TreatmentFileFormSelection(forms.Form):
validators=[valid_id(models.TreatmentFile)])
+class TreatmentFileFormSelectionMultiple(MultiSearchForm):
+ form_label = _("Treatment request search")
+ associated_models = {'pks': models.TreatmentFile}
+ pk = forms.CharField(
+ label="", required=False,
+ widget=widgets.DataTable(
+ reverse_lazy('get-treatmentfile'),
+ TreatmentFileSelect, models.TreatmentFile,
+ multiple_select=True
+ ),
+ validators=[valid_ids(models.TreatmentFile)])
+
+
class TreatmentFileForm(ManageOldType):
form_label = _(u"Treatment request")
base_models = ['treatment_type_type']
diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py
index 537532511..e5c09371b 100644
--- a/archaeological_finds/views.py
+++ b/archaeological_finds/views.py
@@ -349,8 +349,8 @@ find_deletion_condition_dict = {
}
find_deletion_steps = [
- ('selec-find_deletion', forms.FindFormSelection),
- ('selecw-find_deletion', forms.FindFormSelectionWarehouseModule),
+ ('selec-find_deletion', forms.FindFormMultiSelection),
+ ('selecw-find_deletion', forms.FindFormMultiSelectionWarehouseModule),
('final-find_deletion', forms.FindDeletionForm)]
find_deletion_wizard = wizards.FindDeletionWizard.as_view(
@@ -369,7 +369,7 @@ def find_delete(request, pk):
if get_current_profile().warehouse:
key = 'selecw-find_deletion'
wizards.FindDeletionWizard.session_set_value(
- request, key, 'pk', pk, reset=True)
+ request, key, 'pks', pk, reset=True)
step = 'final-find_deletion'
return redirect(
@@ -865,7 +865,7 @@ def treatmentfile_add(request, basket_pk=None):
treatmentfile_deletion_wizard = wizards.TreatmentFileDeletionWizard.as_view([
- ('selec-treatmentfile_deletion', forms.TreatmentFileFormSelection),
+ ('selec-treatmentfile_deletion', forms.TreatmentFileFormSelectionMultiple),
('final-treatmentfile_deletion', forms.TreatmentFileDeletionForm)],
label=_(u"Treatment request deletion"),
url_name='treatmentfile_deletion',)
@@ -877,7 +877,7 @@ def treatmentfile_delete(request, pk):
return HttpResponseRedirect("/")
wizard_url = "treatmentfile_deletion"
wizards.TreatmentFileDeletionWizard.session_set_value(
- request, 'selec-' + wizard_url, 'pk', pk, reset=True)
+ request, 'selec-' + wizard_url, 'pks', pk, reset=True)
return redirect(
reverse(wizard_url, kwargs={'step': 'final-' + wizard_url}))
diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py
index 42f5f47c6..b34bcdcbe 100644
--- a/archaeological_finds/wizards.py
+++ b/archaeological_finds/wizards.py
@@ -22,7 +22,8 @@ from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
from django.utils.translation import ugettext_lazy as _, pgettext
from ishtar_common.forms import reverse_lazy
-from ishtar_common.wizards import Wizard, DeletionWizard, SearchWizard
+from ishtar_common.wizards import Wizard, DeletionWizard, SearchWizard, \
+ MultipleDeletionWizard
from archaeological_operations.wizards import OperationAdministrativeActWizard
from archaeological_operations.models import AdministrativeAct
@@ -37,6 +38,7 @@ class FindSearch(SearchWizard):
class FindWizard(Wizard):
model = models.Find
wizard_done_window = reverse_lazy('show-find')
+ redirect_url = "find_modification"
def get_current_contextrecord(self):
step = self.steps.current
@@ -107,7 +109,7 @@ class FindModificationWizard(FindWizard):
}
-class FindDeletionWizard(DeletionWizard):
+class FindDeletionWizard(MultipleDeletionWizard):
model = models.Find
main_item_select_keys = ('selec-', 'selecw-')
fields = ['label', 'material_types', 'datings', 'find_number',
@@ -115,6 +117,7 @@ class FindDeletionWizard(DeletionWizard):
'preservation_to_considers', 'integrities', 'remarkabilities',
'volume', 'weight', 'length', 'width', 'height', 'diameter',
'comment']
+ redirect_url = "find_deletion"
class TreatmentSearch(SearchWizard):
@@ -126,6 +129,7 @@ class TreatmentBase(Wizard):
wizard_done_window = reverse_lazy('show-treatment')
base_url = ""
saved_args = {"treatment_type_list": []}
+ redirect_url = "treatment_search"
def get_current_finds(self):
step = self.steps.current
@@ -189,13 +193,19 @@ class TreatmentWizard(TreatmentBase):
dct = super(TreatmentWizard, self).get_extra_model(dct, m2m, form_list)
if 'resulting_pk' in dct:
dct['items'] = []
- pks = dct.pop('resulting_pk').split(u',')
+ pks = dct.pop('resulting_pk')
+ if not isinstance(pks, (list, tuple)):
+ pks = pks.split(u',')
+
for pk in pks:
- try:
- find = models.Find.objects.get(pk=pk)
- dct['items'].append(find)
- except models.Find.DoesNotExist:
- raise PermissionDenied
+ if isinstance(pk, models.Find):
+ find = pk
+ else:
+ try:
+ find = models.Find.objects.get(pk=pk)
+ except models.Find.DoesNotExist:
+ raise PermissionDenied
+ dct['items'].append(find)
if 'basket' in dct:
basket = dct.pop('basket')
if basket.user.pk != dct['history_modifier'].pk:
@@ -316,11 +326,14 @@ class TreatmentN1Wizard(TreatmentBase):
if hasattr(pks, 'split'):
pks = pks.split(',') # string
for pk in pks:
- try:
- find = models.Find.objects.get(pk=pk)
- dct['upstream_items'].append(find)
- except models.Find.DoesNotExist:
- raise PermissionDenied
+ if isinstance(pk, models.Find):
+ find = pk
+ else:
+ try:
+ find = models.Find.objects.get(pk=pk)
+ except models.Find.DoesNotExist:
+ raise PermissionDenied
+ dct['upstream_items'].append(find)
for find in dct['upstream_items']:
if 'own' in self.current_right \
@@ -341,6 +354,8 @@ class Treatment1NWizard(TreatmentBase):
saved_args = {"upstream_item": None, "resulting_finds": None,
"treatment_type_list": []}
base_url = 'treatment_creation_1n'
+ redirect_url = "find_modification"
+ open_created_in_redirect = False
def get_form_kwargs(self, step, **kwargs):
kwargs = super(Treatment1NWizard, self).get_form_kwargs(step, **kwargs)
@@ -372,11 +387,14 @@ class Treatment1NWizard(TreatmentBase):
# manage upstream item
pk = dct.pop('resulting_pk')
- try:
- find = models.Find.objects.get(pk=pk)
- dct['upstream_item'] = find
- except models.Find.DoesNotExist:
- raise PermissionDenied
+ if isinstance(pk, models.Find):
+ find = pk
+ else:
+ try:
+ find = models.Find.objects.get(pk=pk)
+ except models.Find.DoesNotExist:
+ raise PermissionDenied
+ dct['upstream_item'] = find
if 'own' in self.current_right \
and not find.is_own(dct['history_modifier']):
@@ -409,12 +427,14 @@ class TreatmentDeletionWizard(DeletionWizard):
'treatment_types', 'location', 'person', 'organization',
'external_id', 'comment', 'description',
'goal', 'start_date', 'end_date', 'container']
+ redirect_url = "treatment_deletion"
class TreatmentAdministrativeActWizard(OperationAdministrativeActWizard):
model = models.Treatment
current_obj_slug = 'administrativeacttreatment'
ref_object_key = 'treatment'
+ redirect_url = "treatment_admacttreatment_modification"
def get_reminder(self):
return
@@ -435,17 +455,19 @@ class TreatmentFileSearch(SearchWizard):
class TreatmentFileWizard(Wizard):
model = models.TreatmentFile
wizard_done_window = reverse_lazy('show-treatmentfile')
+ redirect_url = "treatmentfile_modification"
class TreatmentFileModificationWizard(TreatmentFileWizard):
modification = True
-class TreatmentFileDeletionWizard(DeletionWizard):
+class TreatmentFileDeletionWizard(MultipleDeletionWizard):
model = models.TreatmentFile
fields = ['name', 'internal_reference', 'external_id', 'year',
'index', 'type', 'in_charge', 'reception_date',
'creation_date', 'end_date', 'comment']
+ redirect_url = "treatmentfile_deletion"
class TreatmentFileAdministrativeActWizard(
@@ -453,6 +475,7 @@ class TreatmentFileAdministrativeActWizard(
model = models.TreatmentFile
current_obj_slug = 'administrativeacttreatmentfile'
ref_object_key = 'treatment_file'
+ redirect_url = "treatmentfle_admacttreatmentfle_modification"
def get_reminder(self):
form_key = 'selec-' + self.url_name
@@ -496,6 +519,7 @@ class FindBasketSearch(SearchWizard):
class FindBasketWizard(Wizard):
model = models.FindBasket
wizard_done_window = reverse_lazy('show-findbasket')
+ redirect_url = "find_basket_modification"
class FindBasketEditWizard(FindBasketWizard):
@@ -514,4 +538,5 @@ class FindBasketEditWizard(FindBasketWizard):
class FindBasketDeletionWizard(DeletionWizard):
model = models.FindBasket
+ redirect_url = "find_basket_deletion"
wizard_confirm = 'ishtar/wizard/wizard_findbasket_deletion.html'
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index 1ac451505..3bef38a9c 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -54,7 +54,7 @@ class ParcelField(forms.MultiValueField):
def __init__(self, *args, **kwargs):
if 'widget' not in kwargs:
self.widget = ParcelWidget()
- return super(ParcelField, self).__init__(*args, **kwargs)
+ super(ParcelField, self).__init__(*args, **kwargs)
def compress(self, data_list):
return u"-".join(data_list)
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py
index 0c13139df..f36976684 100644
--- a/ishtar_common/wizards.py
+++ b/ishtar_common/wizards.py
@@ -122,6 +122,7 @@ class Wizard(IshtarWizard):
wizard_done_template = 'ishtar/wizard/wizard_done.html'
wizard_done_window = ''
redirect_url = None
+ open_created_in_redirect = True
wizard_confirm = 'ishtar/wizard/confirm_wizard.html'
wizard_templates = {}
filter_owns = {}
@@ -955,9 +956,10 @@ class Wizard(IshtarWizard):
self.current_object = obj
if self.redirect_url:
- return HttpResponseRedirect(
- reverse(self.redirect_url) + "?open_item={}".format(obj.pk)
- )
+ url = reverse(self.redirect_url)
+ if self.open_created_in_redirect:
+ url += "?open_item={}".format(obj.pk)
+ return HttpResponseRedirect(url)
# force evaluation of lazy urls
wizard_done_window = str(self.wizard_done_window)