Example #1
0
class CommentForm(forms.Form):
    """
    ===============================================================================
    function:    评论表单
    developer:    BeginMan
    add-time      2014/06/14
    ===============================================================================
    """

    content = forms.CharField(label=u'说两句吧',widget=MarkDownInput(
        attrs={'class': 'form-control', 'placeholder': u'我相信您的评论能一针见血!', 'required': ''})
    )

    def __init__(self, request=None, *args, **kwargs):
        self.request = request
        super(CommentForm, self).__init__(*args, **kwargs)

    def clean(self):
        cleaned_data = super(CommentForm, self).clean()
        content = cleaned_data.get("content")
        tid = self.request.POST.get('tid', None)
        if not tid:
            raise forms.ValidationError(u'缺少评论对象')
        if tid:
            # 对content 筛选@,并发送信息通知,邮件通知
            Comment.objects.create(obj=int(tid), user=self.request.user, content=content)
        return cleaned_data
Example #2
0
class BlogForm(ModelForm):
    """
    ---------------------------------------
    功能说明:博客发布
    ---------------------------------------
    时间:     2015-04-10
    ---------------------------------------
    """
    title = forms.CharField(
        max_length=100,
        label=u'标题',
        widget=forms.TextInput(attrs={
            'class': 'form-control',
            'placeholder': u'标题',
            'required': ''
        }))
    type = forms.IntegerField()
    is_show = forms.CharField(required=False,
                              max_length=100,
                              label=u'加密',
                              widget=forms.TextInput(attrs={
                                  'calss': 'form-control',
                                  'placeholder': u'密码'
                              }))
    content = forms.CharField(
        label=u'内容',
        widget=MarkDownInput(attrs={
            'class': 'form-control',
            'placeholder': u'内容',
            'required': 'True'
        }))

    class Meta:
        model = Blog
        fields = ('title', 'type', 'content', 'is_show')
Example #3
0
class ThemeForm(ModelForm):
    """
    ===============================================================================
    function:    Theme编辑表单
    developer:    BeginMan
    add-time      2014/06/10
    ===============================================================================
    """

    title = forms.CharField(max_length=100, label=u'标题', widget=forms.TextInput(
        attrs={'class': 'form-control', 'placeholder': u'标题', 'required': ''})
    )
    type = forms.IntegerField()
    content = forms.CharField(label=u'内容',widget=MarkDownInput(
        attrs={'class': 'form-control', 'placeholder': u'标题', 'required': ''})
    )
    start_date = forms.DateField(label=u'起始时间', widget=forms.TextInput(
        attrs={'class': 'form-control', 'placeholder': u'起始时间', 'required': ''})
    )
    end_date = forms.DateField(label=u'截止时间', widget=forms.TextInput(
        attrs={'class': 'form-control', 'placeholder': u'截止时间', 'required': ''})
    )
    class Meta:
        model = Theme
        fields = ('title','type', 'content', 'start_date', 'end_date')
Example #4
0
class WikiForm(ModelForm):
    """add wiki"""
    content = forms.CharField(label=u'wiki',widget=MarkDownInput(
        attrs={'class': 'form-control', 'placeholder': u'wiki', 'required': ''})
    )
    class Meta:
        model = Wiki
        fields = ('content',)
Example #5
0
class EntryForm(forms.Form):
    title = forms.CharField(
        label="",
        widget=forms.TextInput(attrs={"placeholder": "Select a title"}))
    body = forms.CharField(widget=MarkDownInput(attrs={
        "cols": "80",
        "width": "900px"
    }),
                           label="")
Example #6
0
class PostForm(TaggedModelForm):
  content = forms.CharField(widget=MarkDownInput(),required=False)
  photo = forms.ModelChoiceField(Photo.objects.all(),required=False)
  class Meta:
    model = Post
    fields = ('title','slug','content','short_content','publish_dt','tags','status','photo')

  def clean_slug(self):
    slug = self.cleaned_data['slug']
    if self.instance:
      if Post.objects.filter(slug=slug, user=self.user).exclude(pk=self.instance.pk).count():
        raise forms.ValidationError('You already have a post with this slug')
    return slug

  def clean_tags(self):
    tags = self.cleaned_data['tags']
    if not ',' in tags:
      tags = tags + ','
    return tags

  def save(self,*args,**kwargs):
    try:
      self.instance.user
    except ObjectDoesNotExist:
      self.instance.user = self.user
    return super(PostForm,self).save(*args,**kwargs)

  def __init__(self, *args, **kwargs):
    # checking for user argument here for a more
    # localized form
    self.user = None
    self.timezone = None
    if kwargs.get('instance',None):
      kwargs['initial'] = kwargs.pop('initial',{})
      kwargs['initial']['publish_dt'] = kwargs['instance'].publish_dt

    if 'user' in kwargs:
      self.user = kwargs.pop('user', None)
    super(PostForm, self).__init__(*args, **kwargs)
    self.fields['publish_dt'].widget = AdminSplitDateTime()
    self.fields['slug'].help_text = "URL will be /blog/your-name/<b>slug-goes-here</b>/"
    self.fields['tags'].help_text = "Separate tags with commas. Input will be lowercased."
    self.fields['publish_dt'].help_text = "<i>YYYY-MM-DD</i> and <i>HH:MM</i> (24-hour time)"
    self.fields['photo'].widget=ForeignKeyRawIdWidget(Post._meta.get_field("photo").rel,admin.site)
    # add span class to charfields
    for field in self.fields.values():
      if isinstance(field, forms.fields.CharField):
        if 'class' in field.widget.attrs:
          field.widget.attrs['class'] = "%s %s" % (
            field.widget.attrs['class'],
            'span8',
          )
        else:
          field.widget.attrs['class'] = 'span8'
Example #7
0
class WikiForm(ModelForm):
    """
    ---------------------------------------
    功能说明:Wiki分类表单
    ---------------------------------------
    时间:     2015-04-19
    ---------------------------------------
    """
    content = forms.CharField(
        label=u'wiki',
        widget=MarkDownInput(attrs={
            'class': 'form-control',
            'placeholder': u'wiki',
            'required': ''
        }))

    class Meta:
        model = Wiki
        fields = ('content', )
Example #8
0
class JobForm(ModelForm):
    description = forms.CharField(widget=MarkDownInput(attrs={
        'cols': 90,
        'rows': 15
    }))
    onsite_required = forms.BooleanField(initial=True, required=False)
    honeypot    = forms.CharField(required=False,
                                label=_('If you enter anything in this field '\
                                        'your comment will be treated as spam'))

    def clean_honeypot(self):
        """Check that nothing's been entered into the honeypot."""
        value = self.cleaned_data["honeypot"]
        if value:
            raise forms.ValidationError(self.fields["honeypot"].label)
        return value

    class Meta:
        model = Job
        fields = ('title', 'category', 'job_type', 'description',
                  'company_name', 'onsite_required', 'location', 'website',
                  'to_apply')