def _get_POST_context( request, log_id ): """ Returns correct context for POST. Called by iip_results() """ log.debug( '_get_POST_context() starting' ) request.encoding = u'utf-8' form = forms.SearchForm( request.POST ) # form bound to the POST data resultsPage = 1 qstring_provided = None if request.method == u'GET': qstring_provided = request.GET.get("q", None) resultsPage = int(request.GET.get('resultsPage', resultsPage)) if form.is_valid() or qstring_provided: initial_qstring = "" if qstring_provided: initial_qstring = qstring_provided else: initial_qstring = form.generateSolrQuery() updated_qstring = common.updateQstring( initial_qstring=initial_qstring, session_authz_dict=request.session['authz_info'], log_id=common.get_log_identifier(request.session) )['modified_qstring'] context = common.paginateRequest( qstring=updated_qstring, resultsPage=resultsPage, log_id=common.get_log_identifier(request.session) ) context[u'session_authz_info'] = request.session[u'authz_info'] context[u'admin_links'] = common.make_admin_links( session_authz_dict=request.session[u'authz_info'], url_host=request.get_host(), log_id=log_id ) context[u'initial_qstring'] = initial_qstring return context
def test_paginateRequest( self ): """ Checks data returned by paginateRequest. """ sent_qstring = u'display_status:(approved) AND language:(Aramaic)' sent_results_page = 3 data = common.paginateRequest( qstring=sent_qstring, resultsPage=sent_results_page, log_id=u'123' ) self.assertEqual( [u'dispQstring', u'facets', u'iipResult', u'pages', u'qstring', u'resultsPage'], sorted( data.keys() ) ) self.assertEqual( u'display status:approved AND language:Aramaic', data[u'dispQstring'] ) self.assertEqual( [u'city', u'language', u'physical_type', u'region', u'religion', u'type'], sorted( data[u'facets'].keys() ) ) self.assertEqual( True, u'<solr.paginator.SolrPage instance' in unicode(repr(data[u'iipResult'])) ) self.assertEqual( sent_qstring, data[u'qstring'] ) self.assertEqual( True, u'<solr.paginator.SolrPaginator instance' in unicode(repr(data[u'pages'])) ) self.assertEqual( sent_results_page, data[u'resultsPage'] )
def _get_ajax_unistring( request ): """ Returns unicode string based on ajax update. Called by iip_results() """ log_id = common.get_log_identifier(request.session) log.info( u'in views._get_ajax_unistring(); id, %s; starting' % log_id ) initial_qstring = request.GET.get( u'qstring', u'*:*' ) updated_qstring = common.updateQstring( initial_qstring, request.session[u'authz_info'], log_id )[u'modified_qstring'] resultsPage = int( request.GET[u'resultsPage'] ) context = common.paginateRequest( qstring=updated_qstring, resultsPage=resultsPage, log_id=log_id ) return_str = ajax_snippet.render_block_to_string(u'iip_search_templates/base_zotero.html', u'content', context) return unicode( return_str )
def _get_POST_context( request, log_id ): """ Returns correct context for POST. Called by iip_results() """ request.encoding = u'utf-8' form = SearchForm( request.POST ) # form bound to the POST data if form.is_valid(): initial_qstring = form.generateSolrQuery() resultsPage = 1 updated_qstring = common.updateQstring( initial_qstring=initial_qstring, session_authz_dict=request.session['authz_info'], log_id=common.get_log_identifier(request.session) )['modified_qstring'] context = common.paginateRequest( qstring=updated_qstring, resultsPage=resultsPage, log_id=common.get_log_identifier(request.session) ) context[u'session_authz_info'] = request.session[u'authz_info'] context[u'admin_links'] = common.make_admin_links( session_authz_dict=request.session[u'authz_info'], url_host=request.get_host(), log_id=log_id ) return context
def _get_ajax_unistring(request): """ Returns unicode string based on ajax update. Called by iip_results() """ log_id = common.get_log_identifier(request.session) log.info(u'in views._get_ajax_unistring(); id, %s; starting' % log_id) initial_qstring = request.GET.get(u'qstring', u'*:*') updated_qstring = common.updateQstring(initial_qstring, request.session[u'authz_info'], log_id)[u'modified_qstring'] resultsPage = int(request.GET[u'resultsPage']) context = common.paginateRequest(qstring=updated_qstring, resultsPage=resultsPage, log_id=log_id) return_str = ajax_snippet.render_block_to_string( u'iip_search_templates/base_zotero.html', u'content', context) return unicode(return_str)
def test_paginateRequest(self): """ Checks data returned by paginateRequest. """ sent_qstring = u'display_status:(approved) AND language:(Aramaic)' sent_results_page = 3 data = common.paginateRequest(qstring=sent_qstring, resultsPage=sent_results_page, log_id=u'123') self.assertEqual([ u'dispQstring', u'facets', u'iipResult', u'pages', u'qstring', u'resultsPage' ], sorted(data.keys())) self.assertEqual(u'display status:approved AND language:Aramaic', data[u'dispQstring']) self.assertEqual([ u'city', u'language', u'physical_type', u'region', u'religion', u'type' ], sorted(data[u'facets'].keys())) self.assertEqual(sent_qstring, data[u'qstring']) self.assertEqual( True, u'<solr.paginator.SolrPaginator instance' in unicode(repr(data[u'pages']))) self.assertEqual(sent_results_page, data[u'resultsPage'])
def _get_POST_context(request, log_id): """ Returns correct context for POST. Called by iip_results() """ log.debug('_get_POST_context() starting') request.encoding = u'utf-8' form = forms.SearchForm(request.POST) # form bound to the POST data resultsPage = 1 qstring_provided = None if request.method == u'GET': qstring_provided = request.GET.get("q", None) resultsPage = int(request.GET.get('resultsPage', resultsPage)) if form.is_valid() or qstring_provided: initial_qstring = "" if qstring_provided: initial_qstring = qstring_provided else: initial_qstring = form.generateSolrQuery() updated_qstring = common.updateQstring( initial_qstring=initial_qstring, session_authz_dict=request.session['authz_info'], log_id=common.get_log_identifier( request.session))['modified_qstring'] context = common.paginateRequest(qstring=updated_qstring, resultsPage=resultsPage, log_id=common.get_log_identifier( request.session)) context[u'session_authz_info'] = request.session[u'authz_info'] context[u'admin_links'] = common.make_admin_links( session_authz_dict=request.session[u'authz_info'], url_host=request.get_host(), log_id=log_id) context[u'initial_qstring'] = initial_qstring return context