示例#1
0
def add_notifications(request):
    template_name = "sms-notifications.html"
    if request.method == "POST":  # If the form has been submitted...
        form = SmsNotificationForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # saving the form data is not cleaned
            form.save()
            return message(request, "SMS Notification Added", link="/smsnotification")
    else:
        form = SmsNotificationForm()  # An unbound form

    return render_to_response(request, template_name, {"form": form})
示例#2
0
def edit_notifications(request, pk):
    template_name = "sms-notifications.html"
    notification = get_object_or_404(SmsNotification, pk=pk)
    if request.method == "POST":  # If the form has been submitted...
        form = SmsNotificationForm(request.POST, instance=notification)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # saving the form data is not cleaned
            form.save()
            return message(request, "SMS Notification Updated", link="/smsnotification")
    else:
        form = SmsNotificationForm(instance=notification)

    return render_to_response(request, template_name, {"form": form, "notification": notification})