...
 
Commits (3)
......@@ -455,9 +455,11 @@ class CandidateMediaInline(TabularInline):
formset = CandidateMediaInlineFormset
model = CandidateMedia
class CandidateAttributeValueAdminInline(TabularInline):
model = CandidateAttributeValue
extra = 5
raw_id_fields = ['value']
class CandidateSuperAdmin(admin.ModelAdmin):
......
......@@ -314,7 +314,7 @@ class ApplicationBooleanElementField(ApplicationElementFieldBase):
preview_widget=ApplicationBooleanElementPreviewWidget(), admin_widget=ApplicationBooleanElementAdminWidget()
):
super(ApplicationBooleanElementField,self).__init__(
competition, name, label, required, help_text, widget, preview_widget, admin_widget, admin_widget
competition, name, label, required, help_text, widget, preview_widget, admin_widget, preview_widget
)
......
......@@ -1366,8 +1366,14 @@ class Candidate(models.Model):
application_element_kinds = (
'ApplicationTextElementField', 'ApplicationHtmlElementField',
'ApplicationBooleanElementField'
)
if field_kind.name in application_element_kinds:
if field_kind.name == 'ApplicationBooleanElementField':
if isinstance(value, str):
# checkbox : on si coché
value = (value.lower() in ('on', 'true', ))
value = 'True' if value else 'False'
try:
elt = ApplicationElement.objects.get(candidate=self, key=key)
elt.value = value
......
......@@ -155,9 +155,18 @@ class ApplicationBooleanElementPreviewWidget(forms.CheckboxInput):
attrs.update(default_attrs)
super(ApplicationBooleanElementPreviewWidget,self).__init__(attrs, *args, **kwargs)
def render(self, name, value, attrs=None, **kwargs):
if isinstance(value, str):
value = value != 'False'
return super().render(name, value, attrs, **kwargs)
class ApplicationBooleanElementAdminWidget(forms.CheckboxInput):
template_name = "floppyforms/checkbox_disabled.html"
class ApplicationBooleanElementAdminWidget(ApplicationBooleanElementWidget):
def render(self, name, value, attrs=None, **kwargs):
if isinstance(value, str):
value = value != 'False'
return super().render(name, value, attrs, **kwargs)
class ApplicationHtmlElementWidget(forms.Textarea):
......