Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/6.4.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaitlyn Crawford committed Feb 7, 2018
2 parents 62dc41d + ee4a1e8 commit 85639ac
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 24 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
CHANGE LOG
==========
6.4.6
-----
- Upgrade wagtail-personalisation-molo to 0.10.6

6.4.5
-----
- Bug Fix: stop using private API self.build_attrs() on form fields

6.4.3
-----
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.4.4
6.4.6
2 changes: 1 addition & 1 deletion local_test_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .base import * # noqa
from .base import * # noqa: F403


INSTALLED_APPS += (
Expand Down
31 changes: 12 additions & 19 deletions molo/surveys/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.core.exceptions import ValidationError
from django.forms.utils import ErrorList, flatatt
from django.utils.encoding import force_text
from django.forms.utils import ErrorList
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
from django.utils import six
Expand All @@ -22,28 +21,22 @@ class Media:
js = ('js/widgets/character_count.js',)

def render(self, name, value, attrs=None):
if value is None:
value = ''
final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
max_length = final_attrs['maxlength']
max_length = self.attrs['maxlength']
maximum_text = _('Maximum: {max_length}').format(max_length=max_length)
if value != '':
# Only add the 'value' attribute if a value is non-empty.
final_attrs['value'] = force_text(self._format_value(value))
return format_html('<input {} /><span>{}</span>',
flatatt(final_attrs),
maximum_text)
return format_html(
u'{}<span>{}</span>',
super(CharacterCountWidget, self).render(name, value, attrs),
maximum_text,
)


class MultiLineWidget(forms.Textarea):
def render(self, name, value, attrs=None):
if value is None:
value = ''
final_attrs = self.build_attrs(attrs, name=name)
return format_html('<textarea{}>\r\n{}</textarea><span>{}</span>',
flatatt(final_attrs),
force_text(value),
_('No limit'))
return format_html(
u'{}<span>{}</span>',
super(MultiLineWidget, self).render(name, value, attrs),
_('No limit'),
)


class SurveysFormBuilder(FormBuilder):
Expand Down
25 changes: 25 additions & 0 deletions molo/surveys/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import unicode_literals

from django.test import TestCase

from molo.surveys.forms import CharacterCountWidget, MultiLineWidget


class TestCharacterCountWidget(TestCase):
def test_character_count_widget_render(self):
widget = CharacterCountWidget()
widget.attrs['maxlength'] = 10
html = widget.render('field-name', 'field-value')
self.assertTrue(html.endswith('<span>Maximum: 10</span>'))

def test_character_count_widget_no_maxlength_raises_error(self):
widget = CharacterCountWidget()
with self.assertRaises(KeyError):
widget.render('field-name', 'field-value')


class TestMultiLineWidget(TestCase):
def test_multi_line_widget_render(self):
widget = MultiLineWidget()
html = widget.render('field-name', 'field-value', {'my-attr': 1})
self.assertTrue(html.endswith('<span>No limit</span>'))
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
molo.core<7.0.0,>=6.3.1
molo.core<7.0.0,>=6.5.0
celery<4.0
django-celery
wagtailsurveys==0.1.1
wagtail-personalisation-molo==0.10.5
django==1.10.8
wagtail-personalisation-molo==0.10.6
psycopg2
html5lib==0.9999999
six==1.11.0
Expand Down

0 comments on commit 85639ac

Please sign in to comment.