Fix passing registration status to modal

This commit is contained in:
Mark Veidemanis 2022-08-14 23:59:02 +01:00
parent bfd9c03c82
commit dbb12bc8ff
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
3 changed files with 46 additions and 18 deletions

View File

@ -52,7 +52,7 @@
</span>
</button>
</div>
{% if unreg %}
{% if unreg is not None %}
<form
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-put="{% url 'threshold_irc_actions_registration_net' net %}"
@ -60,14 +60,18 @@
hx-swap="outerHTML">
{% for network, items in unreg.items %}
<h4 class="title is-4">{{ network }}</h4>
{% for nick, num in items %}
<div class="field">
<label class="label">{{ nick }}/{{ num }}</label>
<div class="control">
<input class="input" type="text" name="{{ network }}|{{ num }}" placeholder="Enter token">
{% if items is not False %}
{% for nick, num in items %}
<div class="field">
<label class="label">{{ nick }}/{{ num }}</label>
<div class="control">
<input class="input" type="text" name="{{ network }}|{{ num }}" placeholder="Enter token">
</div>
</div>
</div>
{% endfor %}
{% endfor %}
{% else %}
<p>Error getting information for {{ network }}.</p>
{% endif %}
{% endfor %}
<button
type="button"

View File

@ -1,4 +1,5 @@
import urllib.parse
from django import template
register = template.Library()

View File

@ -418,7 +418,7 @@ class ThresholdIRCActionsRegistration(SuperUserRequiredMixin, APIView):
"message": message,
"class": message_class,
}
if not message_class == "danger":
if "unreg" in unreg:
context["unreg"] = unreg["unreg"]
return render(request, self.template_name, context)
@ -426,6 +426,8 @@ class ThresholdIRCActionsRegistration(SuperUserRequiredMixin, APIView):
"""
Confirm registration for networks.
"""
message = None
message_class = None
if request.resolver_match.url_name == "threshold_irc_actions_registration_net":
template_name = "manage/threshold/irc/network/actions.html"
else:
@ -439,14 +441,23 @@ class ThresholdIRCActionsRegistration(SuperUserRequiredMixin, APIView):
message = updated["reason"]
message_class = "danger"
unreg = threshold.irc_get_unreg(net)
if not unreg:
message = "Could not get registration status."
message_class = "danger"
elif not unreg["success"]:
if "reason" in unreg:
message = unreg["reason"]
message_class = "danger"
else:
message = "Getting registration status failed."
message_class = "danger"
context = {
"unreg": unreg,
"net": net,
"message": message,
"class": message_class,
}
if net:
if net != "None":
context["net"] = net
if "unreg" in unreg:
context["unreg"] = unreg["unreg"]
return render(request, template_name, context)
@ -467,18 +478,30 @@ class ThresholdIRCActionsRegistrationAuth(SuperUserRequiredMixin, APIView):
message = updated["reason"]
message_class = "danger"
if "net" in request.data:
net = request.data["net"]
if request.data["net"] != "None":
net = request.data["net"]
else:
net = None
else:
net = None
unreg = threshold.irc_get_unreg(net)
if not unreg:
message = "Could not get registration status."
message_class = "danger"
elif not unreg["success"]:
if "reason" in unreg:
message = unreg["reason"]
message_class = "danger"
else:
message = "Getting registration status failed."
message_class = "danger"
context = {
"unreg": unreg,
"net": net,
"message": message,
"class": message_class,
}
if "net" in request.data:
if request.data["net"] != "None":
context["net"] = request.data["net"]
if "unreg" in unreg:
context["unreg"] = unreg["unreg"]
return render(request, self.template_name, context)