def page_ocr_txt(request, lccn, date, edition, sequence): title, issue, page = _get_tip(lccn, date, edition, sequence) try: text = page.ocr.text return HttpResponse(text, content_type='text/plain') except models.OCR.DoesNotExist: raise Http404("No OCR for %s" % page)
def page_json(request, lccn, date, edition, sequence): title, issue, page = _get_tip(lccn, date, edition, sequence) host = request.get_host() if page: return HttpResponse(page.json(host=host), content_type='application/json') else: return HttpResponseNotFound()
def page_ocr(request, lccn, date, edition, sequence): title, issue, page = _get_tip(lccn, date, edition, sequence) page_title = "%s, %s, %s" % (label(title), label(issue), label(page)) crumbs = create_crumbs(title, issue, date, edition, page) host = request.get_host() return render_to_response('page_text.html', dictionary=locals(), context_instance=RequestContext(request))
def issue_pages_rdf(request, lccn, date, edition): title, issue, page = _get_tip(lccn, date, edition) graph = issue_to_graph(issue) response = HttpResponse(graph.serialize(base=_rdf_base(request), include_base=True), content_type='application/rdf+xml') return response
def page(request, lccn, date, edition, sequence, words=None): fragments = [] if words: fragments.append("words=" + words) qs = request.META.get('QUERY_STRING') if qs: fragments.append(qs) if fragments: path_parts = dict(lccn=lccn, date=date, edition=edition, sequence=sequence) url = urlresolvers.reverse('openoni_page', kwargs=path_parts) return HttpResponseRedirect(url + "#" + "&".join(fragments)) title, issue, page = _get_tip(lccn, date, edition, sequence) if not page.jp2_filename: notes = page.notes.filter(type="noteAboutReproduction") num_notes = notes.count() if num_notes >= 1: explanation = notes[0].text else: explanation = "" # if no word highlights were requests, see if the user came # from search engine results and attempt to highlight words from their # query by redirecting to a url that has the highlighted words in it if not words: try: words = _search_engine_words(request) words = '+'.join(words) if len(words) > 0: path_parts = dict(lccn=lccn, date=date, edition=edition, sequence=sequence, words=words) url = urlresolvers.reverse('openoni_page_words', kwargs=path_parts) return HttpResponseRedirect(url) except Exception, e: if settings.DEBUG: raise e
def page_ocr_xml(request, lccn, date, edition, sequence): title, issue, page = _get_tip(lccn, date, edition, sequence) return _stream_file(page.ocr_abs_filename, 'application/xml')
def page_jp2(request, lccn, date, edition, sequence): title, issue, page = _get_tip(lccn, date, edition, sequence) return _stream_file(page.jp2_abs_filename, 'image/jp2')
def page_pdf(request, lccn, date, edition, sequence): title, issue, page = _get_tip(lccn, date, edition, sequence) return _stream_file(page.pdf_abs_filename, 'application/pdf')
def page_ocr(request, lccn, date, edition, sequence): title, issue, page = _get_tip(lccn, date, edition, sequence) page_title = "%s, %s, %s" % (label(title), label(issue), label(page)) crumbs = create_crumbs(title, issue, date, edition, page) host = request.get_host() return render(request, 'page_text.html', locals())
def page(request, lccn, date, edition, sequence, words=None): fragments = [] if words: fragments.append("words=" + words) qs = request.META.get('QUERY_STRING') if qs: fragments.append(qs) if fragments: path_parts = dict(lccn=lccn, date=date, edition=edition, sequence=sequence) url = urls.reverse('openoni_page', kwargs=path_parts) return HttpResponseRedirect(url + "#" + "&".join(fragments)) title, issue, page = _get_tip(lccn, date, edition, sequence) if not page.jp2_filename: notes = page.notes.filter(type="noteAboutReproduction") num_notes = notes.count() if num_notes >= 1: explanation = notes[0].text else: explanation = "" # if no word highlights were requests, see if the user came # from search engine results and attempt to highlight words from their # query by redirecting to a url that has the highlighted words in it if not words: try: words = _search_engine_words(request) words = '+'.join(words) if len(words) > 0: path_parts = dict(lccn=lccn, date=date, edition=edition, sequence=sequence, words=words) url = urls.reverse('openoni_page_words', kwargs=path_parts) return HttpResponseRedirect(url) except Exception as e: if settings.DEBUG: raise e # else squish the exception so the page will still get # served up minus the highlights # Calculate the previous_issue_first_page. Note: it was decided # that we want to skip over issues with missing pages. See ticket # #383. _issue = issue while True: previous_issue_first_page = None _issue = _issue.previous if not _issue: break previous_issue_first_page = _issue.first_page if previous_issue_first_page: break # do the same as above but for next_issue this time. _issue = issue while True: next_issue_first_page = None _issue = _issue.next if not _issue: break next_issue_first_page = _issue.first_page if next_issue_first_page: break page_title = "%s, %s, %s" % (label(title), label(issue), label(page)) page_head_heading = "%s, %s, %s" % (title.display_name, label(issue), label(page)) page_head_subheading = label(title) crumbs = create_crumbs(title, issue, date, edition, page) filename = page.jp2_abs_filename if filename: try: im = os.path.getsize(filename) image_size = filesizeformat(im) except OSError: image_size = "Unknown" image_credit = issue.batch.awardee.name host = request.get_host() static_url = settings.STATIC_URL template = "page.html" response = render(request, template, locals()) return response