From 6fc502609ebde844223f436223f893449baf4342 Mon Sep 17 00:00:00 2001 From: Vladislav Yena Date: Thu, 20 Feb 2020 17:30:51 +0200 Subject: [PATCH 1/3] Remove unicode characters, add the correct HTML rendering for the Form Advanced plugin --- aldryn_forms/cms_plugins.py | 2 +- .../contrib/email_notifications/cms_plugins.py | 11 ++++++----- .../contrib/email_notifications/models.py | 2 +- aldryn_forms/forms.py | 18 +++++++++--------- aldryn_forms/models.py | 10 +++++----- aldryn_forms/sizefield/models.py | 2 +- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/aldryn_forms/cms_plugins.py b/aldryn_forms/cms_plugins.py index 01813da6..0552a8fa 100644 --- a/aldryn_forms/cms_plugins.py +++ b/aldryn_forms/cms_plugins.py @@ -285,7 +285,7 @@ class Field(FormElement): def serialize_value(self, instance, value, is_confirmation=False): if isinstance(value, query.QuerySet): - value = u', '.join(map(text_type, value)) + value = ', '.join(map(text_type, value)) elif value is None: value = '-' return text_type(value) diff --git a/aldryn_forms/contrib/email_notifications/cms_plugins.py b/aldryn_forms/contrib/email_notifications/cms_plugins.py index 519308ca..36fce956 100644 --- a/aldryn_forms/contrib/email_notifications/cms_plugins.py +++ b/aldryn_forms/contrib/email_notifications/cms_plugins.py @@ -4,6 +4,7 @@ from django.contrib import admin from django.core.mail import get_connection +from django.utils.html import format_html from django.utils.translation import ugettext_lazy as _ from cms.plugin_pool import plugin_pool @@ -104,14 +105,14 @@ def text_variables(self, obj): for category, choices in choices_by_category: #
  • field_1
  • field_2
  • - fields_li = u''.join((u'
  • {0} | {1}
  • '.format(*var) for var in choices)) + fields_li = ''.join(('
  • {0} | {1}
  • '.format(*var) for var in choices)) if fields_li: - li_item = u'
  • {0}
  • '.format(category, fields_li) + li_item = '
  • {0}
  • '.format(category, fields_li) li_items.append(li_item) - unordered_list = u''.format(u''.join(li_items)) - help_text = u'

    {0}

    '.format(self.text_variables_help_text) - return unordered_list + u'\n' + help_text + unordered_list = ''.format(''.join(li_items)) + help_text = '

    {0}

    '.format(self.text_variables_help_text) + return format_html(unordered_list + '\n' + help_text) text_variables.allow_tags = True text_variables.short_description = _('available text variables') diff --git a/aldryn_forms/contrib/email_notifications/models.py b/aldryn_forms/contrib/email_notifications/models.py index 39718f36..2fa4d1ca 100644 --- a/aldryn_forms/contrib/email_notifications/models.py +++ b/aldryn_forms/contrib/email_notifications/models.py @@ -118,7 +118,7 @@ class Meta: def __str__(self): to_name = self.get_recipient_name() to_email = self.get_recipient_email() - return u'{0} ({1})'.format(to_name, to_email) + return '{0} ({1})'.format(to_name, to_email) def clean(self): recipient_email = self.get_recipient_email() diff --git a/aldryn_forms/forms.py b/aldryn_forms/forms.py index 08e0413b..b2da6451 100644 --- a/aldryn_forms/forms.py +++ b/aldryn_forms/forms.py @@ -219,7 +219,7 @@ def clean(self): min_value = self.cleaned_data.get('min_value') max_value = self.cleaned_data.get('max_value') if min_value and max_value and min_value > max_value: - self.append_to_errors('min_value', _(u'Min value can not be greater than max value.')) + self.append_to_errors('min_value', _('Min value can not be greater than max value.')) return self.cleaned_data @@ -228,11 +228,11 @@ class TextFieldForm(MinMaxValueForm): def __init__(self, *args, **kwargs): super(TextFieldForm, self).__init__(*args, **kwargs) - self.fields['min_value'].label = _(u'Min length') - self.fields['min_value'].help_text = _(u'Required number of characters to type.') + self.fields['min_value'].label = _('Min length') + self.fields['min_value'].help_text = _('Required number of characters to type.') - self.fields['max_value'].label = _(u'Max length') - self.fields['max_value'].help_text = _(u'Maximum number of characters to type.') + self.fields['max_value'].label = _('Max length') + self.fields['max_value'].help_text = _('Maximum number of characters to type.') self.fields['max_value'].required = False class Meta: @@ -309,11 +309,11 @@ class MultipleSelectFieldForm(MinMaxValueForm): def __init__(self, *args, **kwargs): super(MultipleSelectFieldForm, self).__init__(*args, **kwargs) - self.fields['min_value'].label = _(u'Min choices') - self.fields['min_value'].help_text = _(u'Required amount of elements to chose.') + self.fields['min_value'].label = _('Min choices') + self.fields['min_value'].help_text = _('Required amount of elements to chose.') - self.fields['max_value'].label = _(u'Max choices') - self.fields['max_value'].help_text = _(u'Maximum amount of elements to chose.') + self.fields['max_value'].label = _('Max choices') + self.fields['max_value'].help_text = _('Maximum amount of elements to chose.') class Meta: # 'required' and 'required_message' depend on min_value field validator diff --git a/aldryn_forms/models.py b/aldryn_forms/models.py index 96dd1faf..15d1ab3d 100644 --- a/aldryn_forms/models.py +++ b/aldryn_forms/models.py @@ -78,10 +78,10 @@ def field_id(self): field_label = self.label.strip() if field_label: - field_as_string = u'{}-{}'.format(field_label, self.field_type) + field_as_string = '{}-{}'.format(field_label, self.field_type) else: field_as_string = self.name - field_id = u'{}:{}'.format(field_as_string, self.field_occurrence) + field_id = '{}:{}'.format(field_as_string, self.field_occurrence) return field_id @property @@ -261,10 +261,10 @@ def get_form_fields(self): if field_plugin.name: field_name = field_plugin.name else: - field_name = u'{0}_{1}'.format(field_type, field_type_occurrence) + field_name = '{0}_{1}'.format(field_type, field_type_occurrence) if field_label: - field_id = u'{0}_{1}'.format(field_type, field_label) + field_id = '{0}_{1}'.format(field_type, field_label) else: field_id = field_name @@ -591,7 +591,7 @@ def _form_data_hook(self, data, occurrences): if field_label: field_type = data['name'].rpartition('_')[0] - field_id = u'{}_{}'.format(field_type, field_label) + field_id = '{}_{}'.format(field_type, field_label) else: field_id = data['name'] diff --git a/aldryn_forms/sizefield/models.py b/aldryn_forms/sizefield/models.py index d30d6cb1..c33496d4 100644 --- a/aldryn_forms/sizefield/models.py +++ b/aldryn_forms/sizefield/models.py @@ -8,7 +8,7 @@ class FileSizeField(models.BigIntegerField): default_error_messages = { - 'invalid': _(u'Incorrect file size format.'), + 'invalid': _('Incorrect file size format.'), } def formfield(self, **kwargs): From 8b68515e87a34e7c801a3d21df2af92cb97815bd Mon Sep 17 00:00:00 2001 From: Vladislav Yena Date: Thu, 20 Feb 2020 19:57:48 +0200 Subject: [PATCH 2/3] Fix the HTML rendering function in the Form popup --- aldryn_forms/contrib/email_notifications/cms_plugins.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aldryn_forms/contrib/email_notifications/cms_plugins.py b/aldryn_forms/contrib/email_notifications/cms_plugins.py index 36fce956..a55db4b2 100644 --- a/aldryn_forms/contrib/email_notifications/cms_plugins.py +++ b/aldryn_forms/contrib/email_notifications/cms_plugins.py @@ -4,7 +4,7 @@ from django.contrib import admin from django.core.mail import get_connection -from django.utils.html import format_html +from django.utils.html import mark_safe from django.utils.translation import ugettext_lazy as _ from cms.plugin_pool import plugin_pool @@ -112,7 +112,7 @@ def text_variables(self, obj): li_items.append(li_item) unordered_list = ''.format(''.join(li_items)) help_text = '

    {0}

    '.format(self.text_variables_help_text) - return format_html(unordered_list + '\n' + help_text) + return mark_safe(unordered_list + '\n' + help_text) text_variables.allow_tags = True text_variables.short_description = _('available text variables') From d68e9f1e24b6020cdd37d450445ba61e1e23f4b1 Mon Sep 17 00:00:00 2001 From: Vladislav Yena Date: Fri, 21 Feb 2020 17:09:08 +0200 Subject: [PATCH 3/3] Fix the 'formsubmission' export functionality --- aldryn_forms/admin/views.py | 8 +------- setup.py | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/aldryn_forms/admin/views.py b/aldryn_forms/admin/views.py index 673bca65..5206aa87 100644 --- a/aldryn_forms/admin/views.py +++ b/aldryn_forms/admin/views.py @@ -95,13 +95,7 @@ def done(self, form_list, **kwargs): content_type = self.get_content_type() - response_kwargs = {} - - if int(get_version().split('.')[1]) > 6: - response_kwargs['content_type'] = content_type - else: - # Django <= 1.6 compatibility - response_kwargs['mimetype'] = content_type + response_kwargs = {'content_type': content_type} response = HttpResponse(dataset.xls, **response_kwargs) response['Content-Disposition'] = 'attachment; filename=%s' % filename diff --git a/setup.py b/setup.py index aa10a311..cc3317d4 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ 'djangocms-text-ckeditor', 'djangocms-attributes-field>=1.0.0', 'django-tablib', - 'tablib', + 'tablib==0.13.0', 'pillow', 'django-filer', 'django-sizefield',