From 86c03a98d11e93880b4568776e0939113a92a707 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 27 Feb 2019 20:44:52 +0100 Subject: Migrate to python 3 - Clean old migrations and some old scripts --- ishtar_common/forms.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'ishtar_common/forms.py') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index df86d8815..9b1e2da48 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -67,14 +67,14 @@ def my_reverse(*args, **kwargs): my_args = [] for arg in kwargs['args']: if callable(arg): - my_args.append(unicode(arg())) + my_args.append(str(arg())) else: - my_args.append(unicode(arg)) + my_args.append(str(arg)) kwargs['args'] = my_args return reverse(*args, **kwargs) -reverse_lazy = lazy(my_reverse, unicode) +reverse_lazy = lazy(my_reverse, str) regexp_name = re.compile(r"^[,:/\w\-'\"() \&\[\]@]+$", re.UNICODE) name_validator = validators.RegexValidator( @@ -87,7 +87,7 @@ def file_size_validator(value): limit = (settings.MAX_UPLOAD_SIZE * 1024 * 1024) - 100 if value.size > limit: raise ValidationError( - unicode(_(u'File too large. Size should not exceed {} Mo.')).format( + str(_(u'File too large. Size should not exceed {} Mo.')).format( settings.MAX_UPLOAD_SIZE ) ) @@ -98,7 +98,7 @@ class FloatField(forms.FloatField): Allow the use of comma for separating float fields """ def clean(self, value): - if value and (isinstance(value, unicode) or isinstance(value, str)): + if value and (isinstance(value, str) or isinstance(value, str)): value = value.replace(',', '.').replace('%', '') return super(FloatField, self).clean(value) @@ -376,12 +376,12 @@ class PkWizardSearch(object): 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','): + for pk in str(pks).split(u','): if not pk: continue try: items.append( - unicode(cls.current_model.objects.get(pk=int(pk))) + str(cls.current_model.objects.get(pk=int(pk))) ) except (cls.current_model.DoesNotExist, ValueError): continue @@ -613,11 +613,11 @@ class TableSelect(IshtarForm): self.fields[k].alt_name = alt_names[k].search_key else: self.fields[k].alt_name = k - key = self.fields.keys()[0] + key = list(self.fields.keys())[0] self.fields[key].widget.attrs['autofocus'] = 'autofocus' def get_input_ids(self): - return self.fields.keys() + return list(self.fields.keys()) class HistorySelect(CustomForm, TableSelect): @@ -804,7 +804,7 @@ class QAForm(CustomForm, ManageOldType): self.items = kwargs.pop('items') self.confirm = kwargs.pop('confirm') super(QAForm, self).__init__(*args, **kwargs) - for k in self.fields.keys(): + for k in list(self.fields.keys()): if self.MULTI and k in self.SINGLE_FIELDS: self.fields.pop(k) continue @@ -831,17 +831,17 @@ class QAForm(CustomForm, ManageOldType): else: dct_choices[key] = value if v in list(dct_choices.keys()): - values.append(unicode(dct_choices[v])) + values.append(str(dct_choices[v])) elif int(v) in list(dct_choices.keys()): - values.append(unicode(dct_choices[int(v)])) + values.append(str(dct_choices[int(v)])) self.fields[k].rendered_value = mark_safe( u" ; ".join(values)) if k not in self.REPLACE_FIELDS: - self.fields[k].label = unicode(self.fields[k].label) + \ - unicode(_(u" - append to existing")) + self.fields[k].label = str(self.fields[k].label) + \ + str(_(u" - append to existing")) else: - self.fields[k].label = unicode(self.fields[k].label) + \ - unicode(_(u" - replace")) + self.fields[k].label = str(self.fields[k].label) + \ + str(_(u" - replace")) def _set_value(self, item, base_key): value = self.cleaned_data[base_key] -- cgit v1.2.3