Skip to content

Commit d9f4c17

Browse files
committed
better form handling in project_notification for webhook_form and email_form
1 parent 07b10bd commit d9f4c17

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

readthedocs/projects/views/private.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -506,24 +506,25 @@ def project_notifications(request, project_slug):
506506
project = get_object_or_404(
507507
Project.objects.for_admin_user(request.user), slug=project_slug)
508508

509-
email_form = EmailHookForm(data=request.POST or None, project=project)
510-
webhook_form = WebHookForm(data=request.POST or None, project=project)
509+
project_dashboard = reverse('projects_notifications', args=[project.slug])
511510

512-
if request.method == 'POST':
513-
if 'email' not in request.POST:
514-
email_form = EmailHookForm(data=None, project=project)
515-
if 'url' not in request.POST:
516-
webhook_form = WebHookForm(data=None, project=project)
517-
project_dashboard = reverse(
518-
'projects_notifications',
519-
args=[project.slug],
520-
)
511+
if request.method == 'POST' and 'email' in request.POST:
512+
email_form = EmailHookForm(data=request.POST, project=project)
521513
if email_form.is_valid():
522514
email_form.save()
523515
return HttpResponseRedirect(project_dashboard)
516+
else:
517+
# Blank email_form if webhook_form is submitted or the request is GET
518+
email_form = EmailHookForm(data=None, project=project)
519+
520+
if request.method == 'POST' and 'url' in request.POST:
521+
webhook_form = WebHookForm(data=request.POST, project=project)
524522
if webhook_form.is_valid():
525523
webhook_form.save()
526524
return HttpResponseRedirect(project_dashboard)
525+
else:
526+
# Blank webhook_form if email_form is submitted or the request is GET
527+
webhook_form = WebHookForm(data=None, project=project)
527528

528529
emails = project.emailhook_notifications.all()
529530
urls = project.webhook_notifications.all()

0 commit comments

Comments
 (0)