add remove button on custom domain name

This commit is contained in:
Son NK 2020-11-24 12:02:47 +01:00
parent c28872288b
commit bcb2657de3
2 changed files with 18 additions and 7 deletions

View file

@ -72,7 +72,10 @@
name="alias-name"
placeholder="Alias name">
</div>
<button class="btn btn-primary">Save</button>
<button class="btn btn-primary" name="action" value="save">Save</button>
{% if custom_domain.name %}
<button class="btn btn-danger float-right" name="action" value="remove">Remove</button>
{% endif %}
</form>
</div>

View file

@ -154,12 +154,20 @@ def domain_detail(custom_domain_id):
url_for("dashboard.domain_detail", custom_domain_id=custom_domain.id)
)
elif request.form.get("form-name") == "set-name":
custom_domain.name = request.form.get("alias-name").replace("\n", "")
db.session.commit()
flash(
f"Default alias name for Domain {custom_domain.domain} has been set",
"success",
)
if request.form.get("action") == "save":
custom_domain.name = request.form.get("alias-name").replace("\n", "")
db.session.commit()
flash(
f"Default alias name for Domain {custom_domain.domain} has been set",
"success",
)
else:
custom_domain.name = None
db.session.commit()
flash(
f"Default alias name for Domain {custom_domain.domain} has been removed",
"info",
)
return redirect(
url_for("dashboard.domain_detail", custom_domain_id=custom_domain.id)