Changeset 2009
- Timestamp:
- 02/18/07 14:48:22 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
discussionplugin/0.10/tracdiscussion/api.py
r1987 r2009 500 500 # Get new popic and notify about creation. 501 501 new_topic = self.get_topic_by_time(cursor, new_time) 502 new_topic['moderators'] = ' '.join(forum['moderators']) 502 to = self.get_topic_to_recipients(cursor, topic['id']) 503 cc = self.get_topic_cc_recipients(cursor, topic['id']) 503 504 notifier = DiscussionNotifyEmail(self.env) 504 notifier.notify(req, cursor, mode, new_topic) 505 notifier.notify(req, cursor, mode, forum, new_topic, None, to, 506 cc) 505 507 506 508 elif mode == 'topic-edit': … … 629 631 # Get inserted message and notify about its creation. 630 632 new_message = self.get_message_by_time(cursor, new_time) 631 new_message['subject'] = topic['subject']632 new_message['moderators'] = ' '.join(forum['moderators'])633 to = self.get_topic_to_recipients(cursor, topic['id']) 634 cc = self.get_topic_cc_recipients(cursor, topic['id']) 633 635 notifier = DiscussionNotifyEmail(self.env) 634 notifier.notify(req, cursor, mode, new_message) 636 notifier.notify(req, cursor, mode, forum, topic, new_message, 637 to, cc) 635 638 636 639 elif mode == 'message-edit': … … 728 731 return row 729 732 return None 733 734 def get_topic_to_recipients(self, cursor, id): 735 sql = "SELECT t.author FROM topic t WHERE t.id = %s UNION SELECT" \ 736 " m.author FROM message m WHERE m.topic = %s" 737 self.log.debug(sql % (id, id)) 738 cursor.execute(sql, (id, id)) 739 to_recipients = [] 740 for row in cursor: 741 to_recipients.append(row[0]) 742 self.log.debug(to_recipients) 743 return to_recipients 744 745 def get_topic_cc_recipients(self, cursor, id): 746 return [] 730 747 731 748 def get_forum(self, cursor, id): … … 873 890 return forums 874 891 875 def get_topics(self, req, cursor, forum , order_by = 'time', desc = False):892 def get_topics(self, req, cursor, forum_id, order_by = 'time', desc = False): 876 893 if not order_by in ('replies', 'lastreply',): 877 894 order_by = 't.' + order_by … … 883 900 " topic) m ON t.id = m.topic WHERE t.forum = %s ORDER BY " \ 884 901 + order_by + (" ASC", " DESC")[bool(desc)] 885 self.log.debug(sql % (forum ,))886 cursor.execute(sql, (forum ,))902 self.log.debug(sql % (forum_id,)) 903 cursor.execute(sql, (forum_id,)) 887 904 topics = [] 888 905 for row in cursor: … … 900 917 return topics 901 918 902 def get_messages(self, req, cursor, topic , time, order_by = 'time', desc = False):919 def get_messages(self, req, cursor, topic_id, time, order_by = 'time', desc = False): 903 920 order_by = 'm.' + order_by 904 921 columns = ('id', 'replyto', 'time', 'author', 'body') 905 922 sql = "SELECT m.id, m.replyto, m.time, m.author, m.body FROM message m WHERE" \ 906 923 " m.topic = %s ORDER BY " + order_by + (" ASC", " DESC")[bool(desc)] 907 self.log.debug(sql % (topic ,))908 cursor.execute(sql, (topic ,))924 self.log.debug(sql % (topic_id,)) 925 cursor.execute(sql, (topic_id,)) 909 926 messagemap = {} 910 927 messages = [] … … 932 949 return messages; 933 950 934 def get_flat_messages(self, req, cursor, topic , time, order_by =951 def get_flat_messages(self, req, cursor, topic_id, time, order_by = 935 952 'ORDER BY time ASC'): 936 953 columns = ('id', 'replyto', 'time', 'author', 'body') 937 954 sql = "SELECT m.id, m.replyto, m.time, m.author, m.body FROM message m" \ 938 955 " WHERE m.topic = %s " + order_by 939 self.log.debug(sql % (topic ,))940 cursor.execute(sql, (topic ,))956 self.log.debug(sql % (topic_id,)) 957 cursor.execute(sql, (topic_id,)) 941 958 messages = [] 942 959 for row in cursor: discussionplugin/0.10/tracdiscussion/notification.py
r1987 r2009 8 8 9 9 template_name = "discussion-notify-body.cs" 10 forum = None 11 topic = None 12 message = None 13 torcpts = [] 14 ccrcpts = [] 10 15 COLS = 75 11 16 … … 13 18 NotifyEmail.__init__(self, env) 14 19 15 def notify(self, req, cursor, action, object): 20 def notify(self, req, cursor, action, forum = None, topic = None, 21 message = None, torcpts = [], ccrcpts = []): 16 22 self.env.log.debug("action: %s" % action) 17 self.env.log.debug("object: %s" % object) 23 self.env.log.debug("forum: %s" % forum) 24 self.env.log.debug("topic: %s" % topic) 25 self.env.log.debug("message: %s" % message) 26 self.env.log.debug("torcpts: %s" % torcpts) 27 self.env.log.debug("ccrcpts: %s" % ccrcpts) 18 28 19 # Prepare action specific email content. 20 if action == 'topic-post-add': 29 # Store link to currently notifying forum, topic and message. 30 self.forum = forum 31 self.topic = topic 32 self.message = message 33 self.torcpts = torcpts 34 self.ccrcpts = ccrcpts 35 36 # Get action and item of action. 37 index = action.find('-') 38 item = action[:index] 39 action = action[index + 1:] 40 41 # Which item notify about: 42 if item == 'topic': 43 # Prepare topic specific fields. 44 re = '' 21 45 title = 'Topic' 22 re = '' 23 link = req.abs_href.discussion(object['forum'], object['id']) 24 elif action == 'topic-post-edit': 25 title = 'Topic' 26 re = '' 27 link = req.abs_href.discussion(object['forum'], object['id']) 28 elif action == 'message-post-add': 46 id = self.topic['id'] 47 author = " Author: %s" % self.topic['author'] 48 time = " Time: %s" % format_datetime(self.topic['time']) 49 body = self.topic['body'] 50 link = req.abs_href.discussion(self.forum['id'], self.topic['id']) 51 52 # Save link for bad times. 53 topic['link'] = link 54 elif item == 'message': 55 # Prepare message specific fields 56 re = 'Re: ' 29 57 title = 'Message' 30 re = 'Re: ' 31 link = req.abs_href.discussion(object['forum'], object['topic'], 32 object['id']) + '#%s' % object['id'] 33 elif action == 'message-post-edit': 34 title = 'Message' 35 re = 'Re: ' 36 link = req.abs_href.discussion(object['forum'], object['topic'], 37 object['id']) + '#%s' % object['id'] 58 id = self.message['id'] 59 author = " Author: %s" % self.message['author'] 60 time = " Time: %s" % format_datetime(self.message['time']) 61 body = self.message['body'] 62 link = req.abs_href.discussion(self.forum['id'], self.topic['id'], 63 self.message['id']) + '#%s' % self.message['id'] 38 64 39 # Format body table items. 40 author = " Author: %s" % object['author'] 41 time = " Time: %s" % format_datetime(object['time']) 42 moderators = "Moderators: %s" % object['moderators'] 65 # Save link for bad times. 66 message['link'] = link 67 else: 68 return 69 70 prefix = self.config.get('notification', 'smtp_subject_prefix') 71 if prefix == '__default__': 72 prefix = self.env.project_name 73 moderators = "Moderators: %s" % ' '.join(self.forum['moderators']) 74 subject = self.topic['subject'] 43 75 44 76 # Set set e-mail template values. 45 77 self.hdf.set_unescaped('discussion.re', re) 46 prefix = self.config.get('notification', 'smtp_subject_prefix') 47 if prefix != '__default__': 48 self.hdf.set_unescaped('discussion.prefix', prefix) 78 self.hdf.set_unescaped('discussion.prefix', prefix) 49 79 self.hdf.set_unescaped('discussion.title', title) 50 self.hdf.set_unescaped('discussion.id', object['id'])80 self.hdf.set_unescaped('discussion.id', id) 51 81 self.hdf.set_unescaped('discussion.author', author) 82 self.hdf.set_unescaped('discussion.time', time) 52 83 self.hdf.set_unescaped('discussion.moderators', moderators) 53 self.hdf.set_unescaped('discussion.time', time) 54 self.hdf.set_unescaped('discussion.subject', object['subject']) 55 self.hdf.set_unescaped('discussion.body', object['body']) 84 self.hdf.set_unescaped('discussion.subject', subject) 85 self.hdf.set_unescaped('discussion.body', body) 56 86 self.hdf.set_unescaped('discussion.link', link) 57 87 … … 59 89 subject = self.hdf.render('discussion-notify-subject.cs') 60 90 self.env.log.debug(subject) 61 NotifyEmail.notify(self, object['id'], subject) 91 NotifyEmail.notify(self, id, subject) 92 93 def get_topic_id(self, forum_id, topic_id): 94 return "%s-%s-%s" % (forum_id, topic_id, 0) 95 96 def get_message_id(self, forum_id, topic_id, message_id): 97 return "%s-%s-%s" % (forum_id, topic_id, message_id) 62 98 63 99 def get_recipients(self, resid): 64 return ([], []) 100 return (self.torcpts, self.ccrcpts) 101 102 def send(self, torcpts, ccrcpts): 103 header = {} 104 105 # Add item specific e-mail header fields. 106 if self.message: 107 # Get this messge ID. 108 header['Message-ID'] = self.get_message_id(self.forum['id'], 109 self.topic['id'], self.message['id']) 110 header['X-Trac-Message-ID'] = str(self.message['id']) 111 header['X-Trac-Discussion-URL'] = self.message['link'] 112 113 # Get replied message ID. 114 if self.message['replyto'] == -1: 115 reply_id = self.get_topic_id(self.forum['id'], 116 self.topic['id']) 117 else: 118 reply_id = self.get_message_id(self.forum['id'], 119 self.topic['id'], self.message['replyto']) 120 header['In-Reply-To'] = reply_id 121 header['References'] = reply_id 122 else: 123 # Get this message ID. 124 header['Message-ID'] = self.get_topic_id(self.forum['id'], 125 self.topic['id']) 126 header['X-Trac-Topic-ID'] = str(self.topic['id']) 127 header['X-Trac-Discussion-URL'] = self.topic['link'] 128 129 # Send e-mail. 130 NotifyEmail.send(self, torcpts, ccrcpts, header) discussionplugin/0.10/tracdiscussion/templates/discussion-notify-subject.cs
r1987 r2009 1 <?cs var:discussion.re ?><?cs alt:discussion.prefix ?>[<?cs var:project.name ?>]<?cs /alt?> <?cs var:discussion.title ?> #<?cs var:discussion.id ?> - <?cs var:discussion.subject ?>1 <?cs var:discussion.re ?><?cs var:discussion.prefix ?> <?cs var:discussion.title ?> #<?cs var:discussion.id ?> - <?cs var:discussion.subject ?>
