from django import forms

from ideascube.widgets import LangSelect

from .models import Content


class ContentForm(forms.ModelForm):

    class Meta:
        model = Content
        widgets = {
            # We need a normalized date string for JS datepicker, so we take
            # control over the format to bypass L10N.
            "published_at": forms.DateInput(format='%Y-%m-%d'),
            "lang": LangSelect,
        }
        fields = "__all__"

    def save(self, commit=True):
        content = super().save()
        content.save()  # Index m2m.
        return content

from django import forms

from ideascube.widgets import LangSelect

from .models import Content


class ContentForm(forms.ModelForm):
    use_required_attribute = False

    class Meta:
        model = Content
        widgets = {
            # We need a normalized date string for JS datepicker, so we take
            # control over the format to bypass L10N.
            "published_at": forms.DateInput(format='%Y-%m-%d'),
            "lang": LangSelect,
        }
        fields = "__all__"

    def save(self, commit=True):
        content = super().save()
        content.save()  # Index m2m.
        return content

Fix the blog content form
Fix the blog content form

The form plays a trick on the 'text' field: it hides it, and creates a
nicer-looking 'content' field. When submitting the form, the content of
the 'content' field is injected into the 'text' field.

This works great, until Django 1.10.

With Django 1.10, the browser refuses to submit the form, saying the
'text' field is empty and required.

This is due to this hidden gem from the Django 1.10 release notes:

> * Required form fields now have the required HTML attribute. Set the
>   Form.use_required_attribute attribute to False to disable it. You
>   could also add the novalidate attribute to <form> if you don’t want
>   browser validation.

https://docs.djangoproject.com/en/1.10/releases/1.10/#miscellaneous

This commit fixes the blog content form, which is the only one I found
problematic so far.

Hopefully it is the only one that is actually impacted. :-/
