django-summernote
django-summernote copied to clipboard
Using a SummernoteTextField for sanitization, turns a SummernoteInPlaceWidget into a SummernoteWidget.
Hi, when trying to sanitize input, on a SummerNoteInPlaceWidget introduced on a form, if I use a SummernoteTextField in my model, the form displayed starts requiring an iframe. This is a bug, I think.
I am guessing this is due to the following code in fields.py
class SummernoteTextFormField(fields.CharField):
def __init__(self, *args, **kwargs):
kwargs.update({'widget': SummernoteWidget()})
super().__init__(*args, **kwargs)
Hi, my suggestion is to cange to
`class SummernoteTextFormField(fields.CharField): # You can define widget in form with SummernoteTextFormField(widget=OtherWidget). def to_python(self, value): value = super().to_python(value) return bleach.clean(value, tags=ALLOWED_TAGS, attributes=ATTRIBUTES, styles=STYLES)
class SummernoteTextField(models.TextField): # Default widgetas For this field type. # You can define any other widget in model with SummernoteTextField(widget=OtherWidget). widget = CustomWidthSummernoteInplaceWidget()
def __init__(self, widget=None, *args, **kwargs):
if widget:
self.widget = widget
super().__init__(*args, **kwargs)
def formfield(self, **kwargs):
kwargs.update({'form_class': SummernoteTextFormField, 'widget': self.widget})
return super().formfield(**kwargs)
def to_python(self, value):
value = super().to_python(value)
return bleach.clean(value, tags=ALLOWED_TAGS, attributes=ATTRIBUTES, styles=STYLES)
`