1. Curtis Maloney
  2. gnocchi-blog

Source

gnocchi-blog / gnocchi / blog / forms.py

from django import forms
from gnocchi.blog import models, recaptcha
from taggit.models import TaggedItem
import re

class PostAdminForm(forms.ModelForm):
    auto = forms.BooleanField(label='Auto-tag?', required=False, initial=True,
        help_text="Automatically scan content for tags"
    )
    class Meta:
        model = models.Post
    def clean(self):
        data = self.cleaned_data
        if data['auto']:
            words = set([word.strip() for word in data['content'].split()])
            words = set([word.lower() for word in words])
            tags = set(data['tags'])
            tags.update([
                tag
                for tag in TaggedItem.tags_for(models.Post)
                if tag.name in words
            ])
            data['tags'] = list(tags)
        return data

class CommentForm(recaptcha.BaseRecaptchaForm, forms.ModelForm):
    captcha = recaptcha.RecaptchaField()
    class Meta:
        model = models.Comment
        fields = (
            'user_name',
            'user_email',
            'content',
        )