mailing lists: fetch lists on validation error

This fixes a crash which would occur if you had a validation error in
your form submission.
This commit is contained in:
Drew DeVault 2021-08-09 09:06:51 +02:00
parent 7be0b2838f
commit 9add0bfac7
1 changed files with 9 additions and 3 deletions

View File

@ -143,18 +143,22 @@ def new_POST(owner, project_name):
if not valid.ok:
mls = lists.get_lists(owner)
mls = sorted(mls, key=lambda r: r["updated"], reverse=True)
existing = [l.remote_id for l in (MailingList.query
.filter(MailingList.project_id == project.id)).all()]
return render_template("mailing-list-new.html",
view="new-resource", owner=owner, project=project,
lists=mls, **valid.kwargs)
lists=mls, existing=existing **valid.kwargs)
return lists_from_template(owner, project, template)
elif "create" in valid:
mailing_list = lists.create_list(owner, valid)
if not valid.ok:
mls = lists.get_lists(owner)
mls = sorted(mls, key=lambda r: r["updated"], reverse=True)
existing = [l.remote_id for l in (MailingList.query
.filter(MailingList.project_id == project.id)).all()]
return render_template("mailing-list-new.html",
view="new-resource", owner=owner, project=project,
lists=mls, **valid.kwargs)
lists=mls, existing=existing, **valid.kwargs)
else:
list_name = None
for field in valid.source:
@ -167,9 +171,11 @@ def new_POST(owner, project_name):
# TODO: Search properly
mls = filter(lambda r: search.lower() in r["name"].lower(), mls)
mls = sorted(mls, key=lambda r: r["updated"], reverse=True)
existing = [l.remote_id for l in (MailingList.query
.filter(MailingList.project_id == project.id)).all()]
return render_template("mailing-list-new.html",
view="new-resource", owner=owner, project=project,
lists=mls, search=search)
lists=mls, existing=existing, search=search)
mailing_list = lists.get_list(owner, list_name)
ml = MailingList()