Browse Source

adequa widget ao django 1.11

pull/2457/head
Leandro Roberto 6 years ago
parent
commit
d9f93230b2
  1. 43
      sapl/materia/forms.py

43
sapl/materia/forms.py

@ -1298,41 +1298,14 @@ class TipoProposicaoForm(ModelForm):
class TipoProposicaoSelect(Select): class TipoProposicaoSelect(Select):
def render_tipo_option(self, selected_choices, option_value, option_label, def create_option(self, name, value, label, selected, index, subindex=None, attrs=None):
data_has_perfil=False): option = super().create_option(name, value, label, selected,
if option_value is None: index, subindex=subindex, attrs=attrs)
option_value = '' if value:
option_value = force_text(option_value) tipo = TipoProposicao.objects.get(id=value)
if option_value in selected_choices: option['attrs']['data-has-perfil'] = str(tipo.perfis.exists())
selected_html = mark_safe(' selected="selected"')
if not self.allow_multiple_selected: return option
# Only allow for a single selection.
selected_choices.remove(option_value)
else:
selected_html = ''
return format_html(
'<option value="{}"{} data-has-perfil={}>{}</option>',
option_value,
selected_html,
str(data_has_perfil),
force_text(option_label))
def render_options(self, selected_choices):
# Normalize to strings.
selected_choices = set(force_text(v) for v in selected_choices)
output = []
output.append(
self.render_tipo_option(
selected_choices, '', self.choices.field.empty_label))
for tipo in self.choices.queryset.all():
output.append(
self.render_tipo_option(
selected_choices,
str(tipo.pk),
str(tipo),
data_has_perfil=tipo.perfis.exists()))
return '\n'.join(output)
class ProposicaoForm(forms.ModelForm): class ProposicaoForm(forms.ModelForm):

Loading…
Cancel
Save