def add_notification(request): """ add a notification """ if request.method == "POST": form = NotificationMessageForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect(reverse("productdb:home")) else: form = NotificationMessageForm() context = { "form": form } return render(request, "config/notification-add.html", context=context)
def add_notification(request): """ add a notification """ if request.method == "POST": form = NotificationMessageForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect(reverse("productdb:home")) else: form = NotificationMessageForm() context = {"form": form} return render(request, "config/notification-add.html", context=context)
def test_form(self): form = NotificationMessageForm(data={}) assert form.is_valid() is False assert "summary_message" in form.errors assert "title" in form.errors assert "type" in form.errors assert "detailed_message" in form.errors data = { "title": "Test title", "summary_message": "Test summary message", "detailed_message": "Test detailed message", "type": NotificationMessage.MESSAGE_INFO } form = NotificationMessageForm(data=data) assert form.is_valid() is True