def export(request, format=None, kwargs=None): if request.method == 'GET': results = None exporter = None form = AdvancedSearchForm(request.GET) if form.is_valid(): do_search = False for item in form.cleaned_data.values(): if item: do_search = True if do_search: # print form.cleaned_data['doc_type'] # print type(form.cleaned_data['doc_type']) results = search_all(form.cleaned_data) else: return HttpResponseRedirect('/') if format: try: exporter = getattr(exporters, format) except AttributeError: raise Http404('No export format %s is available.' % format) if results: response = exporter(results) return response else: return HttpResponseRedirect('/')
def search_dmt_form(request): form = AdvancedSearchForm() announcement = None try: announcement = Announcement.objects.filter(show__exact=True).latest() except Announcement.DoesNotExist: pass return render_to_response( 'synapse/search.html', { 'form': form, 'announcement': announcement, 'show_dmt': True, 'is_internal': is_internal(request) })
def search(request): if request.GET.has_key('format') and request.GET['format']: ref = request.META['HTTP_REFERER'] start = ref.index('?') q_string = ref[start:] target = "/export/" + request.GET['format'] + "/" + q_string return HttpResponseRedirect(target) else: form = AdvancedSearchForm(request.GET) if form.is_valid(): msg = None do_search = False for item in form.cleaned_data.values(): if item and item not in [ 'Last Name, First', 'Ex: Blood', 'Ex: melanoma', '0', 'BLANK' ]: do_search = True if do_search: # results is a QuerySet results = search_all(form.cleaned_data) # print results result_count = len(results) # print result_count search_phrase, just_author = build_search_phrase(form) if results: paginator = QuerySetPaginator(results, 200) # print paginator try: result_count = paginator.count # print "Result Count: ", result_count except TypeError: # result_count = 0 if just_author: msg = u'Your search for <em>%s</em> returned no results. If this is an MSK author, please contact <a href="/comments/" alt="Synapse Comments" title="Synapse Comments">the Synapse Administrators</a>.' % search_phrase else: msg = u'Your search for <em>%s</em> returned no results. Please broaden your search and try again.' % search_phrase form = AdvancedSearchForm() return render_to_response( 'synapse/search.html', { 'form': form, 'show_dmt': False, 'is_internal': is_internal(request), 'msg': msg }) # full_uri = "/documents/search/?" # # full_uri = full_uri + request.GET.urlencode() # full_uri = request.path + '?' + request.GET.urlencode() # TODO: rip request.GET apart, rebuild new URL without the extraneous page terms new_url = {} if request.GET.has_key('author'): if request.GET['author'] != 'Last Name, First': new_url['author'] = request.GET['author'] if request.GET.has_key('journal'): if request.GET['journal'] != '': new_url['journal'] = request.GET['journal'] if request.GET.has_key('year_start'): if request.GET['year_start'] != 'BLANK': new_url['year_start'] = request.GET['year_start'] if request.GET.has_key('year_end'): if request.GET['year_end'] != 'BLANK': new_url['year_end'] = request.GET['year_end'] if request.GET.has_key('keywords'): if request.GET['keywords'] != '': new_url['keywords'] = request.GET['keywords'] if request.GET.has_key('doc_type'): new_url['doc_type'] = form.cleaned_data['doc_type'] results_page = None page = 0 if request.GET.has_key('page'): page = int(request.GET['page']) else: page = 1 results_page = paginator.page(page) previous = 0 next = 0 if page > 0: previous = results_page.number - 1 next = results_page.number + 1 # if request.GET.has_key('page'): # if request.GET['page'] != '': # new_url['page'] = request.GET['page'] # print "new_url: ", urlencode(new_url, doseq=True) full_uri = '?' + urlencode(new_url, doseq=True) context = { 'data': search_phrase, 'publications': results_page.object_list, 'pages': paginator.num_pages, 'page_range': paginator.page_range, 'page': results_page.number, 'has_next': results_page.has_next(), 'has_previous': results_page.has_previous(), 'next': next, 'previous': previous, 'uri': full_uri, 'result_count': paginator.count, 'is_internal': is_internal(request), } return render_to_response('synapse/results.html', context) else: if just_author: msg = u'Your search for <em>%s</em> returned no results. If this is an MSK author, please contact <a href="/comments/" alt="Synapse Comments" title="Synapse Comments">the Synapse Administrators</a>.' % search_phrase else: msg = u'Your search for <em>%s</em> returned no results. Please broaden your search and try again.' % search_phrase form = AdvancedSearchForm() return render_to_response( 'synapse/search.html', { 'form': form, 'show_dmt': False, 'is_internal': is_internal(request), 'msg': msg }) else: msg = u'Please enter at least one search term.' form = AdvancedSearchForm() return render_to_response( 'synapse/search.html', { 'form': form, 'show_dmt': False, 'is_internal': is_internal(request), 'msg': msg })