wcs: adapt multisort widget for django 1.11 (#21163)

This commit is contained in:
Frédéric Péters 2018-01-13 15:24:25 +01:00
parent 71db20a5e4
commit 461ce4337c
2 changed files with 29 additions and 2 deletions

View File

@ -14,6 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django
from django import forms
from django.utils.datastructures import MultiValueDict
from django.utils.safestring import mark_safe
@ -58,8 +59,12 @@ class MultiSortWidget(forms.SelectMultiple):
self.choices.insert(0, option_tuple)
# render the <select multiple>
rendered = super(MultiSortWidget, self).render(name, value,
attrs=attrs, choices=choices)
if django.VERSION < (1, 11, 0):
rendered = super(MultiSortWidget, self).render(name, value,
attrs=attrs, choices=choices)
else:
rendered = super(MultiSortWidget, self).render(name, value,
attrs=attrs)
# include it in a <div> that will be turned into an appropriate widget
# in javascript

View File

@ -20,6 +20,8 @@ from combo.apps.wcs.models import (WcsFormCell, WcsCurrentFormsCell,
from combo.utils import NothingInCacheException
from test_manager import login, admin_user
pytestmark = pytest.mark.django_db
wcsctl_present = pytest.mark.skipif('WCSCTL' not in os.environ,
@ -471,3 +473,23 @@ def test_current_drafts_cell_render_logged_in(context):
assert len(extra_context['drafts']) == 2
assert len([x for x in extra_context['drafts'] if x['site_slug'] == 'default']) == 1
assert len([x for x in extra_context['drafts'] if x['site_slug'] == 'other']) == 1
@wcsctl_present
def test_manager_forms_of_category_cell(app, admin_user):
Page.objects.all().delete()
page = Page(title='One', slug='one', template_name='standard')
page.save()
app = login(app)
resp = app.get('/manage/pages/%s/' % page.id)
resp = app.get(resp.html.find('option',
**{'data-add-url': re.compile('wcsformsofcategorycell')})['data-add-url'])
cells = page.get_cells()
assert len(cells) == 1
assert isinstance(cells[0], WcsFormsOfCategoryCell)
resp = app.get('/manage/pages/%s/' % page.id)
assert ('data-cell-reference="%s"' % cells[0].get_reference()) in resp.body
resp.forms[0]['c%s-ordering' % cells[0].get_reference()].value = 'manual'
resp = resp.forms[0].submit()
assert resp.status_int == 302