~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to pybb/forms.py

  • Committer: franku
  • Date: 2016-05-15 14:41:54 UTC
  • mto: This revision was merged to the branch mainline in revision 409.
  • Revision ID: somal@arcor.de-20160515144154-00m3tiibyxm0nw2w
added the old threadedcomments app as wildelands app

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
from pybb.models import Topic, Post, PrivateMessage, Attachment
11
11
from pybb import settings as pybb_settings
12
12
 
13
 
from notification import models as notification
 
13
#from pinax.notifications.models import send
14
14
 
15
15
class AddPostForm(forms.ModelForm):
16
16
    name = forms.CharField(label=_('Subject'))
18
18
 
19
19
    class Meta:
20
20
        model = Post
21
 
        fields = ['body', 'markup',]
 
21
        # Listing fields again to get the the right order; See also the NOCOMM
 
22
        fields = ['name','body', 'markup', 'attachment',]
22
23
 
23
24
    def __init__(self, *args, **kwargs):
24
25
        self.user = kwargs.pop('user', None)
26
27
        self.forum = kwargs.pop('forum', None)
27
28
        self.ip = kwargs.pop('ip', None)
28
29
        super(AddPostForm, self).__init__(*args, **kwargs)
29
 
 
30
 
        self.fields.keyOrder = ['name', 'body', 'markup', 'attachment']
 
30
        
 
31
        # NOCOMM: This doesn't work anymore with django 1.8 Use 'field_order' with django 1.9
 
32
        self.fields.keyOrder = ['name', 
 
33
                                'body', 
 
34
                                'markup', 
 
35
                                'attachment']
31
36
 
32
37
        if self.topic:
33
38
            self.fields['name'].widget = forms.HiddenInput()
49
54
 
50
55
    def save(self, *args, **kwargs):
51
56
        if self.forum:
52
 
            topic_is_new = True
 
57
            topic_is_new = True
53
58
            topic = Topic(forum=self.forum,
54
59
                          user=self.user,
55
60
                          name=self.cleaned_data['name'])
66
71
        if pybb_settings.ATTACHMENT_ENABLE:
67
72
            self.save_attachment(post, self.cleaned_data['attachment'])
68
73
 
69
 
        if topic_is_new:
70
 
            notification.send(User.objects.all(), "forum_new_topic",
71
 
                {'topic': topic, 'post':post, 'user':topic.user})
72
 
        else:
73
 
            notification.send(self.topic.subscribers.all(), "forum_new_post",
74
 
                {'post':post, 'topic':topic, 'user':post.user})
 
74
        #NOCOMM franku: notifications do not work
 
75
        # if topic_is_new:
 
76
        #     send(User.objects.all(), "forum_new_topic",
 
77
        #         {'topic': topic, 'post':post, 'user':topic.user})
 
78
        # else:
 
79
        #     send(self.topic.subscribers.all(), "forum_new_post",
 
80
        #         {'post':post, 'topic':topic, 'user':post.user})
75
81
        return post
76
82
 
77
83
 
91
97
class EditPostForm(forms.ModelForm):
92
98
    class Meta:
93
99
        model = Post
94
 
        fields = ['body']
 
100
        fields = ['body', 'markup']
95
101
 
96
102
    def save(self, *args, **kwargs):
97
103
        post = super(EditPostForm, self).save(commit=False)