~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to pybb/forms.py

  • Committer: franku
  • Date: 2016-07-02 12:38:06 UTC
  • mfrom: (404.2.56 widelands)
  • Revision ID: somal@arcor.de-20160702123806-q69u3d48s1prrxds
merged the django1_8 branch

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 notification.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
        
 
31
        # NOCOMM: This doesn't work anymore with django 1.8 Use 'field_order' with django 1.9
30
32
        self.fields.keyOrder = ['name', 
31
33
                                'body', 
32
34
                                'markup', 
64
66
        post = Post(topic=topic, user=self.user, user_ip=self.ip,
65
67
                    markup=self.cleaned_data['markup'],
66
68
                    body=self.cleaned_data['body'])
 
69
 
67
70
        post.save(*args, **kwargs)
68
71
 
69
72
        if pybb_settings.ATTACHMENT_ENABLE:
70
73
            self.save_attachment(post, self.cleaned_data['attachment'])
71
74
 
72
75
        if topic_is_new:
73
 
            notification.send(User.objects.all(), "forum_new_topic",
 
76
            send(User.objects.all(), "forum_new_topic",
74
77
                {'topic': topic, 'post':post, 'user':topic.user})
75
78
        else:
76
 
            notification.send(self.topic.subscribers.all(), "forum_new_post",
 
79
            send(self.topic.subscribers.all(), "forum_new_post",
77
80
                {'post':post, 'topic':topic, 'user':post.user})
78
81
        return post
79
82