def test_render_email(self): template = self.glean.member_organization.create_default_template() body = render_email(self.announcement, self.user.profile) self.assertNotEqual( body, "", "Body is not a string (or we made it to python 3!" " Body is of type: {0}".format(type(body)) )
def HTMLemail(request, announce_id): announce = get_object_or_404(Announcement, pk=announce_id) glean = announce.glean body = render_email(announce, request.user.profile) if announce.title: subject = announce.title else: subject = glean.title return render( request, 'announce/HTMLemail.html', {'body': body, 'subject': subject})
def combinedAnnounce(request, announce_id): announce = get_object_or_404(Announcement, pk=announce_id) profile = request.user.profile if (not request.user.has_perm('announce.uniauth') and profile.member_organization != announce.member_organization): return HttpResponseRedirect( reverse('announce:detailannounce', args=(announce_id,))) glean = announce.glean if announce.title: subject = announce.title else: subject = glean.title templates = Template.objects.filter( member_organization=profile.member_organization) source = primary_source(announce.glean) recipients = [] phone = [] body = render_email(announce, request.user.profile) for recipient in source.counties.people.all(): if (recipient not in recipients and recipient.accepts_email and recipient.preferred_method == '1'): recipients.append(recipient) elif (recipient.preferred_method == '2' and recipient.accepts_email and recipient not in phone): phone.append(recipient) if request.method == 'POST': form = AnnouncementForm(request.POST) if form.is_valid(): new_save = form.save(commit=False) new_save.member_organization = announce.member_organization new_save.glean = announce.glean new_save.datetime = announce.datetime new_save.id = announce.id new_save.save() return HttpResponseRedirect( reverse('announce:combinedannounce', args=(new_save.id,))) else: return render( request, 'announce/combined_announce.html', {'glean': announce.glean, 'templates': templates, 'form': form, 'recipients': recipients, 'phone': phone, 'source': source, 'subject': subject}) else: templates = Template.objects.all() form = AnnouncementForm(instance=announce) if not request.user.has_perm('announce.uniauth'): form.fields['template'].queryset = Template.objects.filter( member_organization=profile.member_organization) return render( request, 'announce/combined_announce.html', {'glean': announce.glean, 'announcement': announce, 'templates': templates, 'form': form, 'phone': phone, 'recipients': recipients, 'source': source, 'test': body, 'subject': subject})