mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Refactor search logic to a create an 'omnisearch' (#484)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user