Example #1
0
 def test_update_q_string( self ):
     """ Tests modification of solr query string. """
     # log.warning( 'starting test' )
     initial_qstring = u'foo'
     log_identifier = u'bar'
     # no session_authz_dict
     session_authz_dict = None
     self.assertEqual(
         {'modified_qstring': u'display_status:(approved) AND foo'},
         common.updateQstring(initial_qstring, session_authz_dict, log_identifier) )
     # session_authz_dict, but no 'authorized' key
     session_authz_dict = { u'some_key': u'some_value' }
     self.assertEqual(
         {'modified_qstring': u'display_status:(approved) AND foo'},
         common.updateQstring(initial_qstring, session_authz_dict, log_identifier) )
     # session_authz_dict, and 'authorized' key, but authorized not True
     session_authz_dict = { u'authorized': u'other_than_true' }
     self.assertEqual(
         {'modified_qstring': u'display_status:(approved) AND foo'},
         common.updateQstring(initial_qstring, session_authz_dict, log_identifier) )
     # life good
     session_authz_dict = { u'authorized': True }
     self.assertEqual(
         {'modified_qstring': u'foo'},
         common.updateQstring(initial_qstring, session_authz_dict, log_identifier) )
Example #2
0
    def _get_results_context(request, log_id):
        """ Returns correct context for POST.
            Called by results() """
        log.debug('starting')
        context = {}
        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))
            log.debug('context, ```%s```' % pprint.pformat(context))
            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
        log.debug('context.keys(), ```%s```' %
                  pprint.pformat(sorted(context.keys())))
        log.debug('type(context), `%s`' % type(context))

        # results = context['iipResult']
        # log.debug( 'type(results), `%s`' % type(results) )
        # for (i, result) in enumerate(results.object_list):
        #     log.debug( 'type(result), `%s`' % type(result) )
        #     log.debug( 'result, `%s`' % result )
        #     if i > 0:
        #         break
        #     1/0

        # print("get_results_context: ", context)

        return context
Example #3
0
 def _get_ajax_unistring(request):
     """ Returns unicode string based on ajax update.
         Called by results() """
     log_id = common.get_log_identifier(request.session)
     log.info('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/old_results.html', u'content', context)
     return unicode(return_str)