summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-08-01 12:41:44 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-08-13 18:26:03 +0200
commitb93797feaa842068f7b93676bddb7ca3e14eb356 (patch)
tree34a471d9e263947fdfc6e6f1c2287f2fd3cb411a
parent5bd94ea3b1083607642afaf014d2663ce420febf (diff)
downloadIshtar-b93797feaa842068f7b93676bddb7ca3e14eb356.tar.bz2
Ishtar-b93797feaa842068f7b93676bddb7ca3e14eb356.zip
Fix innapropriate parcel deletion
-rw-r--r--archaeological_operations/forms.py28
-rw-r--r--archaeological_operations/models.py12
-rw-r--r--ishtar_common/models.py6
-rw-r--r--ishtar_common/tests.py14
4 files changed, 34 insertions, 26 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index acce3835b..866700871 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -77,20 +77,6 @@ class ParcelForm(IshtarForm):
public_domain = forms.BooleanField(label=_(u"Public domain"),
initial=False, required=False)
- def count_valid_fields(self, data):
- if not data:
- return 0
- data = get_data_from_formset(data)
- nb = len(data)
- # remove last non relevant fields
- for idx, vals in enumerate(reversed(data[:])):
- if 'public_domain' in vals:
- break
- if 'section' in vals and 'parcel_number' in vals:
- break
- nb -= 1
- return nb
-
def __init__(self, *args, **kwargs):
towns = None
if 'data' in kwargs and 'TOWNS' in kwargs['data']:
@@ -106,6 +92,20 @@ class ParcelForm(IshtarForm):
if towns:
self.fields['town'].choices = towns
+ def count_valid_fields(self, data):
+ if not data:
+ return 0
+ data = get_data_from_formset(data)
+ nb = len(data)
+ # remove last non relevant fields
+ for idx, vals in enumerate(reversed(data[:])):
+ if 'public_domain' in vals:
+ break
+ if 'section' in vals and 'parcel_number' in vals:
+ break
+ nb -= 1
+ return nb
+
def clean(self):
"""Check required fields"""
if any(self.errors):
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 1c3bbde99..1a534af7a 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -1395,6 +1395,8 @@ def strip_zero(value):
class Parcel(LightHistorizedItem):
EXTERNAL_ID_KEY = 'parcel_external_id'
+ BASE_SEARCH_VECTORS = ['section', 'parcel_number']
+ PARENT_SEARCH_VECTORS = ['operation']
associated_file = models.ForeignKey(
'archaeological_files.File',
@@ -1569,21 +1571,27 @@ def parcel_post_save(sender, **kwargs):
if not kwargs['instance']:
return
parcel = kwargs['instance']
- created = kwargs.get('created', None)
cached_label_changed(sender, **kwargs)
updated = False
+
+ """
# remove when the parcel is linked to nothing
+ # problematic in wizards
+ # TODO: add admin action
if not getattr(parcel, '_updated_id', None) and not created \
and not parcel.operation and not parcel.associated_file:
if parcel.context_record.count():
# trying to restore a lost parcel
parcel.operation = parcel.context_record.all()[0].operation
updated = True
- else:
+ elif parcel.id:
parcel.delete()
return
+ else:
+ return
+ """
if updated:
parcel.save()
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 016883abe..b3ce847ce 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1113,8 +1113,8 @@ class FullSearch(models.Model):
if not hasattr(self, 'search_vector'):
return
if not self.pk:
- logger.warning("Cannot update search vector before save or "
- "after deletion.")
+ # logger.warning("Cannot update search vector before save or "
+ # "after deletion.")
return
if not self.BASE_SEARCH_VECTORS and not self.M2M_SEARCH_VECTORS \
and not self.INT_SEARCH_VECTORS \
@@ -1588,7 +1588,7 @@ class LightHistorizedItem(BaseHistorizedItem):
def save(self, *args, **kwargs):
super(LightHistorizedItem, self).save(*args, **kwargs)
- return True
+ return self
PARSE_FORMULA = re.compile("{([^}]*)}")
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index defc3a0c3..c2abab10c 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -285,17 +285,17 @@ class WizardTest(object):
def pass_test(self):
return False
- def check_response(self, response, current_step):
+ def check_response(self, response, current_step, data_idx):
if "errorlist" in response.content:
- soup = Soup(response.content)
+ soup = Soup(response.content, "lxml")
errorlist = soup.findAll(
"ul", {"class": "errorlist"})
errors = []
for li in errorlist:
lbl = li.findParent().findParent().findChild().text
errors.append(u"{} - {}".format(lbl, li.text))
- raise ValidationError(u"Errors: {} on {}.".format(
- u" ".join(errors), current_step))
+ raise ValidationError(u"Errors: {} on {} - dataset {}.".format(
+ u" ".join(errors), current_step, data_idx + 1))
@classmethod
def wizard_post(cls, client, url, current_step, form_data=None,
@@ -334,7 +334,7 @@ class WizardTest(object):
return
url = reverse(self.url_name)
self.pre_wizard()
- for test_form_data in self.form_datas:
+ for data_idx, test_form_data in enumerate(self.form_datas):
test_form_data.inits(self)
form_data = test_form_data.form_datas
ignored = test_form_data.ignored
@@ -353,9 +353,9 @@ class WizardTest(object):
if current_step == test_form_data.error_expected:
with self.assertRaises(ValidationError):
- self.check_response(response, current_step)
+ self.check_response(response, current_step, data_idx)
else:
- self.check_response(response, current_step)
+ self.check_response(response, current_step, data_idx)
if next_form_is_checked:
next_form = self.steps[idx + 1][0]