Source

fromcontacts.webfactionimportwebfaction_sessiondefupdate_home_group_lists(*args,**kwargs):from.modelsimportHomeGroup,Contactifkwargs.get('raw',False):return# don't do this for fixture loadings=webfaction_session()ifsisNone:# This happens during developmentreturnwebfaction_email_list=[d['email_address']fordins.list_emails()]forhginHomeGroup.objects.exclude(group_email=''):ifhg.group_email!='':email_list=list(set([c.emailforcinhg.contact_set.exclude(email='').filter(include_on_email_lists=True)]))email_list_s=', '.join(email_list)ifhg.group_emailinwebfaction_email_list:# Update:s.update_email(hg.group_email,email_list_s)else:# Create news.create_email(hg.group_email,email_list_s)# Lists for all church members and all contactscontacts=set()members=set()forcinContact.objects.exclude(email='').filter(include_on_email_lists=True):ifc.church_member:members.add(c.email)contacts.add(c.email)s.update_email('church-contacts@christchurchbradford.org.uk',', '.join(list(contacts)))s.update_email('church-members@christchurchbradford.org.uk',', '.join(list(members)))