577 eid_from = self._cw.execute('INSERT %s T : T name "%s"' % ( etype_from, value_from ))[0][0] |
577 eid_from = self._cw.execute('INSERT %s T : T name "%s"' % ( etype_from, value_from ))[0][0] |
578 # link the new entity to the main entity |
578 # link the new entity to the main entity |
579 rql = 'SET F %(rel)s T WHERE F eid %(eid_to)s, T eid %(eid_from)s' % {'rel' : rel, 'eid_to' : eid_to, 'eid_from' : eid_from} |
579 rql = 'SET F %(rel)s T WHERE F eid %(eid_to)s, T eid %(eid_from)s' % {'rel' : rel, 'eid_to' : eid_to, 'eid_from' : eid_from} |
580 return eid_from |
580 return eid_from |
581 |
581 |
582 |
582 # XXX move to massmailing |
583 class SendMailController(Controller): |
583 class SendMailController(Controller): |
584 __regid__ = 'sendmail' |
584 __regid__ = 'sendmail' |
585 __select__ = authenticated_user() & match_form_params('recipient', 'mailbody', 'subject') |
585 __select__ = authenticated_user() & match_form_params('recipient', 'mailbody', 'subject') |
586 |
586 |
587 def recipients(self): |
587 def recipients(self): |
588 """returns an iterator on email's recipients as entities""" |
588 """returns an iterator on email's recipients as entities""" |
589 eids = self._cw.form['recipient'] |
589 eids = self._cw.form['recipient'] |
590 # make sure we have a list even though only one recipient was specified |
590 # eids may be a string if only one recipient was specified |
591 if isinstance(eids, basestring): |
591 if isinstance(eids, basestring): |
592 eids = (eids,) |
592 rset = self._cw.execute('Any X WHERE X eid %(x)s', {'x': eids}) |
593 rql = 'Any X WHERE X eid in (%s)' % (','.join(eids)) |
593 else: |
594 rset = self._cw.execute(rql) |
594 rset = self._cw.execute('Any X WHERE X eid in (%s)' % (','.join(eids))) |
595 for entity in rset.entities(): |
595 return rset.entities() |
596 yield entity |
|
597 |
596 |
598 def sendmail(self, recipient, subject, body): |
597 def sendmail(self, recipient, subject, body): |
599 msg = format_mail({'email' : self._cw.user.get_email(), |
598 msg = format_mail({'email' : self._cw.user.get_email(), |
600 'name' : self._cw.user.dc_title(),}, |
599 'name' : self._cw.user.dc_title(),}, |
601 [recipient], body, subject) |
600 [recipient], body, subject) |
610 body = self._cw.form['mailbody'] |
609 body = self._cw.form['mailbody'] |
611 subject = self._cw.form['subject'] |
610 subject = self._cw.form['subject'] |
612 for recipient in self.recipients(): |
611 for recipient in self.recipients(): |
613 text = body % recipient.as_email_context() |
612 text = body % recipient.as_email_context() |
614 self.sendmail(recipient.get_email(), subject, text) |
613 self.sendmail(recipient.get_email(), subject, text) |
615 # breadcrumbs = self._cw.get_session_data('breadcrumbs', None) |
|
616 url = self._cw.build_url(__message=self._cw._('emails successfully sent')) |
614 url = self._cw.build_url(__message=self._cw._('emails successfully sent')) |
617 raise Redirect(url) |
615 raise Redirect(url) |
618 |
616 |
619 |
617 |
620 class MailBugReportController(SendMailController): |
618 class MailBugReportController(SendMailController): |