Exemplo n.º 1
0
def mail_organizers(request):
    if request.method == 'POST':    
        form = MailOrganizersForm(request.POST)
        if form.is_valid():
            mail.mail_organizers(form.data['subject'], form.data['message'])
            return redirect('fns_admin.views.mail_organizers_done')
    else:
        form = MailOrganizersForm()

    return render_to_response('fns_admin/mail_organizers.html', {
        'form': form,
    }, context_instance=RequestContext(request))
Exemplo n.º 2
0
def mail_organizers(request):
    if request.method == 'POST':
        form = MailOrganizersForm(request.POST)
        if form.is_valid():
            subject = form.cleaned_data['subject']
            message = form.cleaned_data['message']

            boroughs = form.cleaned_data['boroughs']
            lot_types = form.cleaned_data['lot_types']
            owner_names = form.cleaned_data['owner_names']
            user_types = form.cleaned_data['user_types']
            bbox = form.cleaned_data['bbox']

            filters = Q(
                lot__borough__in=boroughs,
                lot__lotlayer__name__in=lot_types,
                lot__owner__name__in=owner_names,
            )

            if bbox:
                p = Polygon.from_bbox(bbox.split(','))
                filters = filters & Q(lot__centroid__within=p)

            if 'organizers' in user_types:
                organizers = Organizer.objects.filter(
                    filters, email__isnull=False).exclude(email='')
                mass_mail_organizers(subject, message, organizers)
            if 'watchers' in user_types:
                watchers = Watcher.objects.filter(
                    filters, email__isnull=False).exclude(email='')
                mass_mail_watchers(subject, message, watchers)
            return redirect('fns_admin.views.mail_organizers_done')
    else:
        form = MailOrganizersForm()

    return render_to_response('fns_admin/mail_organizers.html', {
        'form': form,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 3
0
def mail_organizers(request):
    if request.method == 'POST':    
        form = MailOrganizersForm(request.POST)
        if form.is_valid():
            subject = form.cleaned_data['subject']
            message = form.cleaned_data['message']

            boroughs = form.cleaned_data['boroughs']
            lot_types = form.cleaned_data['lot_types']
            owner_names = form.cleaned_data['owner_names']
            user_types = form.cleaned_data['user_types']
            bbox = form.cleaned_data['bbox']

            filters = Q(
                lot__borough__in=boroughs,
                lot__lotlayer__name__in=lot_types,
                lot__owner__name__in=owner_names,
            )

            if bbox:
                p = Polygon.from_bbox(bbox.split(','))
                filters = filters & Q(lot__centroid__within=p)

            if 'organizers' in user_types:
                organizers = Organizer.objects.filter(filters, email__isnull=False).exclude(email='')
                mass_mail_organizers(subject, message, organizers)
            if 'watchers' in user_types:
                watchers = Watcher.objects.filter(filters, email__isnull=False).exclude(email='')
                mass_mail_watchers(subject, message, watchers)
            return redirect('fns_admin.views.mail_organizers_done')
    else:
        form = MailOrganizersForm()

    return render_to_response('fns_admin/mail_organizers.html', {
        'form': form,
    }, context_instance=RequestContext(request))