def mailinglist_reply(self, group_id, thread_id): try: group = Group.get(int(group_id)) thread_id = int(thread_id) except ValueError: abort(404) thread = GroupMailingListMessage.get(thread_id, group.id) if group is None or thread is None: abort(404) last_post = thread.posts[-1] msg = post_message(group, c.user, u"Re: %s" % thread.subject, self.form_result['message'], reply_to=last_post.message_id) if request.params.has_key('js'): return render_mako_def('/sections/wall_entries.mako', 'thread_reply', id=msg.id, author_id=msg.author_id if msg.author_id is not None else msg.author_or_anonymous, message=msg.body, created_on=msg.sent, attachments=msg.attachments, allow_comment_deletion=False) else: self._redirect()
def post_anonymous(self, group): post = post_message(group, c.user, self.form_result['subject'], self.form_result['message']) h.flash(_('Your message to the group was successfully sent.')) redirect(group.url())
def post(self, group): post = post_message(group, c.user, self.form_result['subject'], self.form_result['message']) redirect(url(controller='home', action='feed'))
def _send_message(self, group, subject, message, category_id=None): if not group.mailinglist_enabled: if category_id is None: category_id = group.forum_categories[0].id post = ForumPost(subject, message, category_id=category_id, thread_id=None) meta.Session.add(post) meta.Session.commit() evt = meta.Session.query(ForumPostCreatedEvent).filter_by(post_id=post.id).one().wall_entry() return evt else: post = post_message(group, c.user, subject, message) evt = meta.Session.query(MailinglistPostCreatedEvent).filter_by(message_id=post.id).one().wall_entry() return evt
def studentgroup_send_message(self, group): if hasattr(self, 'form_result'): subject = self.form_result['subject'] message = self.form_result['message'] #wrap the message with additional information msg_text = render('/emails/teacher_message.mako', extra_vars={'teacher':c.user, 'subject':subject, 'message':message}) if group.group is not None: recipient = group.group if recipient.mailinglist_enabled: attachments = [] if self.form_result['file'] != '': file = self.form_result['file'] f = File(file.filename, file.filename, mimetype=file.type) f.store(file.file) meta.Session.add(f) meta.Session.commit() attachments.append(f) post_message(recipient, c.user, subject, msg_text, force=True, attachments=attachments) else: attachments = [] if self.form_result['file'] != '': attachments = [{'filename': self.form_result['file'].filename, 'file': self.form_result['file'].file}] msg = EmailMessage(_('Message from %(teacher_name)s: %(subject)s') % { 'subject': subject, 'teacher_name': c.user.fullname}, msg_text, sender=recipient.list_address, attachments=attachments) msg.send(group.group) evt = TeacherMessageEvent() evt.context = group.group evt.data = '%s \n\n %s' % (subject, msg_text) evt.user = c.user meta.Session.add(evt) meta.Session.commit() else: attachments = [] if self.form_result['file'] != '': attachments = [{'filename': self.form_result['file'].filename, 'file': self.form_result['file'].file}] msg = EmailMessage(subject, msg_text, sender=c.user.email.email, force=True, attachments=attachments) msg.send(group.email) message = _(u'Message sent to %(group_title)s (%(group_email)s).') % { 'group_title': group.title, 'group_email': group.email} h.flash(message) redirect(url(controller='profile', action='dashboard'))