Věřte si.... 😉 Vašek. J
Odesláno z mého telefonu Huawei
Odesláno z mého telefonu Huawei
-------- Původní zpráva --------
Od: RANGA BHARATH JINKA <bharathjink...@gmail.com>
Datum: so 29. srp 2020 5:00
Komu: django-users@googlegroups.com
Předmět: Re: NoReverseMatch at /searchlit/customsearch and bigger problem of exporting a filtered queryset
--On Sat, 29 Aug 2020, 8:25 am RANGA BHARATH JINKA, <bharathjink...@gmail.com> wrote:Hi,Use jQuery datatable for this. It is easy to use and has inbuilt search and export to CSV, Excel options also.On Sat, 29 Aug 2020, 7:54 am RANGA BHARATH JINKA, <bharathjink...@gmail.com> wrote:On Sat, 29 Aug 2020, 7:33 am RANGA BHARATH JINKA, <bharathjink...@gmail.com> wrote:Hi,Please check this package. This may help you. All the bestOn Sat, 29 Aug 2020, 4:36 am Patrick Carra, <pcarra...@gmail.com> wrote:Hello All! I need some help with a problem I have been struggling with. One of you generous geniuses has the answer I'm sure of it. I am working on integrating an export to csv button(link) on my template to export filtered data from one of my tables. I have previously only been able to dump the entire table to csv which isn't exactly what I need. So my thoughts were to place a button/link on the template passes a parameter(dictionary of my filter criteria) to a view named ExportSearch. The view then calls a function that I have defined to perform my filtered query to the table and then writes outs to csv. In theory I thought this should work but I keep getting errors that I have not been able to resolve and I am at the end of my knowledge capacity here. Applicable code below. Did I mention THANK YOU!!!!From searchLit/urls.pyfrom django.urls import include, pathfrom . import viewsfrom .views import searchapp_name= "searchLit"urlpatterns=[path('customsearch/', views.search, name='search'),path('customsearch/<str:params>/', views.search, name='search'),path('noccustomsearch/', views.nocSearch, name='nocSearch'),path('nocreport/export/', views.noc_export, name='noc_export'),path('customsearch/export/', views.searchLit_export, name='SearchLit_export'),path('customsearch/exportSearch/<str:params>/', views.exportSearch, name='exportSearch'),]From searchLit/views.pydef filterCircuits(params, search_vector):circuits=[]if(params['circuitid']==None and params['bandwidth']==None and params['region']==None and params['carrier']==None and params['status']==None and params['segmentname']==None and params['mrcnew']==None):circuits=Circuitinfotable.objects.all()else:if(params['multipleSearch']!=None and params['multipleSearch']!=""):circuits=Circuitinfotable.objects.annotate(search=search_vector).filter(search=params['multipleSearch'])else:circuits = Circuitinfotable.objects.all()if(params['circuitid']!=None and params['circuitid']!=""):circuits = Circuitinfotable.objects.all()circuits=circuits.filter(circuitid__icontains=params['circuitid'])if(params['bandwidth']!=None and params['bandwidth']!="" and params['bandwidth']!='Select Bandwidth'):circuits=circuits.filter(bandwidth=params['bandwidth'])if(params['region']!=None and params['region']!="" and params['region']!='Select Region'):circuits=circuits.filter(region=params['region'])if(params['carrier']!=None and params['carrier']!="" and params['carrier']!='Select Carrier'):circuits=circuits.filter(carrier=params['carrier'])if(params['status']!=None and params['status']!="" and params['status']!='Select Status'):circuits=circuits.filter(status=params['status'])if(params['segmentname']!=None and params['segmentname']!="" and params['segmentname']!='Select Segment'):circuits=circuits.filter(segmentname=params['segmentname'])if(params['mrcnew']!=None and params['mrcnew']!=""):circuits=circuits.filter(mrcnew=params['mrcnew'])if(params['diversity']!='Select Option'):if(params['diversity']=='None'):circuits=circuits.filter(diversity=None)else:circuits=circuits.filter(diversity__icontains=params['diversity'])if(params['kmz']!='Select YES/NO'):if(params['kmz']=='No'):circuits=circuits.filter(kmz=None)else:circuits=circuits.filter(kmz__isnull=False)return(circuits)def search(request):form = CircuitFormtemplate = 'customsearch/customsearch.html'search_vector = SearchVector('circuitid', 'carrier', 'pathname', 'segmentname', 'segmentid', 'alocationaddress', 'alocationcity', 'alocst', 'zlocationaddress', 'zlocationcity', 'zlocst', 'handoffalocaddress', 'handoffalocst','handoffaloccity', 'handoffzlocaddress', 'handoffzloccity', 'handoffzlocst', 'latestjiraticket', 'installciopsticket', 'retermciopsticket', 'discociopsticket', 'notes', 'diversitynotes')params={'circuitid': request.GET.get('circuitid'),'bandwidth': request.GET.get('bandwidth'),'region': request.GET.get('region'),'carrier': request.GET.get('carrier'),'status': request.GET.get('status'),'segmentname': request.GET.get('segmentname'),'mrcnew': request.GET.get('mrcnew'),'diversity': request.GET.get('diversity'),'kmz': request.GET.get('kmz'),'multipleSearch': request.GET.get('multipleSearch')}context=filterCircuits(params, search_vector)#encoded_params = urllib.parse.urlencode(params)numCircuits=len(context)paramString = str(params)return render(request, template, {'form':form, 'filter':context, 'numcircuits':numCircuits, 'params':params, 'paramString': paramString})def exportSearch(request, params):params = ast.literal_eval(params)search_vector = SearchVector('circuitid', 'carrier', 'pathname', 'segmentname', 'segmentid', 'alocationaddress', 'alocationcity', 'alocst', 'zlocationaddress', 'zlocationcity', 'zlocst', 'handoffalocaddress', 'handoffalocst','handoffaloccity', 'handoffzlocaddress', 'handoffzloccity', 'handoffzlocst', 'latestjiraticket', 'installciopsticket', 'retermciopsticket', 'discociopsticket', 'notes', 'diversitynotes')allcircuits=filterCircuits(params, search_vector)return render_to_csv_response(allcircuits)From template(button/link placed outside of form to capture filters called paramString)<a href="" url 'exportSearch' paramString %}"><input type="button" value="Self Destruct" /></a>--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bbf5ec72-955d-4d52-9c43-b00d0b17551dn%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK5m314c70aUrvtuzmFFPwtNaUZdj8GN4yA-K-dh5pfqH4M6mg%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/j1drc9ot4cbn9st33-d09zjo-pp2xfekua2p2-ra1ks5a39bod-cgnx74-5kqrod93hfzw-q7u6j4-egvrhw-ugxxsprfaj04-vd5llg-x5hu09pgabfzuy1r2n-rb2fg2931c9mfi6j12-qiocxy-vz0wr5.1598672458598%40email.android.com.