From ee3c75244e258242f74ff565eb36cc243a908c13 Mon Sep 17 00:00:00 2001 From: Son NK Date: Wed, 1 Jan 2020 23:51:40 +0100 Subject: [PATCH] Fix custom domain has been added before --- app/dashboard/views/custom_domain.py | 30 +++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/dashboard/views/custom_domain.py b/app/dashboard/views/custom_domain.py index ba4ed7d6..c05cfff0 100644 --- a/app/dashboard/views/custom_domain.py +++ b/app/dashboard/views/custom_domain.py @@ -31,19 +31,25 @@ def custom_domain(): if request.method == "POST": if request.form.get("form-name") == "create": if new_custom_domain_form.validate(): - new_custom_domain = CustomDomain.create( - domain=new_custom_domain_form.domain.data, user_id=current_user.id - ) - db.session.commit() - - flash(f"New domain {new_custom_domain.domain} is created", "success") - - return redirect( - url_for( - "dashboard.domain_detail_dns", - custom_domain_id=new_custom_domain.id, + new_domain = new_custom_domain_form.domain.data + if CustomDomain.get_by(domain=new_domain): + flash(f"{new_domain} already added", "warning") + else: + new_custom_domain = CustomDomain.create( + domain=new_domain, user_id=current_user.id + ) + db.session.commit() + + flash( + f"New domain {new_custom_domain.domain} is created", "success" + ) + + return redirect( + url_for( + "dashboard.domain_detail_dns", + custom_domain_id=new_custom_domain.id, + ) ) - ) return render_template( "dashboard/custom_domain.html",