Mercurial > public > sg101
comparison forums/forms.py @ 722:71d17d267e27
Added an ajax form to upload photos & update post box w/image code.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 21 Sep 2013 17:00:49 -0500 |
parents | 92101013d5ac |
children | 5366c29d6dce |
comparison
equal
deleted
inserted
replaced
721:378b55b81de3 | 722:71d17d267e27 |
---|---|
9 from forums.models import Topic | 9 from forums.models import Topic |
10 from forums.models import Post | 10 from forums.models import Post |
11 from forums.attachments import AttachmentProcessor | 11 from forums.attachments import AttachmentProcessor |
12 import forums.permissions as perms | 12 import forums.permissions as perms |
13 from forums.signals import notify_new_topic, notify_new_post | 13 from forums.signals import notify_new_topic, notify_new_post |
14 | |
15 | |
16 FORUMS_FORM_CSS = { | |
17 'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] + | |
18 settings.GPP_THIRD_PARTY_CSS['jquery-ui']) | |
19 } | |
20 FORUMS_FORM_JS = ( | |
21 settings.GPP_THIRD_PARTY_JS['markitup'] + | |
22 settings.GPP_THIRD_PARTY_JS['jquery-ui'] + | |
23 ['js/jquery.form.min.js', 'js/forums.js'] | |
24 ) | |
14 | 25 |
15 | 26 |
16 class NewPostForm(forms.Form): | 27 class NewPostForm(forms.Form): |
17 """Form for creating a new post.""" | 28 """Form for creating a new post.""" |
18 body = forms.CharField(label='', | 29 body = forms.CharField(label='', |
20 widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) | 31 widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) |
21 topic_id = forms.IntegerField(widget=forms.HiddenInput) | 32 topic_id = forms.IntegerField(widget=forms.HiddenInput) |
22 topic = None | 33 topic = None |
23 | 34 |
24 class Media: | 35 class Media: |
25 css = { | 36 css = FORUMS_FORM_CSS |
26 'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] + | 37 js = FORUMS_FORM_JS |
27 settings.GPP_THIRD_PARTY_CSS['jquery-ui']), | |
28 } | |
29 js = (settings.GPP_THIRD_PARTY_JS['markitup'] + | |
30 settings.GPP_THIRD_PARTY_JS['jquery-ui'] + | |
31 ['js/forums.js']) | |
32 | 38 |
33 def __init__(self, *args, **kwargs): | 39 def __init__(self, *args, **kwargs): |
34 super(NewPostForm, self).__init__(*args, **kwargs) | 40 super(NewPostForm, self).__init__(*args, **kwargs) |
35 attachments = args[0].getlist('attachment') if len(args) else [] | 41 attachments = args[0].getlist('attachment') if len(args) else [] |
36 self.attach_proc = AttachmentProcessor(attachments) | 42 self.attach_proc = AttachmentProcessor(attachments) |
74 user = None | 80 user = None |
75 forum = None | 81 forum = None |
76 has_mod_fields = False | 82 has_mod_fields = False |
77 | 83 |
78 class Media: | 84 class Media: |
79 css = { | 85 css = FORUMS_FORM_CSS |
80 'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] + | 86 js = FORUMS_FORM_JS |
81 settings.GPP_THIRD_PARTY_CSS['jquery-ui']), | |
82 } | |
83 js = (settings.GPP_THIRD_PARTY_JS['markitup'] + | |
84 settings.GPP_THIRD_PARTY_JS['jquery-ui'] + | |
85 ['js/forums.js']) | |
86 | 87 |
87 def __init__(self, user, forum, *args, **kwargs): | 88 def __init__(self, user, forum, *args, **kwargs): |
88 super(NewTopicForm, self).__init__(*args, **kwargs) | 89 super(NewTopicForm, self).__init__(*args, **kwargs) |
89 self.user = user | 90 self.user = user |
90 self.forum = forum | 91 self.forum = forum |
151 class Meta: | 152 class Meta: |
152 model = Post | 153 model = Post |
153 fields = ('body', ) | 154 fields = ('body', ) |
154 | 155 |
155 class Media: | 156 class Media: |
156 css = { | 157 css = FORUMS_FORM_CSS |
157 'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] + | 158 js = FORUMS_FORM_JS |
158 settings.GPP_THIRD_PARTY_CSS['jquery-ui']), | |
159 } | |
160 js = (settings.GPP_THIRD_PARTY_JS['markitup'] + | |
161 settings.GPP_THIRD_PARTY_JS['jquery-ui'] + | |
162 ['js/forums.js']) | |
163 | 159 |
164 def __init__(self, *args, **kwargs): | 160 def __init__(self, *args, **kwargs): |
165 topic_name = kwargs.pop('topic_name', None) | 161 topic_name = kwargs.pop('topic_name', None) |
166 super(PostForm, self).__init__(*args, **kwargs) | 162 super(PostForm, self).__init__(*args, **kwargs) |
167 | 163 |