from __future__ import absolute_import, unicode_literals from django import forms from tagging.forms import TagField from markup_form.forms import make_maprkup_form from pinax.apps.tagging_utils.widgets import TagAutoCompleteInput from pinax.apps.topics.models import Topic class TopicFormBase(forms.ModelForm): tags = TagField(label="Tags", required=False, widget=TagAutoCompleteInput( app_label=Topic._meta.app_label, model=Topic._meta.module_name )) class Meta: model = Topic fields = ["title", "body", "markup", "tags", ] TopicForm = make_maprkup_form( TopicFormBase, {'markup': ['body', ], } )
self.instance.revision_info = { 'comment': self.cleaned_data['comment'], 'editor_ip': self.cleaned_data['user_ip'], 'editor': getattr(self, 'editor', None), } article = super(ArticleFormBase, self).save(commit=False) editor_ip = self.cleaned_data['user_ip'] editor = getattr(self, 'editor', None) group = getattr(self, 'group', None) if not self.instance.pk: article.creator_ip = editor_ip article.group = group if editor is not None: article.creator = editor article.save() self.save_m2m() return article class SearchForm(forms.Form): q = forms.CharField(required=True, label=_('Search')) title_only = forms.BooleanField(required=False, label=_('Title only?')) ArticleForm = make_maprkup_form( ArticleFormBase, {'markup': ['content', 'summary', ], } )
def clean_slug(self): if not self.instance.pk: if Post.objects.filter(author=self.user, created_at__month=datetime.now().month, created_at__year=datetime.now().year, slug=self.cleaned_data["slug"]).exists(): raise forms.ValidationError("This field must be unique for username, year, and month") return self.cleaned_data["slug"] try: post = Post.objects.get( author = self.user, created_at__month = self.instance.created_at.month, created_at__year = self.instance.created_at.year, slug = self.cleaned_data["slug"] ) if post != self.instance: raise forms.ValidationError("This field must be unique for username, year, and month") except Post.DoesNotExist: pass return self.cleaned_data["slug"] BlogForm = make_maprkup_form( BlogFormBase, {'markup': ['body', 'tease', ], } ) class BlogSearchForm(forms.Form): text = forms.CharField( label=_("Search terms"), required=False, )