From 9a71511b55615c2b83d8dee18e1863391ab95654 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 16 Nov 2018 17:55:00 +0100 Subject: Wizard: display selected on final wizard panel --- ishtar_common/forms.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'ishtar_common/forms.py') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 20c65971e..63551ede2 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -341,6 +341,38 @@ class CustomForm(BSForm): return sorted(customs, key=lambda x: x[1]) +class PkWizardSearch(object): + current_model = None + pk_key = None + + @classmethod + def get_formated_datas(cls, cleaned_datas): + if not cls.current_model or not cls.pk_key: + return [] + items = [] + for data in cleaned_datas: + if not data or cls.pk_key not in data or not data[cls.pk_key]: + continue + pks = data[cls.pk_key] + for pk in unicode(pks).split(u','): + if not pk: + continue + try: + items.append( + unicode(cls.current_model.objects.get(pk=int(pk))) + ) + except (cls.current_model.DoesNotExist, ValueError): + continue + return [ + (u"", + mark_safe( + u"" + )) + ] + + + class CustomFormSearch(forms.Form): need_user_for_initialization = True -- cgit v1.2.3 From b58be9a09ae45763da6a08ab00abb62fa83fea04 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 16 Nov 2018 18:02:29 +0100 Subject: Treatment: fix save with multiple items --- archaeological_finds/wizards.py | 19 ++++++++++++------- ishtar_common/forms.py | 1 - 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'ishtar_common/forms.py') diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py index 3314759d1..8a7a3a513 100644 --- a/archaeological_finds/wizards.py +++ b/archaeological_finds/wizards.py @@ -156,19 +156,24 @@ class TreatmentWizard(Wizard): """ dct = super(TreatmentWizard, self).get_extra_model(dct, form_list) if 'resulting_pk' in dct: - try: - find = models.Find.objects.get(pk=dct.pop('resulting_pk')) - if 'own' in self.current_right \ - and not find.is_own(dct['history_modifier']): + dct['items'] = [] + pks = dct.pop('resulting_pk').split(u',') + for pk in pks: + try: + find = models.Find.objects.get(pk=pk) + dct['items'].append(find) + except models.Find.DoesNotExist: raise PermissionDenied - dct['items'] = [find] - except models.Find.DoesNotExist: - raise PermissionDenied if 'basket' in dct: basket = dct.pop('basket') if basket.user.pk != dct['history_modifier'].pk: raise PermissionDenied dct['items'] = list(basket.items.all()) + + for find in dct['items']: + if 'own' in self.current_right \ + and not find.is_own(dct['history_modifier']): + raise PermissionDenied return dct diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 63551ede2..0c93016b1 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -372,7 +372,6 @@ class PkWizardSearch(object): ] - class CustomFormSearch(forms.Form): need_user_for_initialization = True -- cgit v1.2.3 From 97f43cba1ba5204f2da685c04aed5770ff3d68a8 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 4 Dec 2018 11:15:44 +0100 Subject: Fix wizard permissions call --- ishtar_common/forms.py | 7 +++++-- ishtar_common/wizards.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'ishtar_common/forms.py') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 0c93016b1..b27d4cf4d 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -745,8 +745,11 @@ class QAForm(CustomForm, ManageOldType): elif hasattr(self.fields[k], "choices"): values = [] for v in kwargs['data'].getlist(k): - values.append( - dict(self.fields[k].choices)[int(v)]) + dct_choices = dict(self.fields[k].choices) + if v in dct_choices: + values.append(dct_choices[v]) + elif int(v) in dct_choices: + values.append(dct_choices[int(v)]) self.fields[k].rendered_value = mark_safe( u" ; ".join(values)) if k not in self.REPLACE_FIELDS: diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 446afc71e..47355dd06 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -147,7 +147,7 @@ class Wizard(IshtarWizard): form, other_check) return kwargs - def check_own_permissions(self, request, step, *args, **kwargs): + def check_own_permissions(self, request, step=None, *args, **kwargs): # reinit default dispatch of a wizard - not clean... self.request = request self.session = request.session @@ -179,7 +179,7 @@ class Wizard(IshtarWizard): step = kwargs.get('step', None) # check that the current object is really owned by the current user if step and self.current_right and '_own_' in self.current_right: - if not self.check_permissions(request, step, *args, **kwargs): + if not self.check_own_permissions(request, *args, **kwargs): return HttpResponseRedirect('/') # extra filter on forms self.filter_owns_items = True -- cgit v1.2.3 From b462c0c9a34f0bfde560456fa0618479b3afaa47 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 4 Dec 2018 11:38:58 +0100 Subject: Translation --- ishtar_common/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ishtar_common/forms.py') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index b27d4cf4d..e7f73f2d9 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -754,10 +754,10 @@ class QAForm(CustomForm, ManageOldType): u" ; ".join(values)) if k not in self.REPLACE_FIELDS: self.fields[k].label = unicode(self.fields[k].label) + \ - unicode(u" - append to existing") + unicode(_(u" - append to existing")) else: self.fields[k].label = unicode(self.fields[k].label) + \ - unicode(u" - replace") + unicode(_(u" - replace")) def _set_value(self, item, base_key): value = self.cleaned_data[base_key] -- cgit v1.2.3 From 6d89609a716ec59397517c0b0446f9568de16a4a Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 5 Dec 2018 19:23:00 +0100 Subject: QA bulk edit: fix confirm --- ishtar_common/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ishtar_common/forms.py') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index e7f73f2d9..18e32cd76 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -747,9 +747,9 @@ class QAForm(CustomForm, ManageOldType): for v in kwargs['data'].getlist(k): dct_choices = dict(self.fields[k].choices) if v in dct_choices: - values.append(dct_choices[v]) + values.append(unicode(dct_choices[v])) elif int(v) in dct_choices: - values.append(dct_choices[int(v)]) + values.append(unicode(dct_choices[int(v)])) self.fields[k].rendered_value = mark_safe( u" ; ".join(values)) if k not in self.REPLACE_FIELDS: -- cgit v1.2.3 From 9eced41d76545bd2921605b7b81bd14b875ce541 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 10 Jan 2019 17:30:03 +0100 Subject: Formset: delete empty forms --- ishtar_common/forms.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'ishtar_common/forms.py') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 18e32cd76..91e9fb3e9 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -436,6 +436,22 @@ class FormSet(CustomForm, BaseFormSet): form.fields[DELETION_FIELD_NAME].label = '' form.fields[DELETION_FIELD_NAME].widget = self.delete_widget() + def _should_delete_form(self, form): + """ + Returns whether or not the form was marked for deletion. + If no data, set deletion to True + """ + if form.cleaned_data.get(DELETION_FIELD_NAME, False): + return True + if not form.cleaned_data or not [ + __ for __ in form.cleaned_data + if __ != DELETION_FIELD_NAME and + form.cleaned_data[__] is not None and + form.cleaned_data[__] != '']: + form.cleaned_data[DELETION_FIELD_NAME] = True + return True + return False + class FormSetWithDeleteSwitches(FormSet): delete_widget = widgets.DeleteSwitchWidget -- cgit v1.2.3