예제 #1
0
    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
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
 class NewsletterAdmin(BaseNewsletterAdmin):
     formfield_overrides = {
         models.TextField: {
             'widget':
             TextEditorWidget(configuration='NEWSLETTER_CKEDITOR_SETTINGS')
         }
     }
예제 #5
0
    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
예제 #6
0
 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)
예제 #7
0
 class Meta:
     model = Article
     fields = '__all__'
     widgets = {
         'teaser':
         TextEditorWidget(),
         'tags':
         TagAutocompleteWidget(
             autocomplete_url=reverse_lazy('api:articletag-autocomplete'))
     }
예제 #8
0
 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)
예제 #9
0
 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)
예제 #10
0
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 = []
예제 #11
0
 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)
예제 #12
0
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)
예제 #13
0
    class Meta:
        """
        Form meta attributes
        """

        model = Section
        widgets = {
            "title":
            TextEditorWidget(configuration=CKEDITOR_CONFIGURATION_NAME)
        }
        fields = {
            "title",
            "template",
        }
예제 #14
0
    class Meta:
        """
        Form meta attributes
        """

        model = LargeBanner
        widgets = {
            "content": TextEditorWidget(configuration=CKEDITOR_CONFIGURATION_NAME)
        }
        fields = [
            "title",
            "background_image",
            "logo",
            "logo_alt_text",
            "template",
            "content",
        ]
예제 #15
0
파일: forms.py 프로젝트: EliuFlorez/richie
    class Meta:
        """
        Form meta attributes
        """

        model = LargeBanner
        widgets = {
            "content":
            TextEditorWidget(configuration="CKEDITOR_BASIC_SETTINGS")
        }
        fields = [
            "title",
            "background_image",
            "logo",
            "logo_alt_text",
            "template",
            "content",
        ]
예제 #16
0
 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)
예제 #17
0
    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()
예제 #18
0
 def _get_widget(self):
     plugins = plugin_pool.get_text_enabled_plugins(placeholder=None,
                                                    page=None)
     return TextEditorWidget(installed_plugins=plugins)
예제 #19
0
 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
예제 #20
0
 class Meta:
     model = Article
     fields = '__all__'
     widgets = {'teaser': TextEditorWidget()}
예제 #21
0
 class Meta:
     model = Testimony
     widgets = {
       'story': TextEditorWidget(),
     }
     fields = '__all__'
예제 #22
0
 def __init__(self, *args, **kwargs):
     super(ReleaseForm, self).__init__(*args, **kwargs)
     if 'release_notes' in self.fields:
         self.fields['release_notes'].widget = TextEditorWidget()
예제 #23
0
 def __init__(self, *args, **kwargs):
     super(TranslationForm, self).__init__(*args, **kwargs)
     if 'translated_notes' in self.fields:
         self.fields['translated_notes'].widget = TextEditorWidget()
예제 #24
0
 def __init__(self, *args, **kwargs):
     super(ReleasePlatformForm, self).__init__(*args, **kwargs)
     if 'info' in self.fields:
         self.fields['info'].widget = TextEditorWidget()