예제 #1
0
파일: forms.py 프로젝트: tomkins/wagtail
class ImageInsertionForm(forms.Form):
    """
    Form for selecting parameters of the image (e.g. format) prior to insertion
    into a rich text area
    """

    format = forms.ChoiceField(
        label=_("Format"),
        choices=[(format.name, format.label)
                 for format in get_image_formats()],
        widget=forms.RadioSelect,
    )
    image_is_decorative = forms.BooleanField(required=False,
                                             label=_("Image is decorative"))
    alt_text = forms.CharField(required=False, label=_("Alt text"))

    def clean_alt_text(self):
        alt_text = self.cleaned_data["alt_text"]
        image_is_decorative = self.cleaned_data["image_is_decorative"]

        # Empty the alt text value if the image is set to be decorative
        if image_is_decorative:
            return ""
        else:
            # Alt text is required if image is not decorative.
            if not alt_text:
                msg = _(
                    "Please add some alt text for your image or mark it as decorative"
                )
                self.add_error("alt_text", msg)
        return alt_text
예제 #2
0
파일: forms.py 프로젝트: petschna/linux-day
class ImageInsertionForm(forms.Form):
    """
    Form for selecting parameters of the image (e.g. format) prior to insertion
    into a rich text area
    """
    format = forms.ChoiceField(choices=[(format.name, format.label)
                                        for format in get_image_formats()],
                               widget=forms.RadioSelect)
    alt_text = forms.CharField()