def email_send(job_object): """Email background sendor format:: jsondict = { 'apikey':'optional val to override ds default', 'template_name':'thank_you_for_registering_with_demisauce', 'emails':['*****@*****.**'], 'template_data':{ 'displayname':'Bob User', 'title':'welcome', 'email':'*****@*****.**', 'link':'http://www.demisauce.com/?go' } } gearman_client.do_task(Task("email_send",json.dumps(jsondict), background=True)) """ try: emailargs = json.loads(job_object.arg) email_name = urllib.quote_plus(emailargs['template_name']) if 'apikey' in emailargs: response = demisauce_ws('email',email_name,cache=True,apikey=emailargs['apikey']) else: response = demisauce_ws('email',email_name,cache=True) if response.success and response.json and len(response.json) ==1: emailjson = response.json[0] s = Template(emailjson['template']) sh = Template(emailjson['template']) if emailjson['template_html'] not in (None,''): sh = Template(emailjson['template_html']) if 'template_data' in emailargs: template = s.substitute(emailargs['template_data']) templateh = sh.substitute(emailargs['template_data']) else: template = s.substitute({}) templateh = sh.substitute({}) #tuple: (subject, body, to<*****@*****.**>, [[email protected],[email protected]]) data = {'subject': emailjson['subject'], 'message':template, 'from_email':'%s<%s>' % (emailjson['from_name'],emailjson['from_email']), 'recipient_list': emailargs['emails'], 'message_html': templateh} num_sent = mail.send_mail_toeach(data) logging.info('sent email to %s, num_sent = %s' % (emailargs['emails'], num_sent)) return num_sent else: #logging.error("len json = %s" % (len(response.json))) logging.error('Error retrieving that template %s \n\n %s' % (emailargs,response.json)) return -1 except: #logging.error("Error in gearman task email_send: %s" % err) traceback.print_exc() return -1
def by_hashed_email(cls,hemail=''): """ Returns the single person record for this entry """ dsitem = demisauce_ws('person',hemail,format='xml') if dsitem.success == True: return dsitem.xml_node.person else: return None
def all(cls): """ Returns all person entries for your site """ dsitem = demisauce_ws('person',None,format='xml') if dsitem.success == True: return dsitem.xml_node.person else: return None
def test_connection(): "test base api connectivity, auth" response = demisauce_ws('email','welcome_to_demisauce',format='json') assert response.success == True assert response.json is not None assert len(response.json) == 1 # should return exactly one record emailjson = response.json[0] assert 'subject' in emailjson assert 'Demisauce' in emailjson['subject']
def test_person(self): """ Test the xml get capabilities of person/user account system as well as read's """ email = Person.create_random_email() person_data = { 'email':email, 'displayname':'library testing user', 'url':'http://testingurls.com', 'authn':'local' } hashed_email = hash_email(email) dsitem = demisauce_ws('person',hashed_email,data=person_data,format='xml') assert dsitem.success == True print dsitem.data plist = [pl for pl in dsitem.model] assert len(plist) == 1, 'ensure length of array of nodes is 1' p = dsitem.model.person assert p != None, 'p should not be none' assert p.id > 0, 'userid should be returned' assert p.hashedemail == hashed_email assert p.email == email assert p.displayname == 'library testing user' assert p.authn == 'local' person_data = { 'email':email, 'displayname':'library UPDATE', 'url':'http://www.google.com', 'authn':'google' } dsitem2 = demisauce_ws('person',hashed_email,data=person_data,format='xml') assert dsitem2.success == True #assert True == False print dsitem2.data p2 = dsitem2.model assert p2.displayname == 'library UPDATE', 'p2.displayname should have been updated' assert p2.id == p.id, 'userid should be same as other' assert p2.authn == 'google'
def by_name(cls,name=''): """ Returns the comments record's """ name = urllib.quote_plus(name) dsitem = demisauce_ws('comment',name,format='xml') if dsitem.success == True: poll = dsitem.model.comment poll._xml = dsitem.data return poll else: print dsitem.data return None
def by_name(cls,name=''): """ Returns the single poll record for this named poll """ name = urllib.quote_plus(name) dsitem = demisauce_ws('poll',name,format='xml') if dsitem.success == True: poll = dsitem.model poll._xml = dsitem.data return poll else: print dsitem.data return None