Update rendering of the readonly multiselect widget to conform to Django's updated field class interface.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -144,6 +144,7 @@
|
||||
that document type is removed from the workflow.
|
||||
- Make error messages persistent and increase the timeout of warning to 10 seconds.
|
||||
- Improve rendering of the details form.
|
||||
- Update rendering of the readonly multiselect widget to conform to Django's updated field class interface.
|
||||
|
||||
2.7.3 (2017-09-11)
|
||||
==================
|
||||
|
||||
@@ -436,6 +436,8 @@ Other changes worth mentioning
|
||||
upload event as trigger. Thanks to Sema @Miggaten for the find and
|
||||
the solution.
|
||||
- Make error messages persistent and increase the timeout of warning to 10 seconds.
|
||||
- Improve rendering of the details form.
|
||||
- Update rendering of the readonly multiselect widget to conform to Django's updated field class interface.
|
||||
|
||||
|
||||
Removals
|
||||
|
||||
@@ -11,6 +11,6 @@ def get_choice_value(field):
|
||||
try:
|
||||
return dict(field.field.choices)[field.value()]
|
||||
except TypeError:
|
||||
return ', '.join([entry for id, entry in field.field.choices])
|
||||
return ', '.join([subwidget.data['label'] for subwidget in field.subwidgets if subwidget.data['selected']])
|
||||
except KeyError:
|
||||
return _('None')
|
||||
|
||||
@@ -12,9 +12,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from .classes import Package
|
||||
from .models import UserLocaleProfile
|
||||
from .utils import return_attrib
|
||||
from .widgets import (
|
||||
DetailSelectMultiple, DisableableSelectWidget, PlainWidget
|
||||
)
|
||||
from .widgets import DisableableSelectWidget, PlainWidget
|
||||
|
||||
|
||||
class ChoiceForm(forms.Form):
|
||||
@@ -62,22 +60,6 @@ class DetailForm(forms.ModelForm):
|
||||
widget=extra_field.get('widget', PlainWidget)
|
||||
)
|
||||
|
||||
for field_name, field in self.fields.items():
|
||||
if isinstance(field.widget, forms.widgets.SelectMultiple):
|
||||
self.fields[field_name].widget = DetailSelectMultiple(
|
||||
choices=field.widget.choices,
|
||||
attrs=field.widget.attrs,
|
||||
queryset=getattr(field, 'queryset', None),
|
||||
)
|
||||
self.fields[field_name].help_text = ''
|
||||
elif isinstance(field.widget, forms.widgets.Select):
|
||||
self.fields[field_name].widget = DetailSelectMultiple(
|
||||
choices=field.widget.choices,
|
||||
attrs=field.widget.attrs,
|
||||
queryset=getattr(field, 'queryset', None),
|
||||
)
|
||||
self.fields[field_name].help_text = ''
|
||||
|
||||
for field_name, field in self.fields.items():
|
||||
self.fields[field_name].widget.attrs.update(
|
||||
{'readonly': 'readonly'}
|
||||
|
||||
@@ -7,47 +7,6 @@ from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
class DetailSelectMultiple(forms.widgets.SelectMultiple):
|
||||
def __init__(self, queryset=None, *args, **kwargs):
|
||||
self.queryset = queryset
|
||||
super(DetailSelectMultiple, self).__init__(*args, **kwargs)
|
||||
|
||||
def render(self, name, value, attrs=None, choices=(), *args, **kwargs):
|
||||
if value is None:
|
||||
value = ''
|
||||
final_attrs = self.build_attrs(attrs, name=name)
|
||||
css_class = final_attrs.get('class', 'list')
|
||||
output = '<ul class="%s">' % css_class
|
||||
options = None
|
||||
if value:
|
||||
if getattr(value, '__iter__', None):
|
||||
options = [(index, string) for index, string in
|
||||
self.choices if index in value]
|
||||
else:
|
||||
options = [(index, string) for index, string in
|
||||
self.choices if index == value]
|
||||
else:
|
||||
if self.choices:
|
||||
if self.choices[0] != ('', '---------') and value != []:
|
||||
options = [(index, string) for index, string in
|
||||
self.choices]
|
||||
|
||||
if options:
|
||||
for index, string in options:
|
||||
if self.queryset:
|
||||
try:
|
||||
output += '<li><a href="%s">%s</a></li>' % (
|
||||
self.queryset.get(pk=index).get_absolute_url(),
|
||||
string)
|
||||
except AttributeError:
|
||||
output += '<li>%s</li>' % (string)
|
||||
else:
|
||||
output += '<li>%s</li>' % string
|
||||
else:
|
||||
output += '<li>%s</li>' % _('None')
|
||||
return mark_safe(output + '</ul>\n')
|
||||
|
||||
|
||||
class DisableableSelectWidget(forms.SelectMultiple):
|
||||
allow_multiple_selected = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user