Allow deleting requisitions
This commit is contained in:
parent
479e5b1022
commit
144e048d5f
|
@ -81,4 +81,10 @@ urlpatterns = [
|
||||||
aggregators.AggregatorLinkBank.as_view(),
|
aggregators.AggregatorLinkBank.as_view(),
|
||||||
name="aggregator_link",
|
name="aggregator_link",
|
||||||
),
|
),
|
||||||
|
# Delete requisition
|
||||||
|
path(
|
||||||
|
"aggs/<str:type>/delete/<str:pk>/<str:req_id>/",
|
||||||
|
aggregators.ReqDelete.as_view(),
|
||||||
|
name="req_delete",
|
||||||
|
),
|
||||||
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||||
|
|
|
@ -36,14 +36,11 @@ class NordigenClient(BaseClient):
|
||||||
}
|
}
|
||||||
|
|
||||||
response = await self.call("token/new", http_method="post", data=data)
|
response = await self.call("token/new", http_method="post", data=data)
|
||||||
print("RESPONSE IN GET ACCESS TOKEN", response) #
|
|
||||||
access = response["access"]
|
access = response["access"]
|
||||||
access_expires = response["access_expires"]
|
access_expires = response["access_expires"]
|
||||||
print("ACCESS EXPIRES", access_expires)
|
|
||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
# Offset now by access_expires seconds
|
# Offset now by access_expires seconds
|
||||||
access_expires = now + timedelta(seconds=access_expires)
|
access_expires = now + timedelta(seconds=access_expires)
|
||||||
print("ACCESS EXPIRES", access_expires)
|
|
||||||
self.instance.access_token = access
|
self.instance.access_token = access
|
||||||
self.instance.access_token_expires = access_expires
|
self.instance.access_token_expires = access_expires
|
||||||
self.instance.save()
|
self.instance.save()
|
||||||
|
@ -93,7 +90,17 @@ class NordigenClient(BaseClient):
|
||||||
response = await self.call(
|
response = await self.call(
|
||||||
"requisitions", schema="RequisitionsPost", http_method="post", data=data
|
"requisitions", schema="RequisitionsPost", http_method="post", data=data
|
||||||
)
|
)
|
||||||
print("build_link response", response)
|
|
||||||
if "link" in response:
|
if "link" in response:
|
||||||
return response["link"]
|
return response["link"]
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
async def delete_requisition(self, requisition_id):
|
||||||
|
"""
|
||||||
|
Delete a requisision ID.
|
||||||
|
"""
|
||||||
|
path = f"requisitions/{requisition_id}"
|
||||||
|
|
||||||
|
response = await self.call(
|
||||||
|
path, schema="RequisitionDelete", http_method="delete"
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button
|
<button
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
hx-delete="{# url 'aggregator_delete' type=type pk=item.id #}"
|
hx-delete="{% url 'req_delete' type=type pk=pk req_id=item.id %}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
hx-target="#modals-here"
|
hx-target="#modals-here"
|
||||||
hx-swap="innerHTML"
|
hx-swap="innerHTML"
|
||||||
|
|
|
@ -35,8 +35,8 @@ class ReqsList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
|
||||||
list_template = "partials/aggregator-info.html"
|
list_template = "partials/aggregator-info.html"
|
||||||
page_title = "Aggregator Info"
|
page_title = "Aggregator Info"
|
||||||
|
|
||||||
context_object_name_singular = "account link"
|
context_object_name_singular = "requisition"
|
||||||
context_object_name = "account links"
|
context_object_name = "requisitions"
|
||||||
|
|
||||||
list_url_name = "reqs"
|
list_url_name = "reqs"
|
||||||
list_url_args = ["type", "pk"]
|
list_url_args = ["type", "pk"]
|
||||||
|
@ -44,6 +44,11 @@ class ReqsList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
|
||||||
submit_url_name = "aggregator_countries"
|
submit_url_name = "aggregator_countries"
|
||||||
submit_url_args = ["type", "pk"]
|
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):
|
def get_queryset(self, **kwargs):
|
||||||
pk = kwargs.get("pk")
|
pk = kwargs.get("pk")
|
||||||
try:
|
try:
|
||||||
|
@ -179,6 +184,29 @@ class AggregatorLinkBank(LoginRequiredMixin, OTPRequiredMixin, View):
|
||||||
return response
|
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):
|
class AggregatorList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
|
||||||
list_template = "partials/aggregator-list.html"
|
list_template = "partials/aggregator-list.html"
|
||||||
model = Aggregator
|
model = Aggregator
|
||||||
|
|
Loading…
Reference in New Issue