Beispiel #1
0
class CommentForm(forms.Form):
    content_type = forms.CharField(widget=forms.HiddenInput)
    object_id = forms.IntegerField(widget=forms.HiddenInput)
    text = forms.CharField(widget=CKEditorWidget(config_name='comment_ckeditor'),
                                                error_messages={'required': '评论对象不能为空'})
    reply_comment_id = forms.IntegerField(widget=forms.HiddenInput(attrs={'id': 'reply_comment_id'}))

    def __init__(self, *args, **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 = 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)
            self.cleaned_data['content_object'] = model_obj
        except ObjectDoesNotExist:
            raise forms.ValidationError('评论对象不存在')

        return self.cleaned_data        

    def clean_reply_comment_id(self):
        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
        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 #2
0
    class Meta:
        model = Article
        fields = ['title', 'content', 'file_1', 'file_2', 'file_3']

        widgets = {
            'title':
            forms.TextInput(attrs={
                'class': 'form-control',
                'placeholder': '제목'
            }),
            'content':
            CKEditorWidget(),
            'file_1':
            forms.FileInput(attrs={'class': 'custom-file-input'}),
            'file_2':
            forms.FileInput(attrs={'class': 'custom-file-input'}),
            'file_3':
            forms.FileInput(attrs={'class': 'custom-file-input'}),
        }
def bulk_send_worksample_email(request):
    if request.method != 'POST':
        editor = CKEditorWidget(config_name='admin',
                                attrs={
                                    'id': 'email_template_editor',
                                })
        template = 'bulk_send_worksample_email.haml'
        templates = list(
            WorkSampleTemplate.objects.filter(is_active=True, ).values_list(
                'pk', 'description'))
        emails = request.session.pop('emails', None)

        form = request.session.get('bulk_create_form', {})
        editor_html = editor.render('email_template',
                                    form.get('email_template'))

        context = dict(
            worksample_templates=templates,
            form=form,
            emails=emails,
            editor_html=editor_html,
        )
        return render(request, template, context)

    request.session['bulk_create_form'] = request.POST
    form = BulkCreateSendForm(request.POST)
    if form.is_valid():
        emails = form.send_emails(request)
        session_emails = []
        for email_sent, email in emails:
            body = email.body
            if email.alternatives:
                body = email.alternatives[0][0]
            session_email = dict(
                was_sent=email_sent,
                subject=email.subject,
                to=email.to[0],
                from_address=email.from_email,
                body=body,
            )
            session_emails.append(session_email)
        request.session['emails'] = session_emails
    return redirect('bulk_create_worksample')
Beispiel #4
0
class ObservacaoForm(ModelForm):

    observacao = CharField(widget=CKEditorWidget(
        attrs={'id': 'id_observacao_tarefa'}))

    class Meta:
        model = ObservacaoTarefaAtividade
        fields = ['tarefa', 'atividade', 'status', 'observacao', 'user']
        widgets = {
            'user': HiddenInput(),
        }

    def __init__(self, *args, ponto_controle=None, **kwargs):
        super(ObservacaoForm, self).__init__(*args, **kwargs)
        if ponto_controle:
            tarefas = Tarefa.objects.filter(ponto_controle=ponto_controle)
            self.fields['tarefa'].queryset = tarefas
            self.fields['atividade'].queryset = Atividade.objects.filter(
                tarefa__in=tarefas)
Beispiel #5
0
 class Meta:
     model = News
     queryset = Category.objects.all()
     fields = [
         'category', 'title', 'keywords', 'description', 'image', 'slug',
         'detail'
     ]
     widgets = {
         'category':
         Select(attrs={
             'class': 'input',
             'placeholder': 'category'
         },
                choices=queryset),
         'title':
         TextInput(attrs={
             'class': 'input',
             'placeholder': 'title'
         }),
         'keywords':
         TextInput(attrs={
             'class': 'input',
             'placeholder': 'keywords'
         }),
         'description':
         TextInput(attrs={
             'class': 'input',
             'placeholder': 'description'
         }),
         'image':
         FileInput(attrs={
             'class': 'input',
             'placeholder': 'image'
         }),
         'slug':
         TextInput(attrs={
             'class': 'input',
             'placeholder': 'slug'
         }),
         'detail':
         CKEditorWidget(),
     }
Beispiel #6
0
class CommentForm(forms.Form):
    object_id = forms.IntegerField(widget=forms.HiddenInput)
    text = forms.CharField(
        widget=CKEditorWidget(config_name='comment_ckeditor'),
        error_messages={'required': "评论内容不能为空"})
    reply_comment_id = forms.IntegerField(widget=forms.HiddenInput(
        attrs={'id': 'reply_comment_id'}))

    def __init__(self, *args, **kwargs):
        #把user对象传进来,因为没有request
        ## if kwargs has no key 'user', user is assigned None
        # make sure your code handles this case gracefully
        self.user = kwargs.pop('user', None)
        super(CommentForm, self).__init__(*args, **kwargs)

    def clean(self):
        #判断用户是否登录
        if self.user.is_authenticated:
            self.cleaned_data['user'] = self.user
        else:
            raise forms.ValidationError('用户未登录')
        #评论对象验证
        object_id = self.cleaned_data['object_id']
        try:
            blog = Blog.objects.get(id=object_id)
            self.cleaned_data['blog'] = blog
        except ObjectDoesNotExist:
            raise forms.ValidationError("评论对象不存在")
        return self.cleaned_data

    def clean_reply_comment_id(self):
        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
        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
 class Meta:
     model = Content
     fields = [
         'type', 'title', 'slug', 'keywords', 'description', 'image',
         'detail'
     ]  # bu elemanlar gözükecek
     widgets = {
         'type':
         Select(attrs={
             'class': 'input',
             'placeholder': 'type'
         },
                choices=TYPE),
         'title':
         TextInput(attrs={
             'class': 'input',
             'placeholder': 'title'
         }),
         'slug':
         TextInput(attrs={
             'class': 'input',
             'placeholder': 'slug'
         }),
         'keywords':
         TextInput(attrs={
             'class': 'input',
             'placeholder': 'keywords'
         }),
         'description':
         TextInput(attrs={
             'class': 'input',
             'placeholder': 'description'
         }),
         'image':
         FileInput(attrs={
             'class': 'input',
             'placeholder': 'image'
         }),
         'detail':
         CKEditorWidget(
         ),  #ckeditor input, widget içerisinde kullandığım için böyle yazıyorum
     }
Beispiel #8
0
class CommentForms(forms.Form):
    content_type = forms.CharField(widget=forms.HiddenInput)
    object_id = forms.CharField(widget=forms.HiddenInput)
    detail = forms.CharField(widget=CKEditorWidget(config_name='ck_comment'))

    reply_comment = forms.IntegerField(widget=forms.HiddenInput)

    def __init__(self, *args, **kwargs):
        if 'user' in kwargs:
            self.user = kwargs.pop('user')
        super(CommentForms, self).__init__(*args, **kwargs)

    def clean(self):
        if self.user.is_authenticated:
            self.cleaned_data['user'] = self.user
        else:
            raise forms.ValidationError('用户尚未登录')

        ct = self.cleaned_data['content_type']
        obj_id = self.cleaned_data['object_id']

        try:
            model_class = ContentType.objects.get(model=ct).model_class()
            model_obj = model_class.objects.get(pk=obj_id)
            self.cleaned_data['content_object'] = model_obj
        except:
            raise forms.ValidationError('评论的对象不存在')

        return self.cleaned_data

    def clean_reply_comment(self):
        reply_comment_id = self.cleaned_data['reply_comment']
        if reply_comment_id < 0:
            forms.ValidationError('回复发生了异常!')
        elif reply_comment_id == 0:
            self.cleaned_data['reply_parent'] = None
        elif Comments.objects.filter(pk=reply_comment_id).exists():
            self.cleaned_data['reply_parent'] = Comments.objects.get(
                pk=reply_comment_id)
        else:
            forms.ValidationError('回复发生了异常!')
        return reply_comment_id
Beispiel #9
0
class FormBase(ModelForm):
    algoritmo = forms.CharField(widget=CKEditorWidget(config_name='edicion'))

    # usro = forms.ForeignKey(required=False)

    # def clean_usro(self):
    #     usro = self.cleaned_data['usro']
    #     return usro

    class Meta:
        model = Base
        # exclude = ('usro',)
        fields = [
            'tema', 'observacion', 'problema', 'clave', 'solucion',
            'algoritmo', 'referencia', 'usro'
        ]
        labels = {
            'tema': _('Tema'),
            'observacion': _('Observaciones'),
            'problema': _('Problema'),
            'clave': _('Palabras Clave'),
            'solucion': _('Solución'),
            'algoritmo': _('Algoritmo'),
            'referencia': _('Referencia')
        }
        # help_texts = {
        #     'problema': _(Base.problema)
        # }
        error_messages = {
            'problema': {
                'required': _('Ingrese un problema')
            },
            'tema': {
                'required': _('Ingrese un tema')
            },
            'solucion': {
                'required': _('Ingrese una solución')
            },
            'clave': {
                'required': _("Ingrese una o más palabras clave")
            }
        }
Beispiel #10
0
class CompanyForm(forms.ModelForm):
    name = forms.CharField(
        max_length=50,
        required=True,
        widget=forms.TextInput(attrs={
            "class": "form-control col-md-6 col-lg-4",
            "placeholder": "Name"
        }),
    )
    industries = forms.ModelMultipleChoiceField(
        required=False,
        queryset=Industry.objects.all(),
        widget=forms.SelectMultiple(
            attrs={"class": "custom-select col-md-6 col-lg-4"}),
    )
    location = forms.CharField(
        max_length=140,
        required=False,
        widget=forms.Textarea(
            attrs={
                "class": "form-control col-md-6 col-lg-4",
                "placeholder": "Location",
                "rows": 3
            }),
    )
    size = forms.ChoiceField(
        required=False,
        choices=(Company.SIZES),
        widget=forms.Select(attrs={
            "class": "custom-select col-md-6 col-lg-4",
            "placeholder": "Size"
        }),
    )
    notes = forms.CharField(
        required=False,
        widget=CKEditorWidget(config_name='default',
                              attrs={"placeholder": "Notes"}),
    )

    class Meta:
        model = Company
        fields = ("name", "industries", "location", "size", "notes")
Beispiel #11
0
class BooleanQuestionForm(forms.ModelForm):
    lesson = forms.ModelChoiceField(
        queryset=Lesson.objects.all(),
        widget=forms.Select(attrs={
            'class': 'form-control',
            'id': 'lesson',
            'autocomplete': 'off'
        }))

    title = forms.CharField(widget=forms.TextInput(
        attrs={
            'class': 'form-control',
            'id': 'title',
            'autocomplete': 'off'
        }))

    subject = forms.CharField(widget=forms.TextInput(
        attrs={
            'class': 'form-control',
            'id': 'subject',
            'autocomplete': 'off'
        }))

    question = forms.CharField(widget=CKEditorWidget())

    level = forms.CharField(widget=forms.Select(choices=LEVEL,
                                                attrs={
                                                    'class': 'form-control',
                                                    'id': 'level',
                                                    'autocomplete': 'off',
                                                }))

    answer = forms.CharField(widget=forms.Select(choices=ANSWER_BOOLEAN,
                                                 attrs={
                                                     'class': 'form-control',
                                                     'id': 'answer',
                                                     'autocomplete': 'off',
                                                 }))

    class Meta:
        model = Question
        fields = ['lesson', 'title', 'subject', 'level', 'question', 'answer']
Beispiel #12
0
class ContactForm(forms.Form):
    first_name = forms.CharField(
        label='',
        widget=forms.TextInput(attrs={
            'placeholder': 'First Name',
            'class': 'form-control'
        }))
    last_name = forms.CharField(
        label='',
        widget=forms.TextInput(attrs={
            'placeholder': 'Last Name',
            'class': 'form-control'
        }))
    email = forms.EmailField(label='',
                             widget=forms.TextInput(attrs={
                                 'placeholder': 'E-Mail',
                                 'class': 'form-control'
                             }))
    subject = forms.CharField(
        label='',
        widget=forms.TextInput(attrs={
            'placeholder': 'Subject',
            'class': 'form-control input_box'
        }))
    topic = forms.ChoiceField(
        choices=settings.FEED_BACK,
        label='',
        widget=forms.Select(
            attrs={'class': 'mdb-select md-form colorful-select dropdown-ins'
                   }))
    message = RichTextFormField(
        label='',
        widget=CKEditorWidget(attrs={
            'placeholder': 'Message',
            'class': 'form-control'
        }))
    captcha = ReCaptchaField(widget=ReCaptchaWidget(), label="")

    def __init__(self, *args, **kwargs):
        super(ContactForm, self).__init__(*args, **kwargs)
        self.fields['message'].widget.attrs['cols'] = 10
        self.fields['message'].widget.attrs['rows'] = 20
Beispiel #13
0
class ContactForm(forms.ModelForm):
    message = forms.CharField(widget=CKEditorWidget())

    class Meta:
        model = Contact_us
        fields = ['name', 'email', 'message']
        widgets = {
            'name':
            forms.TextInput(attrs={
                'class': 'form-control',
                'placeholder': 'name'
            }),
            'email':
            forms.EmailInput(attrs={
                'class': 'form-control',
                'placeholder': 'email'
            }),
            #    'message' :forms.Textarea(attrs={'class':'form-control',
            # 'placeholder':'Type your message here'}),
        }
Beispiel #14
0
class BookForm(ModelForm):

    book_intro = forms.CharField(widget=CKEditorWidget())
    book_tag = TagField(widget=TagWidget(), required=False, help_text='A comma-separated list of tags.')
    pub_date = forms.DateField(widget=CustomSelectDateWidget(years=YEAR_CHOICES))
    # book_cover = forms.ImageField(widget=PreviewImageWidget())
    book_cover = CustomImageField(widget=PreviewImageWidget())

    class Meta:
        model = Book
        fields = [
            'book_title',
            'sub_title',
            'book_cover',
            'pub_date',
            'book_intro',
            'book_author',
            'book_press',
            'book_tag',
        ]
Beispiel #15
0
class DefaultBlogForm(forms.ModelForm):
    section = forms.ModelChoiceField(queryset=BlogParent.objects.all().filter(
        ~Q(title='Orphan'),
        ~Q(title='Blog'),
        children=None,
    ),
                                     empty_label=None,
                                     required=True,
                                     label="Select Parent")
    content = forms.CharField(widget=CKEditorWidget())
    tags = TagField(help_text="comma seperated fields for tags")

    class Meta:
        model = DefaultBlog

    def save(self):
        instance = DefaultBlog()
        instance.title = self.cleaned_data['title']
        instance.content = self.cleaned_data['content']
        return instance
Beispiel #16
0
class PostForm(forms.Form):
    title = forms.CharField(
        widget=forms.TextInput(attrs={'placeholder': '标题'}),
        error_messages={'required': '评论内容不能为空'})
    text = forms.CharField(
        widget=CKEditorWidget(config_name='comment_ckeditor'),
        error_messages={'required': '发帖内容不能为空'})

    def __init__(self, *args, **kwargs):
        if 'user' in kwargs:
            self.user = kwargs.pop('user')
        super(PostForm, self).__init__(*args, **kwargs)

    def clean(self):
        # 判断用户是否登录
        if self.user.is_authenticated:
            self.cleaned_data['user'] = self.user
        else:
            raise forms.ValidationError("用户尚未登录!")
        return self.cleaned_data
Beispiel #17
0
 class Meta:
     fields = ("title", "url", "active", "image", "sidebar_size",
               "thumbnail_size", "offline_price", "online_price",
               "short_text", "meta_description", "text")
     widgets = {
         'title':
         forms.Textarea(attrs={"style": "width: 400px; height: 34px;"}),
         'url':
         forms.Textarea(attrs={"style": "width: 400px; height: 34px;"}),
         'short_text':
         forms.Textarea(attrs={"style": "width: 400px; height: 68px;"}),
         'text':
         CKEditorWidget(),
         'price':
         forms.NumberInput(),
         'special_price':
         forms.NumberInput(),
         "meta_description":
         forms.Textarea(attrs={"style": "width: 400px; height: 68px;"}),
     }
Beispiel #18
0
class EventUpdateForm(forms.ModelForm):
    #sectors
    fee = forms.DecimalField(
                    initial=None,
                    help_text='<i>if event is Free, paste 0 </i>',)
    content_en = forms.CharField(
                    help_text='<i>short info for notifications ans stuff </i>', 
                    widget=forms.Textarea(attrs={'rows': 3}))
    content_cn = forms.CharField(
                    help_text='<i>in CN , short info for notifications ans stuff </i>', 
                    widget=forms.Textarea(attrs={'rows': 3}))
    richcontent = forms.CharField(widget=CKEditorWidget(attrs={'cols':50,'rows': 3}))

    class Meta:
        model = Event
        widgets = {'author': forms.HiddenInput(),
                    'org': forms.HiddenInput(),
                    }
        
        exclude = ['dt_event']
Beispiel #19
0
class AuthorForm(forms.ModelForm):

    bio = forms.CharField(widget=CKEditorWidget())

    class Meta:
        model = Author
        fields = '__all__'

        widgets = {
            'birth_date':
            forms.DateInput(format="%d %d %Y", attrs={
                'type': 'date',
            }),
            'reminder_time':
            forms.TimeInput(format="%H:%M", attrs={
                'type': 'time',
            }),
            'member_type':
            forms.RadioSelect(),
        }
Beispiel #20
0
class VisaInfoForm(forms.ModelForm):
    visa_details = forms.CharField(widget=CKEditorWidget())

    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request', None)
        super(VisaInfoForm, self).__init__(*args, **kwargs)
        self.fields['visa_country'].empty_label = 'Select Country'

    class Meta:
        model = VisaInfo
        exclude = ()

        widgets = {
            'visa_country': forms.Select(attrs={'class': 'form-control'}),
            # 'visa_details': forms.Textarea(
            #     attrs={
            #         'class': 'form-control'
            #     }
            # )
        }
Beispiel #21
0
class AboutPostAdminForm(forms.ModelForm):
    body = forms.CharField(label=_("content"), widget=CKEditorWidget())

    class Meta:
        model = AboutPost
        fields = []

    def save(self, commit=True):
        post = super(AboutPostAdminForm, self).save(commit=False)

        if post.pk is None or AboutPost.objects.filter(
                pk=post.pk, publish_time=None).count():
            if self.cleaned_data["state"] == 1:
                post.publish_time = now()

        post.body = self.cleaned_data["body"]
        post.update_time = now()
        post.save()

        return post
Beispiel #22
0
class CommentForm(forms.ModelForm):
    # nickname = forms.CharField(
    #     max_length=50,
    #     label='昵称',
    #     widget=forms.widgets.Input(
    #         attrs={'class': 'form-control', 'style': 'width: 60%;'}
    #     )
    # )
    # email = forms.EmailField(
    #     label='邮箱',
    #     widget=forms.widgets.Input(
    #         attrs={'class': 'form-control', 'style': 'width: 60%;'}
    #     )
    # )
    # site = forms.URLField(
    #     label='网站',
    #     widget=forms.widgets.Input(
    #         attrs={'class': 'form-control', 'style': 'width: 60%;'}
    #     )
    # )
    content = forms.CharField(
        max_length=500,
        label='评论内容(内容不得少于十个字符)',
        widget=CKEditorWidget()
        # widget=forms.widgets.Textarea(
        #     attrs={'class': 'form-control', 'rows': 3, 'cols': 60}
        # )
    )

    def clean_content(self):
        content = self.cleaned_data.get('content')
        if len(content) < 10:
            raise forms.ValidationError('内容长度过短,请补充!')
        content = mistune.markdown(content)
        return content

    class Meta:
        model = Comment
        fields = [
            'content',
        ]
Beispiel #23
0
class SendEmailForm(forms.Form):
    recipients = forms.ChoiceField(label=_("Recipient Group"), choices=[])
    subject = forms.CharField(label=_("Email Subject"), max_length=100)
    body = forms.CharField(label="Email Body", widget=CKEditorWidget())

    def __init__(self, *args, **kwargs):
        choices = kwargs.pop("recipients")
        super().__init__(*args, **kwargs)
        self.fields["recipients"].choices = choices
        self.helper = FormHelper()
        self.helper.form_action = reverse_lazy("send_email")
        self.helper.form_method = "post"
        self.helper.html5_required = True
        self.helper.layout = Layout(
            Div(
                Field("recipients", help_text=_("Recipients for this email")),
                Field(
                    "subject",
                    autofocus="autofocus",
                    help_text=_("Email Subject"),
                    wrapper_class="col-12 col-md-6",
                ),
                Field("body", help_text=_("Email Body")),
                css_class="form-row",
            ),
            Div(
                Submit("sendself",
                       _("Send Test Email To Myself"),
                       css_class="default"),
                Submit(
                    "sendreal",
                    _("Send Email To Selected Recipients"),
                    style=("color: #fff !important;"
                           "background-color:#f00 !important"),
                ),
            ),
        )

    def clean(self):
        super().clean()
        self.cleaned_data["sendreal"] = "sendreal" in self.data
Beispiel #24
0
 class Meta:
     model = Content
     fields = [
         'type', 'title', 'slug', 'keywords', 'description', 'image',
         'detail'
     ]
     widgets = {
         'title':
         TextInput(attrs={
             'class': 'input',
             'placeholder': 'title'
         }),
         'slug':
         TextInput(attrs={
             'class': 'input',
             'placeholder': 'slug'
         }),
         'keywords':
         TextInput(attrs={
             'class': 'input',
             'placeholder': 'keywords'
         }),
         'description':
         TextInput(attrs={
             'class': 'input',
             'placeholder': 'description'
         }),
         'type':
         Select(attrs={
             'class': 'input',
             'placeholder': 'type'
         },
                choices=TYPE),
         'image':
         FileInput(attrs={
             'class': 'input',
             'placeholder': 'image'
         }),
         'detail':
         CKEditorWidget()
     }
Beispiel #25
0
 class Meta:
     model = Content
     fields = [
         'kind', 'title', 'keywords', 'description', 'image', 'detail',
         'slug'
     ]
     widgets = {
         'title':
         TextInput(attrs={
             'class': 'form-control',
             'placeholder': 'Title'
         }),
         'slug':
         TextInput(attrs={
             'class': 'form-control',
             'placeholder': 'Slug'
         }),
         'keywords':
         TextInput(attrs={
             'class': 'form-control',
             'placeholder': 'Keywords'
         }),
         'description':
         TextInput(attrs={
             'class': 'form-control',
             'placeholder': 'Description'
         }),
         'kind':
         Select(attrs={
             'class': 'form-control',
             'placeholder': 'Kind'
         },
                choices=TYPE),
         'image':
         FileInput(attrs={
             'class': 'form-control',
             'placeholder': 'Image'
         }),
         'detail':
         CKEditorWidget(),
     }
Beispiel #26
0
 class Meta:
     model = Product
     fields = [
         'category',
         'title',
         'keywords',
         'description',
         'image',
         'price',
         'amount',
         'slug',
         'detail',
     ]
     widgets = {
         'category': Select(attrs={
             'class': 'input',
         }),
         'title': TextInput(attrs={
             'class': 'input',
         }),
         'keywords': TextInput(attrs={
             'class': 'input',
         }),
         'description': TextInput(attrs={
             'class': 'input',
         }),
         'price': TextInput(attrs={
             'class': 'input',
         }),
         'amount': TextInput(attrs={
             'class': 'input',
         }),
         'detail': CKEditorWidget(),
         'image': FileInput(attrs={
             'class': 'input',
         }),
         'slug': TextInput(attrs={
             'class': 'input',
         }),
         # dosya upload edebilmek için FileInput
     }
Beispiel #27
0
class CommentForm(forms.ModelForm):
    nickname = forms.CharField(
        label='昵称',
        max_length=50,
        widget=forms.TextInput(
            attrs={'class': 'form-control', 'style': 'width:60%;'}
        )
    )
    email = forms.CharField(
        label='Email',
        max_length=50,
        widget=forms.EmailInput(
            attrs={'class': 'form-control', 'style': 'width:60%;'}
        )
    )
    website = forms.CharField(
        label='网站',
        max_length=100,
        widget=forms.URLInput(
            attrs={'class': 'form-control', 'style': 'width: 60%;'}
        )
    )
    # content = forms.CharField(
    #     label="内容",
    #     max_length=500,
    #     widget=forms.widgets.Textarea(
    #         attrs={'rows': 6, 'cols': 60, 'class': 'form-control'}
    #     )
    # )
    content = forms.CharField(widget=CKEditorWidget(), label='内容', required=True)

    def clean_content(self):
        content = self.cleaned_data.get('content')
        if len(content) < 10:
            raise forms.ValidationError('内容长度怎么能这么短呢!!')
        content = mistune.markdown(content)
        return content

    class Meta:
        model = Comment
        fields = ['nickname', 'email', 'website', 'content']
Beispiel #28
0
class ContentRichTextForm(forms.Form, BasePluginForm):
    """ContentRichTextForm."""

    plugin_data_fields = [
        ('text', '')
    ]

    text = forms.CharField(
        label=_('Text'),
        required=True,
        widget=CKEditorWidget(),
    )

    def clean_text(self):
        if not BLEACH_INSTALLED:
            return self.cleaned_data['text']

        allowed_tags = getattr(
            settings,
            'FOBI_PLUGIN_CONTENT_RICHTEXT_ALLOWED_TAGS',
            bleach.ALLOWED_TAGS,
        )
        allowed_attrs = getattr(
            settings,
            'FOBI_PLUGIN_CONTENT_RICHTEXT_ALLOWED_ATTRIBUTES',
            bleach.ALLOWED_ATTRIBUTES,
        )
        allowed_styles = getattr(
            settings,
            'FOBI_PLUGIN_CONTENT_RICHTEXT_ALLOWED_STYLES',
            bleach.ALLOWED_STYLES,
        )

        return bleach.clean(
            text=self.cleaned_data['text'],
            tags=allowed_tags,
            attributes=allowed_attrs,
            styles=allowed_styles,
            strip=True,
            strip_comments=True,
        )
Beispiel #29
0
class JournalistCreateVideo(forms.Form):
    title = forms.CharField(
        max_length=255,
        widget=forms.Textarea(attrs={
            'rows': '2',
            'class': 'form-control',
            'placeholder': 'Titre'
        }))

    small_title = forms.CharField(
        max_length=155,
        widget=forms.TextInput(attrs={
            'class': 'form-control',
            'placeholder': 'Titre réduit'
        }))

    url = forms.URLField(widget=forms.URLInput(
        attrs={
            'class': 'form-control',
            'placeholder': 'Lien du vidéo'
        }))

    content = forms.CharField(widget=CKEditorWidget())

    resume = forms.CharField(required=False,
                             widget=forms.Textarea(
                                 attrs={
                                     'rows': '5',
                                     'class': 'form-control',
                                     'placeholder': 'Résumé de l\'article'
                                 }))

    category = forms.CharField(widget=forms.HiddenInput(
        attrs={
            'class': 'form-control',
            'placeholder': 'Résumé de l\'article'
        }))

    comment_enable = forms.CharField(widget=forms.HiddenInput())

    share_enable = forms.CharField(widget=forms.HiddenInput())
Beispiel #30
0
class blogForm(forms.ModelForm):
    icerik = forms.CharField(widget=CKEditorWidget())

    class Meta:
        model = Blog
        fields = ['title', 'image', 'icerik', 'yayin_taslak', 'kategoriler']

    def __init__(self, *args, **kwargs):
        super(blogForm, self).__init__(*args, **kwargs)
        for field in self.fields:
            self.fields[field].widget.attrs = {'class': 'form-control'}
        self.fields['icerik'].widget.attrs['rows'] = 10

    def clean_icerik(self):
        icerik = self.cleaned_data.get('icerik')
        if len(icerik) < 250:
            uzunluk = len(icerik)
            msg = "Lütfen en az 250 karakter giriniz. Şuan girilen karakter: (%s)" % (
                uzunluk)
            raise forms.ValidationError(msg)
        return icerik