Exemplo n.º 1
0
def notification_new(request):
    if request.method == "POST":
        form = NotificationForm(request.POST)
        if form.is_valid():
            coordinates = GeoCoder.get_coordinates_from_address(
                Address(form.cleaned_data["address"],
                        form.cleaned_data["city"],
                        form.cleaned_data["state"],
                        form.cleaned_data["zipcode"]
                        )
            )
            print("Form: %s", form.cleaned_data)
            notification = form.save(commit=False)
            notification.latitude = str(coordinates.latitude)
            notification.longitude = str(coordinates.longitude)
            notification.user = request.user
            notification.save()

            for group in form.cleaned_data['groups']:
                notification.groups.add(group)
            notification.save()

            notification.notify()
            return redirect('website.views.notification_detail', pk=notification.pk)
    else:
        form = NotificationForm()
    return render(request, 'website/notification_edit.html', {'form': form})
Exemplo n.º 2
0
def notification_new(request):
    if request.method == "POST":
        form = NotificationForm(request.POST)
        if form.is_valid():
            coordinates = GeoCoder.get_coordinates_from_address(
                Address(form.cleaned_data["address"],
                        form.cleaned_data["city"], form.cleaned_data["state"],
                        form.cleaned_data["zipcode"]))
            print("Form: %s", form.cleaned_data)
            notification = form.save(commit=False)
            notification.latitude = str(coordinates.latitude)
            notification.longitude = str(coordinates.longitude)
            notification.user = request.user
            notification.save()

            for group in form.cleaned_data['groups']:
                notification.groups.add(group)
            notification.save()

            notification.notify()
            return redirect('website.views.notification_detail',
                            pk=notification.pk)
    else:
        form = NotificationForm()
    return render(request, 'website/notification_edit.html', {'form': form})
Exemplo n.º 3
0
def notification_new_or_edit(request, pk=None):
    template = "website/notification_{0}.html"
    if pk:
        template = str.format(template, "edit")
        notification = get_object_or_404(Notification, pk=pk)
        if notification.user != request.user:
            return HttpResponseForbidden()
    else:
        template = str.format(template, "new")
        notification = Notification(user=request.user)

    if request.method == "POST":
        form = NotificationForm(request.user, request.POST, instance=notification)
        if form.is_valid():
            coordinates = GeoCoder.get_coordinates_from_address(
                Address(form.cleaned_data["address"],
                        form.cleaned_data["city"],
                        form.cleaned_data["state"],
                        form.cleaned_data["zipcode"]
                        )
            )
            notification = form.save(commit=False)
            notification.latitude = str(coordinates.latitude)
            notification.longitude = str(coordinates.longitude)
            notification.user = request.user
            notification.save()

            for group in form.cleaned_data['groups']:
                notification.groups.add(group)
            notification.save()

            notification.notify()
            return redirect('website.views.notification_detail', pk=notification.pk)
    else:
        form = NotificationForm(request.user, instance=notification)
    return render(request, template, {'form': form})