Commits

funkybob  committed 833d8c7

add auto-tagging to post form

  • Participants
  • Parent commits 38e0d9c

Comments (0)

Files changed (1)

File flat_forum/forms.py

 from flat_forum import models
 
 class PostForm(forms.ModelForm):
+
+    def clean(self):
+        '''Auto-tag'''
+        data = self.cleaned_data
+        tags = set([ tag.lower() for tag in data['tags'] ])
+        tags.update([
+            tag
+            for tag in TaggedItem.tags_for(models.Post)
+            if re.search(r'\b%s\b' % tag.name, data['content'], re.I|re.M)
+        ])
+        data['tags'] = list(tags)
+        return data
     class Meta:
         model = models.Post
         exclude = ['reply_to', 'posted_by', 'created',]