def sync_to_mandrill(self): # Clear cached info if hasattr(self, '_mailchimp_template_info'): del(self._mailchimp_template_info) mc_info = self.mailchimp_template_info settings = get_settings() md_name = '%s-%s' % (settings.mandrill_template_prefix, self.mailchimp_template) md_code = '%s' % self.process_mailchimp_source(mc_info['source']) info = { 'name': md_name, 'code': md_code, 'publish': True, } if self.mandrill_template_info: resp = self.c_mandrill.templates.update(**info) else: resp = self.c_mandrill.templates.add(**info) if not resp.has_key('status'): self.mandrill_template = resp['name'] self.last_sync = datetime.now() return True if hasattr(self, '_mandrill_template_info'): del(self._mandrill_template_info) return False
def __call__(self, context): terms = [] for line in get_settings().template_schemas: label, path = line.split('|') terms.append(SimpleTerm( value=path, token=str(path), title=label, )) return SimpleVocabulary(terms)
def mandrill_template_info(self): settings = get_settings() if not self.mandrill_template: if self.mailchimp_template: md_name = '%s-%s' % (settings.mandrill_template_prefix, self.mailchimp_template) # See if a template already exists in Mandrill try: info = self.c_mandrill.templates.info(name=md_name) self._mandrill_template = md_name self._mandrill_template_info = info except HTTPRequestException: return if not hasattr(self, '_mandrill_template_info') or not self._mandrill_template_info: self._mandrill_template_info = self.c_mandrill.templates.info(name=self.mandrill_template) return self._mandrill_template_info