Exemplo n.º 1
0
def iip_results_z(request):
    """ Handles /search_zotero/ GET, POST, and ajax-GET. """
    log_id = common.get_log_identifier(request.session)
    log.info(u'in iip_results_z(); id, %s; starting' % log_id)
    if not u'authz_info' in request.session:
        request.session[u'authz_info'] = {u'authorized': False}
    if request.method == u'POST':  # form has been submitted by user
        log.debug('POST, search-form was submitted by user')
        request.encoding = u'utf-8'
        form = forms.SearchForm(request.POST)
        if not form.is_valid():
            return HttpResponseRedirect(
                u'%s://%s%s?q=*:*' %
                (request.META[u'wsgi.url_scheme'], request.get_host(),
                 reverse(u'results_url')))
        qstring = form.generateSolrQuery()
        # e.g. http://library.brown.edu/cds/projects/iip/results?q=*:*
        redirect_url = u'%s://%s%s?q=%s' % (request.META[u'wsgi.url_scheme'],
                                            request.get_host(),
                                            reverse(u'results_url'), qstring)

        return HttpResponseRedirect(redirect_url)
    if request.method == u'GET' and request.GET.get(u'q', None) != None:
        log.debug('GET, show search-form')
        return render(request, u'iip_search_templates/base_zotero.html',
                      _get_POST_context(request, log_id))
    elif request.is_ajax():  # user has requested another page, a facet, etc.
        log.debug('request.is_axax() is True')
        return HttpResponse(_get_ajax_unistring(request))
    else:  # regular GET
        return render(request, u'iip_search_templates/search_form_zotero.html',
                      _get_GET_context(request, log_id))
Exemplo n.º 2
0
Arquivo: views.py Projeto: crotger/iip
def iip_results_z( request ):
    """ Handles /search_zotero/ GET, POST, and ajax-GET. """
    log_id = common.get_log_identifier( request.session )
    log.info( u'in iip_results_z(); id, %s; starting' % log_id )
    if not u'authz_info' in request.session:
        request.session[u'authz_info'] = { u'authorized': False }
    if request.method == u'POST': # form has been submitted by user
        log.debug( 'POST, search-form was submitted by user' )
        request.encoding = u'utf-8'
        form = forms.SearchForm(request.POST)
        if not form.is_valid():
            return HttpResponseRedirect( u'%s://%s%s?q=*:*' % (request.META[u'wsgi.url_scheme'], request.get_host(), reverse(u'results_url')) )
        qstring = form.generateSolrQuery()
        # e.g. http://library.brown.edu/cds/projects/iip/results?q=*:*
        redirect_url = u'%s://%s%s?q=%s' % (request.META[u'wsgi.url_scheme'], request.get_host(), reverse(u'results_url'), qstring)

        return HttpResponseRedirect( redirect_url )
    if request.method == u'GET' and request.GET.get(u'q', None):
        log.debug( 'GET, show search-form' )
        return render( request, u'iip_search_templates/base_zotero.html', _get_POST_context(request, log_id) )
    elif request.is_ajax():  # user has requested another page, a facet, etc.
        log.debug( 'request.is_axax() is True' )
        return HttpResponse( _get_ajax_unistring(request) )
    else:  # regular GET
        return render( request, u'iip_search_templates/search_form_zotero.html', _get_GET_context(request, log_id) )
Exemplo n.º 3
0
Arquivo: views.py Projeto: crotger/iip
def _setup_viewinscr( request ):
    """ Takes request;
            updates session with authz_info and log_id;
            returns log_id.
        Called by viewinscr() """
    log.debug( u'in _setup_viewinscr(); starting' )
    if not u'authz_info' in request.session:
        request.session[u'authz_info'] = { u'authorized': False }
    log_id = common.get_log_identifier( request.session )
    return log_id
Exemplo n.º 4
0
def _setup_viewinscr(request):
    """ Takes request;
            updates session with authz_info and log_id;
            returns log_id.
        Called by viewinscr() """
    log.debug(u'in _setup_viewinscr(); starting')
    if not u'authz_info' in request.session:
        request.session[u'authz_info'] = {u'authorized': False}
    log_id = common.get_log_identifier(request.session)
    return log_id
Exemplo n.º 5
0
Arquivo: views.py Projeto: 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 )
Exemplo n.º 6
0
Arquivo: views.py Projeto: crotger/iip
def login( request ):
    """ Takes shib-eppn or 'dev_auth_hack' parameter (if enabled for non-shibbolized development) and checks it agains settings list of LEGIT_ADMINS. """
    ## init
    log_id = common.get_log_identifier( request.session )
    log.info( u'in login(); id, %s; starting' % log_id )
    request.session['authz_info'] = { 'authorized': False }
    ## checks
    if _check_shib( request, log_id ) == False:
        _check_dev_auth_hack( request, log_id )
    ## response
    response = _make_response( request, log_id )
    return response
Exemplo n.º 7
0
Arquivo: views.py Projeto: crotger/iip
def _prepare_viewinscr_get_data( request, inscrid ):
    """ Prepares data for regular or ajax GET.
            Returns a tuple of vars.
        Called by viewinscr(). """
    log.debug( u'in _prepare_viewinscr_get_data(); starting' )
    log_id = common.get_log_identifier( request.session )
    q = _call_viewinsc_solr( inscrid )
    current_display_status = _update_viewinscr_display_status( request, q )
    ( bibs, bibDip, bibTsc, bibTrn ) = _get_bib_data( q.results )
    view_xml_url = u'%s://%s%s' % (  request.META[u'wsgi.url_scheme'],  request.get_host(),  reverse(u'xml_url', kwargs={u'inscription_id':inscrid})  )
    current_url = u'%s://%s%s' % (  request.META[u'wsgi.url_scheme'],  request.get_host(),  reverse(u'inscription_url_zotero', kwargs={u'inscrid':inscrid})  )
    return ( q, bibs, bibDip, bibTsc, bibTrn, current_display_status, view_xml_url, current_url )
Exemplo n.º 8
0
def login(request):
    """ Takes shib-eppn or 'dev_auth_hack' parameter (if enabled for non-shibbolized development) and checks it agains settings list of LEGIT_ADMINS. """
    ## init
    log_id = common.get_log_identifier(request.session)
    log.info(u'in login(); id, %s; starting' % log_id)
    request.session['authz_info'] = {'authorized': False}
    ## checks
    if _check_shib(request, log_id) == False:
        _check_dev_auth_hack(request, log_id)
    ## response
    response = _make_response(request, log_id)
    return response
Exemplo n.º 9
0
def iip_results_z( request ):
    """ Handles /search_zotero/ GET, POST, and ajax-GET. """
    log_id = common.get_log_identifier( request.session )
    log.info( u'in iip_results_z(); id, %s; starting' % log_id )
    if not u'authz_info' in request.session:
        request.session[u'authz_info'] = { u'authorized': False }
    if request.method == u'POST':  # form has been submitted by user
        return render( request, u'iip_search_templates/base_zotero.html', _get_POST_context(request, log_id) )
    elif request.is_ajax():  # user has requested another page, a facet, etc.
        return HttpResponse( _get_ajax_unistring(request) )
    else:  # regular GET
        return render( request, u'iip_search_templates/search_form_zotero.html', _get_GET_context(request, log_id) )
Exemplo n.º 10
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
Exemplo n.º 11
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)
Exemplo n.º 12
0
def _prepare_viewinscr_get_data(request, inscrid):
    """ Prepares data for regular or ajax GET.
            Returns a tuple of vars.
        Called by viewinscr(). """
    log.debug(u'in _prepare_viewinscr_get_data(); starting')
    log_id = common.get_log_identifier(request.session)
    q = _call_viewinsc_solr(inscrid)
    current_display_status = _update_viewinscr_display_status(request, q)
    (bibs, bibDip, bibTsc, bibTrn) = _get_bib_data(q.results)
    view_xml_url = u'%s://%s%s' % (
        request.META[u'wsgi.url_scheme'], request.get_host(),
        reverse(u'xml_url', kwargs={u'inscription_id': inscrid}))
    current_url = u'%s://%s%s' % (
        request.META[u'wsgi.url_scheme'], request.get_host(),
        reverse(u'inscription_url_zotero', kwargs={u'inscrid': inscrid}))
    return (q, bibs, bibDip, bibTsc, bibTrn, current_display_status,
            view_xml_url, current_url)
Exemplo n.º 13
0
def _z_prepare_viewinscr_get_data(request, inscrid):
    """ Prepares data for regular or ajax GET.
            Returns a tuple of vars.
        Called by viewinscr(). """
    log.debug(u'in _z_prepare_viewinscr_get_data(); starting')
    log_id = common.get_log_identifier(request.session)
    q = _call_viewinsc_solr(
        inscrid
    )  # The results of the solr query to find the inscription. q.results is list of dictionaries of values.
    current_display_status = _update_viewinscr_display_status(request, q)
    z_bibids_initial = [
        x.replace(".xml", "").replace("bibl=",
                                      "").replace("nType=",
                                                  "").replace("n=", "")
        for x in q.results[0]['bibl']
    ]
    z_bibids = {}
    for entry in z_bibids_initial:
        bibid, ntype, n = entry.split("|")
        if (not bibid in z_bibids):
            z_bibids[bibid] = []
        if (not (ntype, n) in z_bibids[bibid]):
            z_bibids[bibid].append((ntype, n))
    specific_sources = dict()
    specific_sources['transcription'] = q.results[0]['biblTranscription'][
        0] if 'biblTranscription' in q.results[0] else ""
    specific_sources['translation'] = q.results[0]['biblTranslation'][
        0] if 'biblTranslation' in q.results[0] else ""
    specific_sources['diplomatic'] = q.results[0]['biblDiplomatic'][
        0] if 'biblDiplomatic' in q.results[0] else ""

    view_xml_url = u'%s://%s%s' % (
        request.META[u'wsgi.url_scheme'], request.get_host(),
        reverse(u'xml_url', kwargs={u'inscription_id': inscrid}))
    current_url = u'%s://%s%s' % (
        request.META[u'wsgi.url_scheme'], request.get_host(),
        reverse(u'inscription_url_zotero', kwargs={u'inscrid': inscrid}))
    return (q, z_bibids, specific_sources, current_display_status,
            view_xml_url, current_url)
Exemplo n.º 14
0
Arquivo: views.py Projeto: crotger/iip
def _z_prepare_viewinscr_get_data (request, inscrid):
    """ Prepares data for regular or ajax GET.
            Returns a tuple of vars.
        Called by viewinscr(). """
    log.debug( u'in _z_prepare_viewinscr_get_data(); starting' )
    log_id = common.get_log_identifier( request.session )
    q = _call_viewinsc_solr( inscrid )  # The results of the solr query to find the inscription. q.results is list of dictionaries of values.
    current_display_status = _update_viewinscr_display_status( request, q )
    z_bibids_initial = [x.replace(".xml", "").replace("bibl=", "").replace("nType=", "").replace("n=", "") for x in q.results[0]['bibl']]
    z_bibids = {}
    for entry in z_bibids_initial:
        bibid, ntype, n = entry.split("|")
        if(not bibid in z_bibids):
            z_bibids[bibid] = []
        if(not (ntype, n) in z_bibids[bibid]):
            z_bibids[bibid].append((ntype, n))
    specific_sources = dict()
    specific_sources['transcription'] = q.results[0]['biblTranscription'][0] if 'biblTranscription' in q.results[0] else ""
    specific_sources['translation'] = q.results[0]['biblTranslation'][0] if 'biblTranslation' in q.results[0] else ""
    specific_sources['diplomatic'] = q.results[0]['biblDiplomatic'][0] if 'biblDiplomatic' in q.results[0] else ""

    view_xml_url = u'%s://%s%s' % (  request.META[u'wsgi.url_scheme'],  request.get_host(),  reverse(u'xml_url', kwargs={u'inscription_id':inscrid})  )
    current_url = u'%s://%s%s' % (  request.META[u'wsgi.url_scheme'],  request.get_host(),  reverse(u'inscription_url_zotero', kwargs={u'inscrid':inscrid})  )
    return ( q, z_bibids, specific_sources, current_display_status, view_xml_url, current_url )
Exemplo n.º 15
0
Arquivo: views.py Projeto: 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
Exemplo n.º 16
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