from django import forms
from django.db import models


class RichTextFormField(forms.fields.CharField):
    def __init__(self, *args, **kwargs):
        super(RichTextFormField, self).__init__(*args, **kwargs)
        css_class = self.widget.attrs.get('class', '')
        css_class += ' item-richtext'
        self.widget.attrs['class'] = css_class

    def clean(self, value):
        # TODO add cleansing here?
        return super(RichTextFormField, self).clean(value)


class RichTextField(models.TextField):
    """
    Drop-in replacement for Django's ``models.TextField`` which allows editing
    rich text instead of plain text in the item editor.
    """
    formfield = RichTextFormField


try:
    from south.modelsinspector import add_introspection_rules

    RichTextField_introspection_rule = ( (RichTextField,), [], {}, )

    add_introspection_rules(rules=[RichTextField_introspection_rule],
        patterns=["^feincms\.contrib\.richtext"])
except ImportError:
    pass

from django import forms
from django.db import models


class RichTextFormField(forms.fields.CharField):
    def __init__(self, *args, **kwargs):
        super(RichTextFormField, self).__init__(*args, **kwargs)
        css_class = self.widget.attrs.get('class', '')
        css_class += ' item-richtext'
        self.widget.attrs['class'] = css_class

    def clean(self, value):
        # TODO add cleansing here?
        return super(RichTextFormField, self).clean(value)


class RichTextField(models.TextField):
    """
    Drop-in replacement for Django's ``models.TextField`` which allows editing
    rich text instead of plain text in the item editor.
    """
    def formfield(self, form_class=RichTextFormField, **kwargs):
        return super(RichTextField, self).formfield(form_class=form_class, **kwargs)


try:
    from south.modelsinspector import add_introspection_rules

    RichTextField_introspection_rule = ( (RichTextField,), [], {}, )

    add_introspection_rules(rules=[RichTextField_introspection_rule],
        patterns=["^feincms\.contrib\.richtext"])
except ImportError:
    pass

Fix RichTextField form field generation.
Fix RichTextField form field generation.

All standard properties that would affect formfield were being ignored
(such as blank=True).
