Refactor asset search to use SecureAPIRequest

Closes #474 and #465
This commit is contained in:
2022-01-19 19:02:35 +00:00
parent 9e1d54dc02
commit ce83ae6dd1
7 changed files with 30 additions and 100 deletions

View File

@@ -87,28 +87,10 @@ class AssetList(LoginRequiredMixin, generic.ListView):
return context
class AssetSearch(AssetList):
hide_hidden_status = False
def render_to_response(self, context, **response_kwargs):
result = []
for asset in context["object_list"]:
result.append({"id": asset.pk, "label": (asset.asset_id + " | " + asset.description)})
return JsonResponse(result, safe=False)
class AssetIDUrlMixin:
def get_object(self, queryset=None):
pk = self.kwargs.get(self.pk_url_kwarg)
queryset = models.Asset.objects.filter(asset_id=pk)
try:
# Get the single item from the filtered queryset
obj = queryset.get()
except queryset.model.DoesNotExist:
raise Http404("No assets found matching the query")
return obj
return get_object_or_404(models.Asset, asset_id=pk)
class AssetDetail(LoginRequiredMixin, AssetIDUrlMixin, generic.DetailView):
@@ -194,7 +176,6 @@ class AssetOEmbed(OEmbedView):
class AssetAuditList(AssetList):
template_name = 'asset_audit_list.html'
hide_hidden_status = False
# TODO Refresh this when the modal is submitted
def get_queryset(self):
@@ -242,17 +223,6 @@ class SupplierList(GenericListView):
return context
class SupplierSearch(SupplierList):
hide_hidden_status = False
def render_to_response(self, context, **response_kwargs):
result = []
for supplier in context["object_list"]:
result.append({"id": supplier.pk, "name": supplier.name})
return JsonResponse(result, safe=False)
class SupplierDetail(GenericDetailView):
model = models.Supplier