Пример #1
0
def render_search_result(request, catalog, zresult=''):
    cookies = {}
    if zresult == '':
        url = catalog.url
        new_get = []
        for key in request.GET:
            if key == 'zstate': continue
            new_get.append(urlquote(key) + '=' + urlquote(request.GET[key]))

        new_get = '&'.join(new_get)

        if request.GET['zstate'] == 'action':
            url = url + '?' + new_get
        else:
            url = url + '?' + request.GET['zstate'].replace(' ', '+')

        (zresult, cookies) = zworker.request(url, cookies=request.COOKIES)
    try:
        zresults_body_element = zworker.get_body_element(zresult)
        zresults_body_element = zworker.change_form_action(zresults_body_element)

        zresults_body_element = zworker.change_links_href(zresults_body_element)
    except Exception:
        return HttpResponse(u'Некорректный url')
    result = zworker.make_html_body_content(zresults_body_element)

    response = render(request, 'zgate/search_results.html', {
        'catalog_title': catalog.title,
        'search_results': result
    })

    return  set_cookies_to_response(cookies, response)
Пример #2
0
def render_search_result(request, catalog, zresult=''):
    cookies = {}
    if zresult == '':
        url = catalog.url
        new_get = []
        for key in request.GET:
            if key == 'zstate': continue
            new_get.append(urlquote(key) + '=' + urlquote(request.GET[key]))

        new_get = '&'.join(new_get)

        if request.GET['zstate'] == 'action':
            url = url + '?' + new_get
        else:
            url = url + '?' + request.GET['zstate'].replace(' ', '+')

        (zresult, cookies) = zworker.request(url, cookies=request.COOKIES)
    try:
        zresults_body_element = zworker.get_body_element(zresult)
        zresults_body_element = zworker.change_form_action(
            zresults_body_element)

        zresults_body_element = zworker.change_links_href(
            zresults_body_element)
    except Exception:
        return HttpResponse(u'Некорректный url')
    result = zworker.make_html_body_content(zresults_body_element)

    response = render(request, 'zgate/search_results.html', {
        'catalog_title': catalog.title,
        'search_results': result
    })

    return set_cookies_to_response(cookies, response)
Пример #3
0
def render_form(request, zresult, catalog):
    zworker.entry_point = reverse("zgate_index", args=[catalog.id])
    page_body = zworker.get_body_element(zresult)
    page_body = zworker.change_links_href(page_body)
    page_body = zworker.change_form_action(page_body)
    page_body = zworker.make_html_body_content(page_body)

    return render(request, 'zgate/search_form.html',
            {'catalog_title': catalog.title,
             'search_form': page_body,
             'catalog': catalog})
Пример #4
0
def render_form(request, zresult, catalog):
    zworker.entry_point = reverse("zgate_index", args=[catalog.id])
    page_body = zworker.get_body_element(zresult)
    page_body = zworker.change_links_href(page_body)
    page_body = zworker.change_form_action(page_body)
    page_body = zworker.make_html_body_content(page_body)

    return render(
        request, 'zgate/search_form.html', {
            'catalog_title': catalog.title,
            'search_form': page_body,
            'catalog': catalog
        })
Пример #5
0
def render_detail(request, catalog):
    zvars = request.GET['zstate'].split(' ')
    zstate = request.GET['zstate'].replace(' ', '+')
    zgate_url = catalog.url

    (zresult, cookies) = zworker.request(zgate_url + '?' + zstate,
                                         cookies=request.COOKIES)
    zresults_body_element = zworker.get_body_element(zresult)
    zresults_body_element = zworker.change_links_href(zresults_body_element)

    #забираем xml представление записи
    (xml_record,
     cookies) = zworker.request(zgate_url + '?' + zstate.replace('1+F', '1+X'),
                                cookies=request.COOKIES)
    owners = []
    record_id = '0'
    st = request.GET['zstate']
    zsession = zvars[1]
    zoffset = zvars[3]
    save_document = False
    doc = None
    try:
        xml_record = ET.XML(xml_record)
        record_tree = xml_record.xpath('/record/bibliographicRecord/*')
        if record_tree:
            doc = xslt_transformer(record_tree[0])
            doc = doc_tree_to_dict(doc)


#        owners = get_document_owners(xml_record)
#        record_id = get_record_id(xml_record)
        save_document = True
    except SyntaxError as e:
        pass  #не будем добавлять держателей

    result = zworker.make_html_body_content(zresults_body_element)
    response = render(
        request,
        'zgate/search_results.html',
        {
            'doc': doc,
            'catalog_title': catalog.title,
            'search_results': result,
            #        'owners': owners,
            'record_id': record_id,
            'zsession': zsession,
            'zoffset': zoffset,
            'catalog': catalog,
            'save_document': save_document,
        })
    return set_cookies_to_response(cookies, response)
Пример #6
0
def render_detail(request, catalog):
    zvars = request.GET['zstate'].split(' ')
    zstate = request.GET['zstate'].replace(' ', '+')
    zgate_url = catalog.url

    (zresult, cookies) = zworker.request(zgate_url + '?' + zstate, cookies=request.COOKIES)
    zresults_body_element = zworker.get_body_element(zresult)
    zresults_body_element = zworker.change_links_href(zresults_body_element)

    #забираем xml представление записи
    (xml_record, cookies) = zworker.request(zgate_url + '?' + zstate.replace('1+F', '1+X'), cookies=request.COOKIES)
    owners = []
    record_id = '0'
    st = request.GET['zstate']
    zsession = zvars[1]
    zoffset = zvars[3]
    save_document = False
    doc = None
    try:
        xml_record = ET.XML(xml_record)
        record_tree = xml_record.xpath('/record/bibliographicRecord/*')
        if record_tree:
            doc = xslt_transformer(record_tree[0])
            doc = doc_tree_to_dict(doc)

        owners = get_document_owners(xml_record)

#        record_id = get_record_id(xml_record)
        save_document = True
    except SyntaxError as e:
        pass #не будем добавлять держателей
    districts = list(District.objects.all())

    result = zworker.make_html_body_content(zresults_body_element)
    response =  render(request, 'zgate/search_results.html', {
        'doc': doc,
        'catalog_title': catalog.title,
        'search_results': result,
        'owners': owners,
        'record_id': record_id,
        'zsession': zsession,
        'zoffset': zoffset,
        'catalog': catalog,
        'save_document': save_document,
        'districts': districts
    })
    return set_cookies_to_response(cookies, response)
Пример #7
0
def render_detail(request, catalog):
    zvars = request.GET['zstate'].split(' ')
    zstate = request.GET['zstate'].replace(' ', '+')
    zgate_url = catalog.url

    (zresult, cookies) = zworker.request(zgate_url + '?' + zstate, cookies=request.COOKIES)
    zresults_body_element = zworker.get_body_element(zresult)
    zresults_body_element = zworker.change_links_href(zresults_body_element)

    #забираем xml представление записи
    try:
        (xml_record, cookies) = zworker.request(zgate_url + '?' + zstate.replace('1+F', '1+X'), cookies=request.COOKIES)
    except zworker.ZWorkerError as e:
        return HttpResponse(u'Ошибка подключения к поисковому серверу: ' + str(e))
    s = time.time();
    owners = []
    record_id = '0'
    st = request.GET['zstate']
    zsession = zvars[1]
    zoffset = zvars[3]
    save_document = False
    try:
        xml_record = ET.XML(xml_record)
        owners = get_document_owners(xml_record)
        record_id = get_record_id(xml_record)
        save_document = True
    except SyntaxError as e:
        pass #не будем добавлять держателей


    result = zworker.make_html_body_content(zresults_body_element)
    response =  render(request, 'zgate/search_results.html', {
        'catalog_title': catalog.title,
        'search_results': result,
        'owners': owners,
        'record_id': record_id,
        'zsession': zsession,
        'zoffset': zoffset,
        'catalog': catalog,
        'save_document': save_document,
    })
    return set_cookies_to_response(cookies, response)