Exemplo n.º 1
0
class ProyectoSave(forms.Form):

    public_options = [(res.id, res.name) for res in Category.objects.all()]

    name = forms.CharField(label='Nombre del proyecto',
                           max_length=50,
                           required=True)

    category = forms.TypedChoiceField(label='Categoria del proyecto',
                                      choices=public_options)

    goal = forms.IntegerField(
        label='Meta del proyecto $',
        required=True,
    )

    deadline = forms.DateTimeField(
        label='Fecha limite',
        required=False,
        widget=forms.TimeInput(attrs={'type': 'date'}))

    description = forms.CharField(label='Cuentanos de tu proyecto',
                                  max_length=10000,
                                  required=True,
                                  widget=CKEditorWidget())

    image = forms.ImageField(
        label='Carga la imagen...',
        required=True,
        widget=forms.ClearableFileInput(attrs={'id': 'file'}))
Exemplo n.º 2
0
class CommentMasalahForm(forms.ModelForm):
    content = forms.CharField(
        label='แสดงความคิดเห็น',
        widget=CKEditorWidget(config_name='awesome_comment'))

    class Meta:
        model = CommentMasalah
        fields = ('content', )
Exemplo n.º 3
0
class PostEditForm(forms.ModelForm):
    body = forms.CharField(label='เขียนเนื้อหาโพสต์/บทความ',
                           widget=CKEditorWidget(config_name='awesome'))
    title = forms.CharField(label="หัวข้อโพสต์/บทความ", required=True)

    class Meta:
        model = Post
        fields = ('title', 'body', 'category', 'status')
Exemplo n.º 4
0
class CommentForm(forms.Form):
    parent = forms.CharField(widget=forms.HiddenInput)
    post_id = forms.IntegerField(widget=forms.HiddenInput)
    content = forms.CharField(
        widget=CKEditorWidget(config_name='comment_config'),
        error_messages={'required': '评论内容不能为空.'})

    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('用户尚未登录')
        post_id = self.cleaned_data['post_id']
        try:
            post = Post.objects.get(id=post_id)
            self.cleaned_data['post'] = post
        except ObjectDoesNotExist as e:
            raise forms.ValidationError('文章不存在')
        return self.cleaned_data

    def clean_parent(self):
        parent = int(self.cleaned_data['parent'])
        if parent < 0:
            raise forms.ValidationError('回复出错')
        elif parent == 0:
            self.cleaned_data['parent'] = None
        elif Comment.objects.filter(pk=parent).exists():
            self.cleaned_data['parent'] = Comment.objects.get(pk=parent)
        else:
            raise forms.ValidationError('回复出错')
        return self.cleaned_data['parent']
Exemplo n.º 5
0
 class Meta:
     model = Page
     widgets = {  'parent': forms.Select(attrs={'size': 10, 'width':100}) \
                 , 'content' : CKEditorWidget(config_name='default', attrs={}) \
                 ,'teaser': forms.Textarea(attrs={'rows':3, 'cols':40}) \
                 }
Exemplo n.º 6
0
class ArticleCommentForm(forms.Form):
    '''回帖表单'''
    body = forms.CharField(label='回帖', widget=CKEditorWidget(), required=True)
Exemplo n.º 7
0
class EditForm(forms.Form):
    content = forms.CharField(widget=CKEditorWidget())