def sendMessages(self, tmplid, tmplData, whoTo, subject): """ Same as above however sends the message to multiple people Finds the given template id in the database, renders it into HTML via markdown, then runs mustache to fill in template data. Finally, the rendered and compiled template is put into an email package and sent via email to the person given by `whoTo` :param tmplid: The document id of the template for which to use for the email :param tmplData: The data which should be placed into the template with mustache Should be in a dict whos keys are the emails in `whoTo` and the values are the data :param whoTo: The email address of the person who this email should go to should be a list :param subject: The subject of the email """ tmplObj = tm.templateORM.getByID(tmplid) tmpl = tmplObj.template for person in whoTo: msg = self.makeMessage(subject, person, tmpl, tmplData[person]) logger.debug("Sending message...") if sm.getSetting("emailServer", "sendEmail"): try: self.s.sendmail("fla.gr", [person], msg.as_string()) except: self.s.connect() self.s.sendmail("fla.gr", [person], msg.as_string())
def POST(self): name = self.env["members"]["name"] if self.env["members"].has_key("name") else "" description = self.env["members"]["description"] if self.env["members"].has_key("description") else "" template = self.env["members"]["template"] if self.env["members"].has_key("template") else "" tmplType = self.env["members"]["type"] if self.env["members"].has_key("type") else "" tmplid = self.env["members"][0] tmpl = tm.templateORM.getByID(tmplid) tmpl.description = description tmpl.template = template tmpl.type = tmplType if not name: try: currentTypes = sm.getSetting("templates", "types") except: currentTypes = {"Set template types in settings"} view = adminEditTemplatesTmpl(searchList=[self.tmplSearchList]) view.nameError = True view.templateTypes = currentTypes view.tmpl = tmpl return view tmpl.name = name tmpl.created = datetime.now() tmpl.save() self.head = ("303 SEE OTHER", [("location", "/admin/templates/view/%s"%tmplid)]) self.session.pushAlert("We've updated this template!", "Congrats", "success")
def POST(self): name = self.env["members"]["name"] if self.env["members"].has_key("name") else "" description = self.env["members"]["description"] if self.env["members"].has_key("description") else "" template = self.env["members"]["template"] if self.env["members"].has_key("template") else "" tmplType = self.env["members"]["type"] if self.env["members"].has_key("type") else "" if not name: view = adminNewTemplatesTmpl(searchList=[self.tmplSearchList]) view.nameError = True view.description = description view.template = template try: currentTypes = sm.getSetting("templates", "types") except: currentTypes = {"Set template types in settings"} view.templateTypes = currentTypes return view tmpl = tm.templateORM(name=name, description=description, template=template, type=tmplType) tmpl.save() self.head = ("303 SEE OTHER", [("location", "/admin/templates/view/%s"%tmpl.id)]) self.session.pushAlert("We've created this template with the info you gave us!", "Congrats", "success")
def GET(self): """ """ page = self.env["members"]["p"] \ if self.env["members"].has_key("p") else 1 view = adminViewTemplatesTmpl(searchList=[self.tmplSearchList]) view.scripts = ["handlebars_1.0.min", "jquery.json-2.4.min", "sidebarTabs.flagr", "bulkCheck.flagr", "adminModal.flagr", "editForm.flagr", "adminViewTemplates.flagr", "dynamicInput.flagr"] templates = bcc.baseCouchCollection(tm.templateORM) templates.paginate(page, 25) templates.fetch() templates.format() view.templates = templates try: view.templateTypes = json.dumps(list(sm.getSetting("templates", "types"))) except: view.templateTypes = json.dumps([]) return view
def setup(self): if sm.getSetting("emailServer", "notLocalhost"): logger.debug("Email server not localhost, attempting to login") self.s = smtplib.SMTP(sm.getSetting("emailServer", "host"), int(sm.getSetting("emailServer", "port"))) self.s.ehlo() self.s.starttls() self.s.ehlo() try: self.s.login(sm.getSetting("emailServer", "loginEmail"), sm.getSetting("emailServer", "loginPassword")) except Exception as exc: logger.critical("Could not login to email server!") logger.debug(exc) else: try: self.s = smtplib.SMTP('localhost') except Exception as exc: logger.critical("Could not connect to localhost email server!") logger.debug(exc) logger.debug("Connected to email server...")
def GET(self): """ """ view = adminNewTemplatesTmpl(searchList=[self.tmplSearchList]) try: currentTypes = sm.getSetting("templates", "types") except: currentTypes = {"Set template types in settings"} view.templateTypes = currentTypes return view
def GET(self): """ """ tmplid = self.env["members"][0] view = adminEditTemplatesTmpl(searchList=[self.tmplSearchList]) template = tm.templateORM.getByID(tmplid) try: currentTypes = sm.getSetting("templates", "types") except: currentTypes = {"Set template types in settings"} view.templateTypes = currentTypes view.tmpl = template return view
def GET(self): """ """ if self.env["cfg"].enableRequests: page = self.env["members"]["p"] \ if self.env["members"].has_key("p") else 1 view = adminViewRequestsTmpl(searchList=[self.tmplSearchList]) view.scripts = ["handlebars_1.0.min", "jquery.json-2.4.min", "sidebarTabs.flagr", "adminModal.flagr", "bulkCheck.flagr", "editForm.flagr", "adminViewRequests.flagr"] requests = bcc.baseCouchCollection(rm.requestORM) requests.paginate(page, 25) requests.fetch() requests.format() view.requests = requests try: currentTmpl = sm.getSetting("enableRequests", "tmplid") except: currentTmpl = "" tmpl = bcc.baseCouchCollection(tm.templateORM) tmpl.fetch() tmpl.filterBy("type", "email") for tmp in tmpl: if tmp.id == currentTmpl: tmp.current = True view.tmpls = tmpl return view else: self._404()
def POST(self): if self.env["cfg"].enableRequests: ids = json.loads(self.env["members"]["array"]) \ if self.env["members"].has_key("array") else [] try: tmplID = sm.getSetting("enableRequests", "tmplid") except: self.head = ("303 SEE OTHER", [("Location", "/admin/requests")]) self.session.pushAlert("I can't find which template you want \ to use for sending out invites! Please click on the \ settings tab for this page and select which template \ to use.", "Oh no!", "error") return tmplData = {} emails = [] for ID in ids: req = rm.requestORM.find(ID) regToken = req.generateToken() tmplData[req.email] = {"email": req.email, "registerToken": regToken} emails.append(req.email) try: eu.sendMessage(tmplID, tmplData, emails, "fla.gr Invite") self.session.pushAlert("You granted the requests! A special \ email is on the way to them, as a result of your kind \ actions", ":)", "success") except Exception as exc: self.session.pushAlert("OH NO! One or all of the grant \ messages didn't send. Heres the error: %s"%exc, "FAILURE!" "error") self.head = ("303 SEE OTHER", [("location", "/admin/requests")]) else: self._404()
def sendMessage(self, tmplid, tmplData, whoTo, subject): """ Finds the given template id in the database, renders it into HTML via markdown, then runs mustache to fill in template data. Finally, the rendered and compiled template is put into an email package and sent via email to the person given by `whoTo` :param tmplid: The document id of the template for which to use for the email :param tmplData: The data which should be placed into the template with mustache :param whoTo: The email address of the person who this email should go to :param subject: The subject of the email """ tmplObj = tm.templateORM.getByID(tmplid) tmpl = tmplObj.template msg = self.makeMessage(subject, whoTo, tmpl, tmplData) logger.debug("Sending message...") if sm.getSetting("emailServer", "sendEmail"): try: self.s.sendmail("fla.gr", [whoTo], msg.as_string()) except: self.s.connect() self.s.sendmail("fla.gr", [whoTo], msg.as_string())
def GET(self): """ """ tmplid = self.env["members"][0] view = adminInfoTemplatesTmpl(searchList=[self.tmplSearchList]) template = tm.templateORM.getByID(tmplid) template.format() view.scripts = ["handlebars_1.0.min", "adminModal.flagr", "sidebarTabs.flagr", "editForm.flagr", "adminInfoTemplates.flagr"] try: currentTypes = sm.getSetting("templates", "types") except: currentTypes = {"Set template types in settings"} view.templateTypes = currentTypes view.tmpl = template return view