def load_for_name(self, name): obj = self.filter(name=name).first() if not obj: source, path = utils.get_template_source(name) text = source or "subject\nbody" subject, text = text.split('\n', 1) obj = self.objects.create( name=name, subject=subject, text=text) return obj
def get_template(self, name, site=None): site = site or Site.app_site() ret, created = self.get_or_create(site=site, name=name) if created or not ret.subject or not ret.text: try: path = 'paloma/mails/default_%s.html' % name.lower() source = Soup(get_template_source(path)) ret.subject = source.select('subject')[0].text ret.subject = ret.subject.replace('\n', '').replace('\r', '') ret.text = source.select('text')[0].text ret.save() except Exception: logger.debug(traceback.format_exc()) return ret