def send_emails(email_template,recipient_list,substitution_dict=None): """ Gets an email template from demisauce and sends to recipient list using scheduler which runs in the background allowing this current request to continue processing """ from demisauce.lib import mail from demisaucepy import pylons_helper, demisauce_ws_get import urllib resource_id = urllib.quote_plus(email_template) response = demisauce_ws_get('email',resource_id,format='xml',cache=False) if response.success: t = response.model from string import Template if hasattr(t,'template'): s = Template(t.template) template = s.substitute(substitution_dict) mail.send_mail_toeach((t.subject, template, '%s<%s>' % (t.from_name,t.from_email), recipient_list)) log.debug('sent emails to %s' % recipient_list) else: log.error('Error retrieving that template 1') elif not emails.success: log.error('Error retrieving that template 2') return False
def test_connection(self): """ Test that Server is up, apikey works """ assert self.cfg['demisauce.url'] == 'http://localhost:4951' item = demisauce_ws_get('connect','') assert item.success == True assert item.data # we should have a valid api key assert item.data.find('connected') >= 0
def test_emailget(self): """ Test the xml get capabilities of email """ response = demisauce_ws_get('email','welcome_to_demisauce',format='xml') assert response.success == True #print response.data email = response.model #print response.xmlnode #print dir(response.xmlnode) #print len(response.xmlnode) assert response.model is not None assert len(response.xmlnode) == 1 # this means email = model #print dir(model) #print 'is model none? %s' % (model == None) # this is really more of a test of xmlnode, should move it assert email.subject == 'Welcome To Demisauce', 'ensure suject for each node is what we want' assert email.key == 'welcome_to_demisauce' assert 'Welcome' in email.template
def ws_get(): return demisauce_ws_get(method, resource_id, format=format)