Mercurial > public > sg101
diff gpp/forums/forms.py @ 285:8fd4984d5c3b
This is a first rough commit for #95, adding the ability to embed YouTube videos in forum posts. Some more polish and testing needs to happen at this point. I wanted to get all these changes off my hard drive and into the repository.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 14 Oct 2010 02:39:35 +0000 |
parents | 13330e1836f3 |
children | 72fd300685d5 |
line wrap: on
line diff
--- a/gpp/forums/forms.py Mon Oct 04 01:01:29 2010 +0000 +++ b/gpp/forums/forms.py Thu Oct 14 02:39:35 2010 +0000 @@ -7,6 +7,7 @@ from forums.models import Forum from forums.models import Topic from forums.models import Post +from forums.attachments import AttachmentProcessor class NewPostForm(forms.Form): @@ -25,6 +26,11 @@ settings.GPP_THIRD_PARTY_JS['jquery-ui'] + ('js/forums.js', )) + def __init__(self, *args, **kwargs): + super(NewPostForm, self).__init__(*args, **kwargs) + attachments = args[0].getlist('attachment') if len(args) else [] + self.attach_proc = AttachmentProcessor(attachments) + def clean_topic_id(self): id = self.cleaned_data['topic_id'] try: @@ -40,6 +46,7 @@ post = Post(topic=self.topic, user=user, body=self.cleaned_data['body'], user_ip=ip) post.save() + self.attach_proc.save_attachments(post) return post @@ -76,6 +83,9 @@ self.fields['locked'] = forms.BooleanField(required=False) self.has_mod_fields = True + attachments = args[0].getlist('attachment') if len(args) else [] + self.attach_proc = AttachmentProcessor(attachments) + def save(self, ip=None): """ Creates the new Topic and first Post from the form data and supplied @@ -93,6 +103,9 @@ body=self.cleaned_data['body'], user_ip=ip) post.save() + + self.attach_proc.save_attachments(post) + return topic