comparison messages/forms.py @ 804:95b3d59913ad

Private messages refactoring: compose functionality.
author Brian Neal <bgneal@gmail.com>
date Sun, 31 Aug 2014 13:51:06 -0500
parents 9aae4f99f062
children 0f0ba45704b7
comparison
equal deleted inserted replaced
803:b3eeaefc39a8 804:95b3d59913ad
1 """ 1 """
2 Forms for the messages application. 2 Forms for the messages application.
3
3 """ 4 """
4
5 from django import forms 5 from django import forms
6 from django.contrib.auth.models import User 6 from django.contrib.auth.models import User
7 from django.conf import settings 7 from django.conf import settings
8 from django.contrib.sites.models import Site 8 from django.contrib.sites.models import Site
9 from django.core.urlresolvers import reverse 9 from django.core.urlresolvers import reverse
28 max_length=30, 28 max_length=30,
29 widget=AutoCompleteUserInput()) 29 widget=AutoCompleteUserInput())
30 subject = forms.CharField(max_length=120, widget=forms.TextInput(attrs={'size': 52})) 30 subject = forms.CharField(max_length=120, widget=forms.TextInput(attrs={'size': 52}))
31 message = forms.CharField(widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) 31 message = forms.CharField(widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'}))
32 attach_signature = forms.BooleanField(label='Attach Signature?', required=False) 32 attach_signature = forms.BooleanField(label='Attach Signature?', required=False)
33 parent_id = forms.IntegerField(required=False, widget=forms.HiddenInput)
33 34
34 def __init__(self, user, *args, **kwargs): 35 def __init__(self, user, *args, **kwargs):
35 forms.Form.__init__(self, *args, **kwargs) 36 forms.Form.__init__(self, *args, **kwargs)
36 self.user = user 37 self.user = user
37 options = Options.objects.for_user(user) 38 options = Options.objects.for_user(user)
88 subject=subject, 89 subject=subject,
89 message=message, 90 message=message,
90 signature_attached=attach_signature, 91 signature_attached=attach_signature,
91 ) 92 )
92 new_msg.save() 93 new_msg.save()
93 if parent_msg is not None:
94 parent_msg.reply_date = new_msg.send_date
95 parent_msg.save()
96 94
95 # Update the parent message (if there is one)
96 parent_id = self.cleaned_data['parent_id']
97 if parent_id:
98 try:
99 parent_msg = Message.objects.get(pk=parent_id)
100 except Message.DoesNotExist:
101 parent_msg = None
102
103 if parent_msg and parent_msg.receiver == self.user:
104 parent_msg.reply_date = new_msg.send_date
105 parent_msg.save()
106
107 # Notify recipient
97 receiver_opts = Options.objects.for_user(receiver) 108 receiver_opts = Options.objects.for_user(receiver)
98 if receiver_opts.notify_email: 109 if receiver_opts.notify_email:
99 notify_receiver(new_msg) 110 notify_receiver(new_msg)
100 111
101 class Media: 112 class Media: