Example #1
0
 def test_update_q_string(self):
     """ Tests modification of solr query string. """
     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
File: views.py Project: crotger/iip
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
Example #3
0
File: views.py Project: crotger/iip
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 )
Example #4
0
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
Example #5
0
 def test_update_q_string( self ):
     """ Tests modification of solr query string. """
     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 #6
0
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)
Example #7
0
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