def phoneAnnounce(request, announce_id): announcement = get_object_or_404(Announcement, pk=announce_id) if (not request.user.has_perm('announce.uniauth') and request.user.profile.member_organization != announcement.member_organization): return HttpResponseRedirect(reverse('announce:announcements')) glean = announcement.glean source = primary_source(announcement.glean) return render(request, 'announce/phone.html', {'announcement': announcement, 'glean': glean, 'source': source})
def editAnnounce(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,))) templates = Template.objects.all( member_organization=profile.member_organization) source = primary_source(announce.glean) 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:detailannounce', args=(new_save.id,))) else: return render( request, 'announce/edit_announce.html', {'glean': announce.glean, 'templates': templates, 'form': form, 'recipients': recipients, 'source': source}) else: templates = Template.objects.all() form = AnnouncementForm(instance=announce) return render( request, 'announce/edit_announce.html', {'glean': announce.glean, 'templates': templates, 'form': form, 'source': source})
def detailAnnounce(request, announce_id): announcement = get_object_or_404(Announcement, pk=announce_id) if (not request.user.has_perm('announce.uniauth') and request.user.profile.member_organization != announcement.member_organization): return HttpResponseRedirect(reverse('announce:announcements')) body = render_mail(template, announcement, request.user.profile) glean = announcement.glean source = primary_source(announcement.glean) if request.method == 'POST' and announcement.sent is False: mail_from_source(announcement) announcement.sent = True announcement.sent_by = request.user announcement.save() return HttpResponseRedirect( reverse('announce:detailannounce', args=(announce_id,))) else: return render( request, 'announce/announce_detail.html', {'announcement': announcement, 'test': body, 'glean': glean, 'source': source})
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})