Exemplo n.º 1
0
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})
Exemplo n.º 2
0
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})