def show(self, template_id): try: template = self.db(self.db.t_email_template.id == template_id).select(self.db.t_email_template.f_html_text).first() except Exception as e: logger.warning("Not possible to get page.") logger.warning(str(e)) return None if not template: return None return template.f_html_text.replace("{=", '')
def __load_ldap_connection(ldap, db, auth, config): try: if config.__getattribute__(ldap).is_active: from gluon.contrib.login_methods.ldap_auth import ldap_auth if config.auth.auth_local_database: auth.settings.login_methods.append( ldap_auth( mode=config.__getattribute__(ldap).mode, secure=config.__getattribute__(ldap).secure, server=config.__getattribute__(ldap).server, port=config.__getattribute__(ldap).port, base_dn=config.__getattribute__(ldap).base_dn, allowed_groups=config.__getattribute__(ldap).allowed_groups, group_dn=config.__getattribute__(ldap).group_dn, group_name_attrib=config.__getattribute__(ldap).group_name_attrib, group_member_attrib=config.__getattribute__(ldap).group_member_attrib, group_filterstr=config.__getattribute__(ldap).group_filterstr, manage_user=True, user_firstname_attrib="cn:1", user_lastname_attrib="cn:2", user_mail_attrib="mail", db=db, ) ) else: auth.settings.login_methods = [ ( ldap_auth( mode=config.__getattribute__(ldap).mode, secure=config.__getattribute__(ldap).secure, server=config.__getattribute__(ldap).server, port=config.__getattribute__(ldap).port, base_dn=config.__getattribute__(ldap).base_dn, allowed_groups=config.__getattribute__(ldap).allowed_groups, group_dn=config.__getattribute__(ldap).group_dn, group_name_attrib=config.__getattribute__(ldap).group_name_attrib, group_member_attrib=config.__getattribute__(ldap).group_member_attrib, group_filterstr=config.__getattribute__(ldap).group_filterstr, manage_user=True, user_firstname_attrib="cn:1", user_lastname_attrib="cn:2", user_mail_attrib="mail", db=db, ) ) ] except Exception as e: logger.warning("Not possible to connect to LDAP.") raise PRETTYHTTP(500, e)
def __define_domain(domain, config): domain = domain.lower() try: count = 1 while True: ldap_connection = "auth_ldap_0" + str(count) if config.__getattribute__(ldap_connection).is_active: if config.__getattribute__(ldap_connection).domain == domain: __load_ldap_connection(ldap_connection, config) break count += 1 except Exception as e: logger.warning("Not possible to connect to LDAP.") raise PRETTYHTTP(400, "Upppss, the domain you have type, I could not find it...")
def _set_twitter_card(self): ''' <meta name="twitter:title" content="Linux-Cambodia" /> <meta name="twitter:description" content="Linux-Cambodia is a non-profit project committed with the current and emergent technology trends in Cambodia, with the Internet, with education...Behind the headings, the products and the services offered by Linux Cambodia there is a team of professionals with sound experience on information technologies, online marketing, events management, video producing, social media, training, web developing... The initiative is rooted in the idea that every person has the right to access information and knowledge. In this sense and due to the lack of these contents in the Cambodian market, this project is launched with the hope of reaching all audiences who are passionate about open source." /> <meta name="twitter:image" content="http://www.linux-cambodia.com/default/download/new.picture.98d62da3eccd8100.77656c636f6d652e6a7067_thumb.jpg" /> ''' for name in ['image', 'title', 'description']: dict = OrderedDict() if name == 'title': content = self.title else: try: content = self.row['f_'+name] except AttributeError as e: logger.warning("%s attribute have been not set" % name) content = None if content: dict['property'] = "twitter:"+name dict['content'] = content self.response.meta['tc_'+name] = dict
def build_message_from_template(self, event_type, render_html=True, **kwargs): from gluon.html import XML from gluon.template import render path = self.request.folder + "/" + "private/email_templates/" + event_type + ".html" template = str(XML(open(path).read())) if not template: logger.warning( "App notification message, you need to define an email template for %s event \n %s" % (event_type, str(kwargs)) ) self.render = lambda text: render(text, context=dict(event_type=event_type, **kwargs)) try: if render_html: html_message = self.render(template) import html2text plain_message = html2text.html2text(html_message) except Exception as e: html_message = "" logger.warning("Render email template %s. Please, edit the email template carefully" % event_type) logger.warning(str(e)) return dict(message=[plain_message, html_message], reply_to=self.config.take("smtp.reply_to"))
def show(self, slug_key=None, page_id=None): try: if page_id: page = self.db((self.db.t_page.id == page_id)).select().first() else: page = self.db((self.db.t_page.f_is_active == True) & (self.db.t_page.f_slug_key == slug_key) & (self.db.t_page.f_lang_code == self.T.accepted_language)).select().first() if not page: page = self.db((self.db.t_page.f_is_active == True) & (self.db.t_page.f_slug_key == slug_key) & (self.db.t_page.f_lang_code == self.config.take('general.default_language'))).select().first() logger.warning("You need to define a static %s page for %s " % (self.T.accepted_language, slug_key)) except Exception as e: logger.warning("Not possible to get page.") logger.warning(str(e)) return None if not page: return None # Set some seo parameters based in the info we have already in the database seo = SEO(page, locale=self.T.accepted_language, type="website") seo.set() return page.f_html_text
def _set_open_graph(self): for name in ['type', 'title', 'url', 'description', 'site_name', 'locale', 'locale_alternate', 'image']: dict = OrderedDict() if name == 'type': content = self.type elif name == 'site_name': content = self.title elif name == 'url': content = self.url elif name == 'locale': content = self.locale elif name == 'locale_alternate': content = self.config.take('general.locale_alternate') else: try: content = self.row['f_'+name] except AttributeError as e: logger.warning("%s attribute have been not set" % name) content = None if content: dict['name'] = "og:"+name dict['content'] = content self.response.meta['og_'+name] = dict
def build_message_from_template(self, event_type, lang=None, render_html=True, **kwargs): lang = lang or self.T.accepted_language template = self.db((self.db.t_email_template.f_template_key == event_type) & (self.db.t_email_template.f_lang_code == lang)).select().first() if not template: template = self.db((self.db.t_email_template.f_template_key == event_type) & (self.db.t_email_template.f_lang_code == self.config.take('general.default_language'))).select().first() logger.warning("App notification message, you need to define an email template for %s event \n %s" % (event_type, str(kwargs))) self.render = lambda text: render(text, context=dict(event_type=event_type, **kwargs)) try: if render_html: html_message = self.render(template.f_html_text) else: html_message = template.f_html_text except Exception as e: html_message = '' logger.warning("Render html_message template %s. Please, edit the email template carefully" % event_type) logger.warning(str(e)) try: if render_html: subject_text = self.render(template.f_subject_text) else: subject_text = template.f_subject_text except Exception as e: subject_text = '' logger.warning("Render subject_text template %s. Please, edit the email template carefully" % event_type) logger.warning(str(e)) try: if render_html: plain_message = self.render(template.f_plain_text) else: plain_message = template.f_plain_text except Exception as e: plain_message = '' logger.warning("Render plain_message template %s. Please, edit the email template carefully" % event_type) logger.warning(str(e)) return dict(message=[plain_message, html_message], subject=subject_text % kwargs, reply_to=template.f_reply_to or "Undisclosed Recipients", bcc=template.f_copy_to or "", attachments=[template.f_attachment_file] or "")