summaryrefslogtreecommitdiff
path: root/archaeological_context_records
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_context_records')
-rw-r--r--archaeological_context_records/forms.py63
-rw-r--r--archaeological_context_records/views.py4
-rw-r--r--archaeological_context_records/wizards.py6
3 files changed, 51 insertions, 22 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py
index 375943c9c..fef256b68 100644
--- a/archaeological_context_records/forms.py
+++ b/archaeological_context_records/forms.py
@@ -29,12 +29,13 @@ from django.forms.formsets import formset_factory
from django.utils.translation import ugettext_lazy as _
from ishtar_common.models import valid_id, IshtarSiteProfile, Town, \
- SpatialReferenceSystem
+ SpatialReferenceSystem, valid_ids
from archaeological_context_records import models
from ishtar_common.forms import FinalForm, FormSet, \
- reverse_lazy, get_form_selection, TableSelect, ManageOldType, CustomForm, \
- FieldType, CustomFormSearch, IshtarForm, FormHeader, HistorySelect
+ reverse_lazy, get_form_selection, ManageOldType, CustomForm, \
+ FieldType, CustomFormSearch, IshtarForm, FormHeader, HistorySelect, \
+ MultiSearchForm
from ishtar_common.forms_common import get_town_field
from archaeological_operations.forms import OperationSelect, ParcelField, \
RecordRelationsForm as OpeRecordRelationsForm, RecordRelationsFormSetBase
@@ -112,10 +113,35 @@ class RecordSelect(HistorySelect):
ids.append('ope_relation_types_{}'.format(idx))
return ids
+class BaseRecordFormSelection(object):
+ pk_key = None
-class RecordFormSelection(CustomFormSearch):
+ def clean(self):
+ cleaned_data = self.cleaned_data
+ print(self.cleaned_data, self.pk_key)
+ if self.pk_key not in cleaned_data or not cleaned_data[self.pk_key]:
+ raise forms.ValidationError(_(u"You should at least select one "
+ u"context record."))
+ pks = self.cleaned_data[self.pk_key]
+ if isinstance(pks, int):
+ pks = [pks]
+ else:
+ pks = pks.split(",")
+ for pk in pks:
+ try:
+ cr = models.ContextRecord.objects.get(pk=pk)
+ except models.ContextRecord.DoesNotExist:
+ raise forms.ValidationError(_("Invalid selection."))
+ if cr.locked:
+ raise forms.ValidationError(_("This context record is locked "
+ "for edition."))
+ return self.cleaned_data
+
+
+class RecordFormSelection(BaseRecordFormSelection, CustomFormSearch):
SEARCH_AND_SELECT = True
form_label = _("Context record search")
+ pk_key = 'pk'
associated_models = {'pk': models.ContextRecord}
currents = {'pk': models.ContextRecord}
@@ -128,20 +154,21 @@ class RecordFormSelection(CustomFormSearch):
source_full=reverse_lazy('get-contextrecord-full')),
validators=[valid_id(models.ContextRecord)])
- def clean(self):
- cleaned_data = self.cleaned_data
- if 'pk' not in cleaned_data or not cleaned_data['pk']:
- raise forms.ValidationError(_(u"You should at least select one "
- u"context record."))
- pk = self.cleaned_data["pk"]
- try:
- cr = models.ContextRecord.objects.get(pk=pk)
- except models.ContextRecord.DoesNotExist:
- raise forms.ValidationError(_("Invalid selection."))
- if cr.locked:
- raise forms.ValidationError(_("This context record is locked for "
- "edition."))
- return self.cleaned_data
+
+class RecordFormMultiSelection(BaseRecordFormSelection, MultiSearchForm):
+ form_label = _("Context record search")
+ associated_models = {'pks': models.ContextRecord}
+ pk_key = 'pks'
+
+ pk = forms.CharField(
+ label="", required=False,
+ widget=widgets.DataTable(
+ reverse_lazy('get-contextrecord'),
+ RecordSelect, models.ContextRecord,
+ multiple_select=True,
+ gallery=True, map=True,
+ source_full=reverse_lazy('get-contextrecord-full')),
+ validators=[valid_ids(models.ContextRecord)])
class RecordFormGeneral(CustomForm, ManageOldType):
diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py
index 20718b33f..2493c9ba7 100644
--- a/archaeological_context_records/views.py
+++ b/archaeological_context_records/views.py
@@ -145,7 +145,7 @@ def record_modify(request, pk):
kwargs={'step': 'operation-record_modification'}))
record_deletion_wizard = wizards.RecordDeletionWizard.as_view([
- ('selec-record_deletion', forms.RecordFormSelection),
+ ('selec-record_deletion', forms.RecordFormMultiSelection),
('final-record_deletion', forms.RecordDeletionForm)],
label=_(u"Context record deletion"),
url_name='record_deletion',)
@@ -157,7 +157,7 @@ def record_delete(request, pk):
return HttpResponseRedirect("/")
wizards.RecordDeletionWizard.session_set_value(
- request, 'selec-record_deletion', 'pk', pk, reset=True)
+ request, 'selec-record_deletion', 'pks', pk, reset=True)
return redirect(reverse('record_deletion',
kwargs={'step': 'final-record_deletion'}))
diff --git a/archaeological_context_records/wizards.py b/archaeological_context_records/wizards.py
index f0f11a1f3..c880f2a4f 100644
--- a/archaeological_context_records/wizards.py
+++ b/archaeological_context_records/wizards.py
@@ -22,7 +22,7 @@ from django.utils.translation import ugettext_lazy as _
from . import models
from ishtar_common.forms import reverse_lazy
-from ishtar_common.wizards import Wizard, DeletionWizard, SearchWizard
+from ishtar_common.wizards import Wizard, MultipleDeletionWizard, SearchWizard
class RecordSearch(SearchWizard):
@@ -34,6 +34,7 @@ class RecordWizard(Wizard):
edit = False
wizard_done_window = reverse_lazy('show-contextrecord')
relations_step_key = 'relations'
+ redirect_url = 'record_modification'
def get_template_names(self):
templates = super(RecordWizard, self).get_template_names()
@@ -147,10 +148,11 @@ class RecordModifWizard(RecordWizard):
return kwargs
-class RecordDeletionWizard(DeletionWizard):
+class RecordDeletionWizard(MultipleDeletionWizard):
model = models.ContextRecord
fields = ['label', 'parcel', 'description', 'length', 'width', 'thickness',
'depth', 'location', 'datings', 'units', 'documentations',
'filling', 'interpretation', 'taq', 'taq_estimated', 'tpq',
'tpq_estimated']
filter_owns = {'selec-record_deletion': ['pk']}
+ redirect_url = "record_deletion"