def get_widget(self, page, language, fallback=Textarea):
        if 'ckeditor' not in settings.INSTALLED_APPS:
            return fallback

        with_stmt = self.widget # name of the widget as called in template like...
        # {% ckeditor_placeholder "welcome" with text_wysiwym_widget:default%}
        splitted = with_stmt.split(":")

        if len(splitted) == 1:
            ck = CKEditorWidget(config_name='default')
        elif len(splitted) > 1:
            ck = CKEditorWidget(config_name=splitted[1])

        if not ck.config.get('language'):
            ck.config['language'] = translation.get_language()

        return ck
Beispiel #2
0
class IntroAdminForm(forms.ModelForm):
    content = forms.CharField(widget=CKEditorWidget(config_name='basic'))

    class Meta:
        model = Intro
        exclude = []
Beispiel #3
0
 def __init__(self, *args, **kwargs):
     super(RequirementForm, self).__init__(*args, **kwargs)
     self.fields["description"].widget = CKEditorWidget()
     self.fields["other_comments"].widget = CKEditorWidget()
Beispiel #4
0
class announcementAdminForm(forms.ModelForm):
    body = forms.CharField(widget=CKEditorWidget(config_name='admin_ckeditor'))

    class Meta:
        model = announcement
        fields = '__all__'
Beispiel #5
0
class FlatpageAdminForm(FlatpageForm):
    content = forms.CharField(widget=CKEditorWidget())

    class Meta:
        model = FlatPage
        fields = '__all__'
Beispiel #6
0
class PostForm(forms.ModelForm):
    conteudo = forms.CharField(widget=CKEditorWidget())

    class Meta:
        model = Post
        fields = ('titulo', 'conteudo', 'categoria', 'imagem', 'status')
Beispiel #7
0
class ComposeFromCompanyForm(forms.ModelForm):
    to_companies = forms.ModelMultipleChoiceField(
        label="Send to:",
        help_text="Contacts from these companies",
        required=True,
        queryset=Company.objects.all(),
        widget=forms.SelectMultiple(attrs={
            "class": "col-sm-10",
            "placeholder": "Companies list",
        }),
    )

    primary_selection = MultiSelectFormField(
        label="Which are:",
        help_text="Primary status (ignored if unset)",
        required=False,
        choices=(Email.PRIMARY_CHOICES),
        widget=forms.SelectMultiple(attrs={
            "class": "custom-select col-md-6 col-lg-4",
            "placeholder": ""
        }),
    )

    contacted_selection = MultiSelectFormField(
        label="With contacts who have been:",
        help_text="Contacted this many times (ignored if unset)",
        required=False,
        choices=(Email.CONTACTED_CHOICES),
        widget=forms.SelectMultiple(attrs={
            "class": "custom-select col-md-6 col-lg-4",
            "placeholder": ""
        }),
    )

    exclude_contacted_companies = forms.BooleanField(required=False)
    exclude_responded_companies = forms.BooleanField(required=False)

    subject = forms.CharField(
        required=True,
        widget=forms.TextInput(attrs={
            "class": "form-control",
            "placeholder": "Subject",
        }),
    )

    body = forms.CharField(
        required=True,
        widget=CKEditorWidget(config_name='default',
                              attrs={"placeholder": "Body"}),
    )

    class Meta:
        model = Email
        fields = (
            'internal_title',
            'to_companies',
            'primary_selection',
            'contacted_selection',
            'exclude_contacted_companies',
            'exclude_responded_companies',
            'subject',
            'body',
            'attach_packet',
        )
Beispiel #8
0
from ckeditor.widgets import CKEditorWidget
from django.contrib import admin
from django.contrib.flatpages.admin import FlatpageForm
from django.contrib.flatpages.models import FlatPage
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.contrib.sites.shortcuts import get_current_site
from modeltranslation.admin import TranslationAdmin
from pod.main.models import LinkFooter

SITE_ID = getattr(settings, 'SITE_ID', 1)
content_widget = {}
for key, value in settings.LANGUAGES:
    content_widget['content_%s' % key.replace('-', '_')] = CKEditorWidget(
        config_name='complete')


class PageForm(FlatpageForm):
    class Meta:
        model = FlatPage
        fields = '__all__'
        widgets = content_widget


# CustomFlatPage admin panel


class CustomFlatPageAdmin(TranslationAdmin):
    list_display = ('title', 'url')
    form = PageForm
Beispiel #9
0
 def formfield_for_dbfield(self, db_field, **kwargs):
     if db_field.name in ['header', 'content']:
         kwargs['widget'] = CKEditorWidget()
     return super(ArticleArchiveAdmin, self).formfield_for_dbfield(db_field, **kwargs)
Beispiel #10
0
    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name in ['header']:
            kwargs['widget'] = CKEditorWidget()

        return super(SectionAdmin, self).formfield_for_dbfield(db_field, **kwargs)
Beispiel #11
0
class FlatPageAdminForm(forms.ModelForm):
    content = forms.CharField(widget=CKEditorWidget())

    class Meta:
        model = FlatPage
Beispiel #12
0
class ContactForm(forms.ModelForm):
    first_name = forms.CharField(
        max_length=50,
        required=True,
        widget=forms.TextInput(
            attrs={
                "class": "form-control col-md-6 col-lg-4",
                "placeholder": "First Name",
            }
        ),
    )
    last_name = forms.CharField(
        max_length=50,
        required=True,
        widget=forms.TextInput(
            attrs={
                "class": "form-control col-md-6 col-lg-4",
                "placeholder": "Last Name",
            }
        ),
    )
    company = forms.ModelChoiceField(
        required=True,
        queryset=Company.objects.all(),
        widget=forms.Select(
            attrs={"class": "custom-select col-md-6 col-lg-4", "placeholder": "Company"}
        ),
    )
    position = forms.CharField(
        max_length=100,
        required=False,
        widget=forms.TextInput(
            attrs={"class": "form-control col-md-6 col-lg-4", "placeholder": "Position"}
        ),
    )
    email = forms.EmailField(
        max_length=50,
        required=False,
        widget=forms.EmailInput(
            attrs={
                "class": "form-control col-md-6 col-lg-4",
                "placeholder": "*****@*****.**",
            }
        ),
    )
    phone_number = forms.CharField(
        max_length=50,
        required=False,
        widget=forms.TextInput(
            attrs={
                "class": "form-control col-md-6 col-lg-4",
                "placeholder": "(000) 000-0000",
                "type": "tel",
            }
        ),
    )
    notes = forms.CharField(
        required=False,
        widget=CKEditorWidget(
            config_name = 'default',
            attrs={"placeholder": "Notes"}
        ),
    )

    class Meta:
        model = Contact
        fields = (
            "first_name",
            "last_name",
            "company",
            "position",
            "email",
            "phone_number",
            "notes",
        )
Beispiel #13
0
class FlatpageAdminForm(BaseFlatpageForm):
    content = forms.CharField(widget=CKEditorWidget())
Beispiel #14
0
class NewsAdminForm(forms.ModelForm):
    content = forms.CharField(widget=CKEditorWidget())

    class Meta:
        model = News
Beispiel #15
0
 class Meta:
     model = Product
     fields = [
         'category', 'title', 'slug', 'keywords', 'description', 'image',
         'detail', 'price', 'marka', 'disrenk', 'model', 'modelyili', 'km',
         'amount', 'yakit', 'vites', 'govde', 'icrenk', 'doseme', 'kaplama',
         'motorhacmi', 'motorgucu', 'isim', 'email', 'telefon'
     ]
     widgets = {
         'title':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'slug':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'keywords':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'description':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'category':
         Select(attrs={
             'class': 'input',
             'placeholder': ''
         },
                choices=Category.objects.all()),
         'image':
         FileInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'detail':
         CKEditorWidget(),
         'price':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'marka':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'model':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'modelyili':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'km':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'amount':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'yakit':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'vites':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'govde':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'icrenk':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'disrenk':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'doseme':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'kaplama':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'motorhacmi':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'motorgucu':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'isim':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'email':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
         'telefon':
         TextInput(attrs={
             'class': 'input',
             'placeholder': ''
         }),
     }
        "template with the given name and populate this field with its "
        "content.")
else:
    content_help_text = ""

if settings.DBTEMPLATES_USE_CODEMIRROR and settings.DBTEMPLATES_USE_TINYMCE:
    raise ImproperlyConfigured("You may use either CodeMirror or TinyMCE "
        "with dbtemplates, not both. Please disable one of them.")

if settings.DBTEMPLATES_USE_TINYMCE:
    from tinymce.widgets import AdminTinyMCE
    TemplateContentTextArea = AdminTinyMCE()

if settings.DBTEMPLATES_USE_CKEDITOR:
    from ckeditor.widgets import CKEditorWidget
    widget = CKEditorWidget()
    widget.config['entities'] = False
    TemplateContentTextArea = widget


class TemplateAdminForm(forms.ModelForm):
    """
    Custom AdminForm to make the content textarea wider.
    """
    content = forms.CharField(
        widget=TemplateContentTextArea,
        help_text=content_help_text, required=False)

    class Meta:
        model = Template
Beispiel #17
0
class CommentForm(forms.Form):
    content_type = forms.CharField(
        widget=forms.HiddenInput
    )  #forms.HiddenInput 隐藏不显示,相当于input标签里属性type="hidden"
    object_id = forms.IntegerField(widget=forms.HiddenInput)

    #引入回复后新增的字段,因为需要跳转到富文本编辑器,所以需要通过id把点击的那条评论找到,即父评论id(如果不为0的话)
    reply_comment_id = forms.IntegerField(widget=forms.HiddenInput(
        attrs={'id': 'reply_comment_id'}))

    #text = forms.CharField(widget=forms.Textarea) #设置成textarea标签,而不是input标签
    # 使用ckeditor开源依赖来引入富文本,修改发生为空错误时的信息提示
    text = forms.CharField(
        widget=CKEditorWidget(config_name='comment_ckeditor'),
        error_messages={'required': '评论内容不能为空'})

    #初始化会自动调用
    def __init__(self, *args, **kwargs):
        #先处理自己的逻辑
        #优化一:最好不要使用kwargs['user']这种方式,因为用get,即使没有‘user’,那就是取none,不会报错
        #优化二:如果用get,那即使获取到数据,kwargs字典中还有,然后调用super方法时,会看到关键字参数user,那就会判断关键字参数是否合法。
        #       如果没有规定这个参数,而我们写这个参数,会报错,所以用pop获取user关键字参数对应的值时,把user也从kwargs中去掉
        if 'user' in kwargs:
            self.user = kwargs.pop('user')

        super(CommentForm, self).__init__(*args, **kwargs)  #调用父类方法

    def clean(self):
        #判断用户是否登录(即使前端有判断,但是我们还是认为前端不可信)
        if self.user.is_authenticated:
            self.cleaned_data['user'] = self.user
        else:
            raise forms.ValidationError('用户尚未登录')

        #评论对象验证,需要两个内容,一个是content_type,另一个是object_id
        content_type = self.cleaned_data['content_type']
        object_id = self.cleaned_data['object_id']
        try:
            model_class = ContentType.objects.get(
                model=content_type).model_class()
            model_obj = model_class.objects.get(pk=object_id)

            #验证通过后,我们把对象保存到cleaned_data中,供views来做获取
            self.cleaned_data['content_object'] = model_obj

        #因为我们验证就是判断获取的博客对象存不存在,如果不存在,会有ObjectDoesNotExist 异常
        #最好是精确到对应的异常,而不要使用Exception
        except ObjectDoesNotExist as e:
            raise forms.ValidationError('评论对象不存在')

        return self.cleaned_data

    def clean_reply_comment_id(self):
        #判断逻辑如下:
        #单独判断新增的id字段,如果小于0,抛出错误;如果等于0,说明是主评论,因为对博客评论默认是0,那它parent为None;
        #如果不是0且能找到评论,说明是子评论,那parent的值就是这个reply_comment_id对应的评论
        reply_comment_id = self.cleaned_data['reply_comment_id']
        if reply_comment_id < 0:
            raise forms.ValidationError('回复出错')
        elif reply_comment_id == 0:
            self.cleaned_data['parent'] = None  #我们新建parent来引入,这样会给view判断提供数据来源
        elif Comment.objects.filter(pk=reply_comment_id).exists():
            self.cleaned_data['parent'] = Comment.objects.get(
                pk=reply_comment_id)
        else:
            raise forms.ValidationError('回复出错')
        return reply_comment_id
Beispiel #18
0
 def formfield_for_dbfield(self, db_field, **kwargs):
     if db_field.name in ['html']:
         kwargs['widget'] = CKEditorWidget()
     return super(EmailAgendadoAdmin, self).formfield_for_dbfield(db_field, **kwargs)
Beispiel #19
0
 def __init__(self, *args, **kwargs):
     super(PageAdminForm, self).__init__(*args, **kwargs)
     self.fields['text'].widget = CKEditorWidget(config_name='default')
Beispiel #20
0
class MessageForm(forms.Form):
    subject = forms.CharField(max_length=255)
    message = forms.CharField(widget=CKEditorWidget())
    _selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
    action = forms.CharField(widget=forms.HiddenInput)
Beispiel #21
0
 def __init__(self, config_name='default', *args, **kwargs):
     kwargs.update({'widget': CKEditorWidget(config_name=config_name)})
     super(RichTextFormField, self).__init__(*args, **kwargs)
Beispiel #22
0
 class Meta:
     model = ArticleModel
     fields = ['title', 'text', 'upload']
     widgets = {
         'text': CKEditorWidget(),
     }
Beispiel #23
0
class ColophonAdminForm(forms.ModelForm):
    body = forms.CharField(widget=CKEditorWidget())

    class Meta:
        model = Colophon
        fields = ('name', 'country', 'body')
Beispiel #24
0
class PublicacionAdminForm(forms.ModelForm):
    contenido = forms.CharField(widget=CKEditorWidget())

    class Meta:
        model = Publicacion
        fields = ['titulo', 'contenido']
Beispiel #25
0
class BaseMotionForm(CleanHtmlFormMixin, CssClassMixin, forms.ModelForm):
    """
    Base FormClass for a Motion.

    For it's own, it append the version data to the fields.

    The class can be mixed with the following mixins to add fields for the
    submitter, supporters etc.
    """
    clean_html_fields = ('text', 'reason')

    title = forms.CharField(widget=forms.TextInput(), label=ugettext_lazy("Title"))
    """
    Title of the motion. Will be saved in a MotionVersion object.
    """

    text = forms.CharField(widget=CKEditorWidget(), label=ugettext_lazy("Text"))
    """
    Text of the motion. Will be saved in a MotionVersion object.
    """

    reason = forms.CharField(
        widget=CKEditorWidget(), required=False, label=ugettext_lazy("Reason"))
    """
    Reason of the motion. will be saved in a MotionVersion object.
    """

    attachments = forms.ModelMultipleChoiceField(
        queryset=Mediafile.objects.all(),
        required=False,
        label=ugettext_lazy('Attachments'))
    """
    Attachments of the motion.
    """

    tags = forms.ModelMultipleChoiceField(
        queryset=Tag.objects.all(),
        required=False,
        label=ugettext_lazy('Tags'))

    key_order = ('identifier',
                 'title',
                 'text',
                 'reason',
                 'submitter',
                 'supporter',
                 'category',
                 'tags',
                 'attachments',
                 'workflow',
                 'disable_versioning',)
    """
    Order of fields, including optional fields from mixins (for example MotionSupporterMixin)
    """

    class Meta:
        model = Motion
        fields = ()

    def __init__(self, *args, **kwargs):
        """
        Fill the FormFields related to the version data with initial data.
        Fill also the initial data for attachments and tags.
        """
        self.motion = kwargs.get('instance', None)
        self.initial = kwargs.setdefault('initial', {})
        if self.motion is not None:
            last_version = self.motion.get_last_version()
            self.initial['title'] = last_version.title
            self.initial['text'] = last_version.text
            self.initial['reason'] = last_version.reason
            self.initial['attachments'] = self.motion.attachments.all()
            self.initial['tags'] = self.motion.tags.all()
        super(BaseMotionForm, self).__init__(*args, **kwargs)

        keys = self.fields.keys()
        keys_order = [key for key in self.key_order if key in keys]
        keys_order.extend(set(keys) - set(keys_order))
        self.fields = collections.OrderedDict([(key, self.fields[key]) for key in keys_order])
Beispiel #26
0
class AnswerForm(forms.ModelForm):
    ans = forms.CharField(widget=CKEditorWidget())

    class Meta:
        model = Answer
        fields = ["ans"]
Beispiel #27
0
class videoAdminForm(forms.ModelForm):
    body = forms.CharField(widget=CKEditorWidget(config_name='admin_ckeditor'))

    class Meta:
        model = video
        fields = '__all__'
Beispiel #28
0
class QuestionForm(forms.ModelForm):
    details = forms.CharField(widget=CKEditorWidget())

    class Meta:
        model = Question
        fields = ["qus", "details", "tags"]
Beispiel #29
0
class PostAdminForm(forms.ModelForm):
    description = forms.CharField(widget=CKEditorWidget())

    class Meta:
        model = Post
        fields = "__all__"
Beispiel #30
0
class AdminBodyForm(forms.ModelForm):
    body = forms.CharField(widget=CKEditorWidget(
        attrs={'style': 'width: 800px;'}))
class SendMailForm(forms.Form):
    content_field = forms.CharField(widget=CKEditorWidget())
class PostForm(forms.ModelForm):
    description = forms.CharField(widget=CKEditorWidget())

    class Meta:
        model = Post
        fields = ['title', 'description']