def POST(self): form = web.input() subject = form['subject'] email_body = form['body'] to = form['to'] receivers = [] if to=="admins": receivers =[u for u in User.selectBy(admin=True, disabled=False)] elif to=="supadmins": receivers=[u for u in User.selectBy(super_admin=True).distinct()] elif to == 'contrib': id_channel=form['select_channel'] c = PluginChannel.get(id_channel) receivers = [u for u in c.get_contribs()] elif to=="channel_editor_users": pc = PluginChannel.select() for elem in pc: if elem.plugin.name=="editor": l1=[u1 for u1 in elem.get_admins()] l2=[u2 for u2 in elem.get_contribs()] list_users = l1+l2 receivers=[u for u in list_users] else: for s in Screen.select(): receivers=[u for u in s.owners] try: for u in receivers: web.sendmail(web.config.smtp_sendername, u.email, subject, email_body, headers={'Content-Type': 'text/html;charset=utf-8'}) except smtplib.SMTPException: logger.error('An error occured when sending email ', exc_info=True) return web.seeother("/")
def _get_screens_number(self): """ Return the number of screens that are subscribed to channels of this plugin. """ plugin_channels = PluginChannel.select().filter( PluginChannel.q.plugin == self) screens = set(plugin_channels.throughTo.subscriptions.throughTo.screen. distinct()) bundles = set(c for c in ChannelBundle.select() if any(bc.plugin == self for bc in c.flatten())) for b in bundles: screens |= set(Subscription.select().filter( Subscription.q.channel == b).throughTo.screen.distinct()) return len(screens)
def post(self): form = self.form subject = form['subject'] email_body = form['body'] to = form['to'] receivers = [] if to == "admins": receivers = [u for u in User.selectBy(admin=True, disabled=False)] elif to == "supadmins": receivers = [u for u in User.selectBy(super_admin=True).distinct()] elif to == 'contrib': id_channel = form['select_channel'] c = PluginChannel.get(id_channel) receivers = [u for u in c.get_contribs()] elif to == "channel_editor_users": pc = PluginChannel.select() for elem in pc: if elem.plugin.name == "editor": l1 = [u1 for u1 in elem.get_admins()] l2 = [u2 for u2 in elem.get_contribs()] list_users = l1 + l2 receivers = [u for u in list_users] else: for s in Screen.select(): receivers = [u for u in s.owners] try: mail = Mail(self.app) msg = Message( recipients=[u.email for u in receivers], subject=subject, body=email_body, extra_headers={'Content-Type': 'text/html;charset=utf-8'}) mail.send(msg) except smtplib.SMTPException: logger.error('An error occured when sending email ', exc_info=True) resp.seeother("/")