class PostForm(forms.Form): subject = forms.CharField(label=_(u"Subject")) body = forms.CharField(label=_(u"Body"), widget=forms.Textarea(attrs={'rows': 10, 'cols': 70}), help_text=describe_render_choices(), ) markup = forms.CharField(label=_('Markup'), widget=forms.Select(choices=POST_MARKUP_CHOICES, )) captcha = sphutils.CaptchaField(label=_('Captcha'), widget=sphutils.CaptchaWidget, help_text=_(u'Please enter the result of the above calculation.'), ) def __init__(self, *args, **kwargs): super(PostForm, self).__init__(*args, **kwargs) if not sphutils.has_captcha_support() or get_current_user().is_authenticated: del self.fields['captcha'] if len(POST_MARKUP_CHOICES) == 1: del self.fields['markup'] def init_for_category_type(self, category_type, post): """ Called after initialization with the category type instance. Arguments: category_type: the category_type instance of the category. post: the post which is edited (if any) """ pass
class AnnotateForm(forms.Form): body = forms.CharField(label=_(u'Body'), widget=forms.Textarea(attrs={'rows': 10, 'cols': 80, }, ), help_text=describe_render_choices(), ) markup = forms.CharField(label=_('Markup'), widget=forms.Select(choices=POST_MARKUP_CHOICES, )) hide_post = forms.BooleanField(label=_('Hide Post'), required=False) def __init__(self, *args, **kwargs): super(AnnotateForm, self).__init__(*args, **kwargs) if len(POST_MARKUP_CHOICES) == 1: del self.fields['markup'] def clean(self): if 'markup' not in self.cleaned_data and len(POST_MARKUP_CHOICES): self.cleaned_data['markup'] = POST_MARKUP_CHOICES[0][0] return self.cleaned_data