Allow deleting requisitions

This commit is contained in:
2023-03-08 15:44:21 +00:00
parent 479e5b1022
commit 144e048d5f
4 changed files with 48 additions and 7 deletions

View File

@@ -35,8 +35,8 @@ class ReqsList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
list_template = "partials/aggregator-info.html"
page_title = "Aggregator Info"
context_object_name_singular = "account link"
context_object_name = "account links"
context_object_name_singular = "requisition"
context_object_name = "requisitions"
list_url_name = "reqs"
list_url_args = ["type", "pk"]
@@ -44,6 +44,11 @@ class ReqsList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
submit_url_name = "aggregator_countries"
submit_url_args = ["type", "pk"]
def get_context_data(self):
context = super().get_context_data()
context["pk"] = self.kwargs.get("pk")
return context
def get_queryset(self, **kwargs):
pk = kwargs.get("pk")
try:
@@ -179,6 +184,29 @@ class AggregatorLinkBank(LoginRequiredMixin, OTPRequiredMixin, View):
return response
class ReqDelete(LoginRequiredMixin, OTPRequiredMixin, View):
def delete(self, request, *args, **kwargs):
pk = kwargs.get("pk")
req_id = kwargs.get("req_id")
try:
aggregator = Aggregator.get_by_id(pk, self.request.user)
except Aggregator.DoesNotExist:
message = "Aggregator does not exist"
message_class = "danger"
context = {
"message": message,
"message_class": message_class,
"window_content": self.window_content,
}
return self.render_to_response(context)
run = synchronize_async_helper(NordigenClient(aggregator))
synchronize_async_helper(run.delete_requisition(req_id))
response = HttpResponse(status=204)
response["HX-Trigger"] = "requisitionEvent"
return response
class AggregatorList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
list_template = "partials/aggregator-list.html"
model = Aggregator