~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to pybb/forms.py

  • Committer: Holger Rapp
  • Date: 2012-03-17 16:22:06 UTC
  • Revision ID: sirver@gmx.de-20120317162206-fgttamk22qt1nytj
Let post count be calculated automatically instead of keeping track of it manually. Let's see how this affects performance

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 pinax.notifications.models import send
 
13
from notification import models as notification
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
 
        # Listing fields again to get the the right order; See also the NOCOMM
22
 
        fields = ['name','body', 'markup', 'attachment',]
 
21
        fields = ['body', 'markup',]
23
22
 
24
23
    def __init__(self, *args, **kwargs):
25
24
        self.user = kwargs.pop('user', None)
27
26
        self.forum = kwargs.pop('forum', None)
28
27
        self.ip = kwargs.pop('ip', None)
29
28
        super(AddPostForm, self).__init__(*args, **kwargs)
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']
 
29
 
 
30
        self.fields.keyOrder = ['name', 'body', 'markup', 'attachment']
36
31
 
37
32
        if self.topic:
38
33
            self.fields['name'].widget = forms.HiddenInput()
54
49
 
55
50
    def save(self, *args, **kwargs):
56
51
        if self.forum:
57
 
            topic_is_new = True
 
52
            topic_is_new = True
58
53
            topic = Topic(forum=self.forum,
59
54
                          user=self.user,
60
55
                          name=self.cleaned_data['name'])
71
66
        if pybb_settings.ATTACHMENT_ENABLE:
72
67
            self.save_attachment(post, self.cleaned_data['attachment'])
73
68
 
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})
 
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})
81
75
        return post
82
76
 
83
77
 
97
91
class EditPostForm(forms.ModelForm):
98
92
    class Meta:
99
93
        model = Post
100
 
        fields = ['body', 'markup']
 
94
        fields = ['body']
101
95
 
102
96
    def save(self, *args, **kwargs):
103
97
        post = super(EditPostForm, self).save(commit=False)