mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Dedupe generic search logic
This commit is contained in:
@@ -40,10 +40,6 @@ class SupplierForm(forms.ModelForm):
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class SupplierSearchForm(forms.Form):
|
||||
query = forms.CharField(required=False)
|
||||
|
||||
|
||||
class CableTypeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = models.CableType
|
||||
|
||||
@@ -14,6 +14,7 @@ from django.utils.decorators import method_decorator
|
||||
from django.views import generic
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from versioning import versioning
|
||||
from PyRIGS.views import GenericListView
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, name='dispatch')
|
||||
@@ -205,36 +206,11 @@ class AssetAudit(AssetEdit):
|
||||
return super().get_success_url()
|
||||
|
||||
|
||||
class SupplierList(generic.ListView):
|
||||
class SupplierList(GenericListView):
|
||||
model = models.Supplier
|
||||
template_name = 'supplier_list.html'
|
||||
paginate_by = 40
|
||||
ordering = ['name']
|
||||
|
||||
def get_queryset(self):
|
||||
if self.request.method == 'POST':
|
||||
self.form = forms.SupplierSearchForm(data=self.request.POST)
|
||||
elif self.request.method == 'GET':
|
||||
self.form = forms.SupplierSearchForm(data=self.request.GET)
|
||||
else:
|
||||
self.form = forms.SupplierSearchForm(data={})
|
||||
form = self.form
|
||||
if not form.is_valid():
|
||||
return self.model.objects.none()
|
||||
|
||||
query_string = form.cleaned_data['query'] or ""
|
||||
if len(query_string) == 0:
|
||||
queryset = self.model.objects.all()
|
||||
else:
|
||||
queryset = self.model.objects.filter(Q(name__icontains=query_string))
|
||||
|
||||
return queryset
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(SupplierList, self).get_context_data(**kwargs)
|
||||
context["form"] = self.form
|
||||
return context
|
||||
|
||||
|
||||
class SupplierSearch(SupplierList):
|
||||
hide_hidden_status = False
|
||||
|
||||
Reference in New Issue
Block a user