def __init__(self, language, *args, **kwargs): self.language = language if kwargs['instance'].translation_of: self.translation_of = kwargs['instance'].translation_of else: self.translation_of = kwargs['instance'] kwargs['instance'], _ = News.objects.get_or_create( language=language, translation_of=self.translation_of, defaults={ 'title': self.translation_of.title, 'link': self.translation_of.link, 'excerpt': self.translation_of.excerpt, 'content': self.translation_of.content, }) super(TranslationForm, self).__init__(*args, **kwargs) # Set the help texts to the English version for key in ('excerpt', 'content'): attrs = {'id': 't_%s' % key} content = getattr(self.translation_of, key) editor = TextEditorWidget(configuration='CKEDITOR_READONLY') text = editor.render(attrs['id'], content, attrs) self.fields[key].help_text = self.template % text
def __init__(self, *args, **kwargs): super(NewsAdminForm, self).__init__(*args, **kwargs) if 'translation_of' in self.fields: self.fields['translation_of'].queryset = self.english kw = dict(configuration='CKEDITOR_NEWS') if 'excerpt' in self.fields: self.fields['excerpt'].widget = TextEditorWidget(**kw) if 'content' in self.fields: self.fields['content'].widget = TextEditorWidget(**kw)
def get_form(self, request, obj=None, **kwargs): if obj: caption = self.html_parser.unescape(obj.glossary.get( 'caption', '')) obj.glossary.update(caption=caption) parent_obj = self.get_parent_instance(request) if not (parent_obj and issubclass(parent_obj.plugin_class, BootstrapPluginBase)): raise ImproperlyConfigured( "A CarouselSlidePlugin requires a valid parent") # define glossary fields on the fly, because the TextEditorWidget requires the plugin_pk text_editor_widget = TextEditorWidget( installed_plugins=[TextLinkPlugin], pk=parent_obj.pk, placeholder=parent_obj.placeholder, plugin_language=parent_obj.language) caption = GlossaryField( text_editor_widget, label=_("Slide Caption"), name='caption', help_text=_("Caption text to be laid over the backgroud image.")) kwargs['glossary_fields'] = (caption, ) return super(CarouselSlidePlugin, self).get_form(request, obj, **kwargs)
class NewsletterAdmin(BaseNewsletterAdmin): formfield_overrides = { models.TextField: { 'widget': TextEditorWidget(configuration='NEWSLETTER_CKEDITOR_SETTINGS') } }
def get_form(self, request, obj=None, change=False, **kwargs): """ Add an HTML max length validator and/or a CKEditor configuration based on what is configured in settings for the current placeholder. """ form = super().get_form(request, obj=obj, change=change, **kwargs) placeholder_id = request.GET.get("placeholder_id") if not placeholder_id and not obj: return form if placeholder_id: placeholder = Placeholder.objects.only("slot").get( id=placeholder_id) else: placeholder = obj.placeholder for configuration in SIMPLETEXT_CONFIGURATION: if ("placeholders" not in configuration or placeholder.slot in configuration["placeholders"]): break else: configuration = {} body_field = form.base_fields["body"] if configuration.get("max_length"): body_field.validators.append( HTMLMaxLengthValidator(configuration["max_length"])) if configuration.get("ckeditor"): body_field.widget = TextEditorWidget( configuration=configuration["ckeditor"]) return form
def get_editor_widget(self, request, plugins, pk, placeholder): """ Returns the Django form Widget to be used for the text area """ return TextEditorWidget(installed_plugins=plugins, pk=pk, placeholder=placeholder)
class Meta: model = Article fields = '__all__' widgets = { 'teaser': TextEditorWidget(), 'tags': TagAutocompleteWidget( autocomplete_url=reverse_lazy('api:articletag-autocomplete')) }
def get_form(self, request, obj=None, **kwargs): if obj: html_content = self.html_parser.unescape(obj.glossary.get('html_content', '')) obj.glossary.update(html_content=html_content) text_editor_widget = TextEditorWidget(installed_plugins=[TextLinkPlugin], pk=obj.pk, placeholder=obj.placeholder, plugin_language=obj.language) kwargs['glossary_fields'] = ( PartialFormField('html_content', text_editor_widget, label=_("HTML content")), ) return super(AcceptConditionFormPlugin, self).get_form(request, obj, **kwargs)
def get_form(self, request, obj=None, **kwargs): if obj: notes = self.html_parser.unescape(obj.glossary.get('notes', '')) obj.glossary.update(notes=notes) # define glossary fields on the fly, because the TextEditorWidget requires the plugin_pk text_editor_widget = TextEditorWidget(installed_plugins=[], pk=self.parent.pk, placeholder=self.parent.placeholder, plugin_language=self.parent.language) kwargs['glossary_fields'] = ( PartialFormField('notes', text_editor_widget, label=_("Speaker Notes")), ) return super(RevealSpeakerNotePlugin, self).get_form(request, obj, **kwargs)
class ArticleAdminModelForm(forms.ModelForm): if 'djangocms_text_ckeditor' in settings.INSTALLED_APPS: from djangocms_text_ckeditor.widgets import TextEditorWidget body = forms.CharField(widget=TextEditorWidget()) elif 'tinymce' in settings.INSTALLED_APPS: from tinymce.widgets import TinyMCE body = forms.CharField(widget=TinyMCE()) teaser = forms.CharField(required=False, widget=SmallTextField()) class Meta: model = get_model('newscenter', 'article') exclude = []
def get_editor_widget(self, request, plugins): """ Returns the Django form Widget to be used for the text area """ if USE_TINYMCE and "tinymce" in settings.INSTALLED_APPS: from cms.plugins.text.widgets.tinymce_widget import TinyMCEEditor return TinyMCEEditor(installed_plugins=plugins) elif "djangocms_text_ckeditor" in settings.INSTALLED_APPS: from djangocms_text_ckeditor.widgets import TextEditorWidget return TextEditorWidget(installed_plugins=plugins) else: from cms.plugins.text.widgets.wymeditor_widget import WYMEditor return WYMEditor(installed_plugins=plugins)
class CarouselSlidePlugin(BootstrapPluginBase): name = _("Slide") model_mixins = (ImagePropertyMixin,) form = ImageForm default_css_class = 'img-responsive' parent_classes = ['CarouselPlugin'] raw_id_fields = ('image_file',) fields = ('image_file', 'glossary',) render_template = os.path.join(CASCADE_TEMPLATE_DIR, 'carousel-slide.html') glossary_fields = ( PartialFormField('caption', TextEditorWidget(), label=_("Slide Caption"), help_text=_("Caption text to be laid over the backgroud image."), ), ) def get_form(self, request, obj=None, **kwargs): caption = HTMLParser().unescape(obj.glossary.get('caption', '')) obj.glossary.update(caption=caption) return super(CarouselSlidePlugin, self).get_form(request, obj, **kwargs) def render(self, context, instance, placeholder): # image shall be rendered in a responsive context using the ``<picture>`` element elements = utils.get_picture_elements(context, instance) caption = HTMLParser().unescape(instance.glossary.get('caption', '')) context.update({ 'is_responsive': True, 'instance': instance, 'caption': caption, 'placeholder': placeholder, 'elements': elements, }) return super(CarouselSlidePlugin, self).render(context, instance, placeholder) @classmethod def sanitize_model(cls, obj): sanitized = super(CarouselSlidePlugin, cls).sanitize_model(obj) complete_glossary = obj.get_complete_glossary() obj.glossary.update({'resize-options': complete_glossary.get('resize-options', [])}) return sanitized @classmethod def get_identifier(cls, obj): identifier = super(CarouselSlidePlugin, cls).get_identifier(obj) try: content = force_text(obj.image) except AttributeError: content = _("No Slide") return format_html('{0}{1}', identifier, content)
class Meta: """ Form meta attributes """ model = Section widgets = { "title": TextEditorWidget(configuration=CKEDITOR_CONFIGURATION_NAME) } fields = { "title", "template", }
class Meta: """ Form meta attributes """ model = LargeBanner widgets = { "content": TextEditorWidget(configuration=CKEDITOR_CONFIGURATION_NAME) } fields = [ "title", "background_image", "logo", "logo_alt_text", "template", "content", ]
class Meta: """ Form meta attributes """ model = LargeBanner widgets = { "content": TextEditorWidget(configuration="CKEDITOR_BASIC_SETTINGS") } fields = [ "title", "background_image", "logo", "logo_alt_text", "template", "content", ]
def get_form(self, request, obj=None, **kwargs): if obj: caption = self.html_parser.unescape(obj.glossary.get( 'caption', '')) obj.glossary.update(caption=caption) # define glossary fields on the fly, because the TextEditorWidget requires the plugin_pk text_editor_widget = TextEditorWidget( installed_plugins=[TextLinkPlugin], pk=self.parent.pk, placeholder=self.parent.placeholder, plugin_language=self.parent.language) kwargs['glossary_fields'] = (PartialFormField( 'caption', text_editor_widget, label=_("Slide Caption"), help_text=_("Caption text to be laid over the backgroud image."), ), ) return super(CarouselSlidePlugin, self).get_form(request, obj, **kwargs)
def __init__(self, *args, **kw): super(TeamForm, self).__init__(*args, **kw) for field in ('desc', 'charter', 'side_bar'): if field in self.fields: self.fields[field].widget = TextEditorWidget()
def _get_widget(self): plugins = plugin_pool.get_text_enabled_plugins(placeholder=None, page=None) return TextEditorWidget(installed_plugins=plugins)
def __init__(self, *args, **kwargs): super(News3Form, self).__init__(*args, **kwargs) plugins = plugin_pool.get_text_enabled_plugins(placeholder=None, page=None) widget = TextEditorWidget(installed_plugins=plugins) self.fields['content'].widget = widget
class Meta: model = Article fields = '__all__' widgets = {'teaser': TextEditorWidget()}
class Meta: model = Testimony widgets = { 'story': TextEditorWidget(), } fields = '__all__'
def __init__(self, *args, **kwargs): super(ReleaseForm, self).__init__(*args, **kwargs) if 'release_notes' in self.fields: self.fields['release_notes'].widget = TextEditorWidget()
def __init__(self, *args, **kwargs): super(TranslationForm, self).__init__(*args, **kwargs) if 'translated_notes' in self.fields: self.fields['translated_notes'].widget = TextEditorWidget()
def __init__(self, *args, **kwargs): super(ReleasePlatformForm, self).__init__(*args, **kwargs) if 'info' in self.fields: self.fields['info'].widget = TextEditorWidget()