Refactor search logic to a create an 'omnisearch' (#484)

This commit is contained in:
2022-02-08 15:01:01 +00:00
committed by GitHub
parent 3e1e0079d8
commit 54c90a7be4
19 changed files with 290 additions and 164 deletions

View File

@@ -50,13 +50,7 @@ class AssetList(LoginRequiredMixin, generic.ListView):
# TODO Feedback to user when search fails
query_string = form.cleaned_data['q'] or ""
if len(query_string) == 0:
queryset = self.model.objects.all()
elif len(query_string) >= 3:
queryset = self.model.objects.filter(
Q(asset_id__exact=query_string.upper()) | Q(description__icontains=query_string) | Q(serial_number__exact=query_string))
else:
queryset = self.model.objects.filter(Q(asset_id__exact=query_string.upper()))
queryset = models.Asset.objects.search(query=query_string)
if form.cleaned_data['is_cable']:
queryset = queryset.filter(is_cable=True)
@@ -176,6 +170,7 @@ class AssetOEmbed(OEmbedView):
class AssetAuditList(AssetList):
template_name = 'asset_audit_list.html'
hide_hidden_status = True
# TODO Refresh this when the modal is submitted
def get_queryset(self):
@@ -388,12 +383,14 @@ class GenerateLabels(generic.View):
base64_encoded_result_str = base64_encoded_result_bytes.decode('ascii')
images.append(base64_encoded_result_str)
name = f"Asset Label Sheet generated at {timezone.now()}"
context = {
'images0': images[::4],
'images1': images[1::4],
'images2': images[2::4],
'images3': images[3::4],
'filename': "Asset Label Sheet generated at {}".format(timezone.now())
'filename': name
}
merger = PdfFileMerger()
@@ -405,6 +402,6 @@ class GenerateLabels(generic.View):
merged = BytesIO()
merger.write(merged)
response['Content-Disposition'] = 'filename="{}"'.format(context['filename'])
response['Content-Disposition'] = f'filename="{name}"'
response.write(merged.getvalue())
return response