Implement alias editing form
This commit is contained in:
parent
c80b37663a
commit
5a66236828
|
@ -214,6 +214,68 @@ class ThresholdIRCAliases(SuperUserRequiredMixin, APIView):
|
|||
}
|
||||
return render(request, self.template_name, context)
|
||||
|
||||
class ThresholdIRCAliasesEdit(SuperUserRequiredMixin, APIView):
|
||||
template_name = "manage/threshold/irc/overview/modals/edit-aliases.html"
|
||||
parser_classes = [FormParser]
|
||||
|
||||
def get(self, request):
|
||||
"""
|
||||
Get aliases edit form.
|
||||
"""
|
||||
aliases = threshold.get_aliases()
|
||||
context = {
|
||||
"aliases": aliases["aliases"],
|
||||
}
|
||||
return render(request, self.template_name, context)
|
||||
|
||||
def post(self, request):
|
||||
"""
|
||||
Set the aliases
|
||||
"""
|
||||
message = "Successfully updated aliases"
|
||||
message_class = "success"
|
||||
new_aliases = {}
|
||||
for item in request.data:
|
||||
if not "|" in item:
|
||||
continue
|
||||
spl = item.split("|")
|
||||
if len(spl) != 2:
|
||||
message = f"Invalid item: {item}"
|
||||
message_class = "danger"
|
||||
break
|
||||
num, field = spl
|
||||
value = request.data[item]
|
||||
if field == "emails":
|
||||
value = request.data[item].split("\n")
|
||||
print("EMAILS", )
|
||||
for email in value:
|
||||
# Check field isn't just empty
|
||||
if len(email) != 0:
|
||||
# Simple check for valid email
|
||||
if "@" not in email:
|
||||
message = f"Invalid email: {email}"
|
||||
message_class = "danger"
|
||||
break
|
||||
# Need to exit here and not run the update
|
||||
# Or just let threshold do the validation
|
||||
if num not in new_aliases:
|
||||
new_aliases[num] = {field: value}
|
||||
else:
|
||||
new_aliases[num][field] = value
|
||||
print("NEW", new_aliases)
|
||||
#if not message_class = "danger":
|
||||
# updated = threshold.update_aliases(new_aliases)
|
||||
# if not updated:
|
||||
# message = updated["reason"]
|
||||
# message_class = "danger"
|
||||
template_name = "manage/threshold/irc/overview/aliases.html"
|
||||
aliases = threshold.get_aliases()
|
||||
context = {
|
||||
"aliases": aliases["aliases"],
|
||||
"message": message,
|
||||
"class": message_class,
|
||||
}
|
||||
return render(request, template_name, context)
|
||||
|
||||
class ThresholdIRCNetworkActions(SuperUserRequiredMixin, View):
|
||||
template_name = "manage/threshold/irc/network/actions.html"
|
||||
|
|
Loading…
Reference in New Issue