def extra_formatting(tree, version): try: tree.attrib['formatted.assent'] = format_govt_date( safe_date(tree.attrib['date.assent'])) except Exception: # ew pass try: tree.attrib['formatted.reprint'] = format_govt_date( safe_date(tree.xpath('.//reprint-date')[0].text)) except Exception: # ew pass tree.attrib['version'] = '%.1f' % version
def instrument_location(instrument, location, args): def massage(): return nodes_from_path_string(instrument.get_tree(), link_to_canonical(location)) try: tree = nodes_from_path_string(instrument.get_tree(), location) if len(tree) == 1 and tree[0] == instrument.get_tree(): raise CustomException('try again') except CustomException: tree = massage() full_location, _, path = generate_path_string(tree[0]) tree = cull_tree(tree) return { 'html_content': etree.tostring(tohtml(tree), encoding='UTF-8', method="html"), 'title': instrument.title, 'full_title': full_location, 'document_id': instrument.id, 'doc_type': 'instrument', "latest": instrument.attributes['latest'], "path": instrument.attributes['path'], "date_as_at_str": format_govt_date(instrument.attributes['date_as_at']), 'format': 'fragment', 'query': { 'doc_type': 'instrument', 'document_id': instrument.id, 'find': 'location', 'location': path } }
def instrument_skeleton_response(instrument, args={}): result = { 'html_content': instrument.skeleton, 'title': instrument.title, 'full_title': instrument.title, 'document_id': instrument.id, 'doc_type': 'instrument', "latest": instrument.attributes['latest'], "path": instrument.attributes['path'], "date_as_at_str": format_govt_date(instrument.attributes['date_as_at']), 'format': 'skeleton', 'heights': instrument.heights, 'parts': {}, 'query': { 'doc_type': 'instrument', 'document_id': instrument.id, 'find': 'full' } } if args.get('highlight'): highlight = args.get('highlight') highlight_args = { 'document_id': args.get('id', args.get('document_id')), 'parts': args.get('parts'), 'contains': highlight } result['title'] = '%s Find: %s' % (result['title'], args.get('highlight')) result.update(query_contains_skeleton(highlight_args)) return result
def instrument_preview(instrument): preview = limit_tree_size(instrument.get_tree()) return { 'html_content': etree.tostring(tohtml(preview), encoding='UTF-8', method="html"), 'title': instrument.title, 'full_title': instrument.title, 'document_id': instrument.id, 'doc_type': 'instrument', "latest": instrument.attributes['latest'], "path": instrument.attributes['path'], "date_as_at_str": format_govt_date(instrument.attributes['date_as_at']), 'format': 'preview', 'query': { 'doc_type': 'instrument', 'document_id': instrument.id, 'find': 'preview' } }
def instrument_full(instrument, args={}): "who doesn't love magic numbers?" if current_app.config.get('USE_SKELETON') and (instrument.length > 100000 or args.get('highlight')): return instrument_skeleton_response(instrument, args) return { 'html_content': etree.tostring(tohtml(instrument.get_tree()), encoding='UTF-8', method="html"), 'title': instrument.title, 'full_title': instrument.title, 'document_id': instrument.id, 'doc_type': 'instrument', "latest": instrument.attributes['latest'], "path": instrument.attributes['path'], "date_as_at_str": format_govt_date(instrument.attributes['date_as_at']), 'format': 'full', 'query': { 'doc_type': 'instrument', 'document_id': instrument.id, 'find': 'full' } }
def instrument_govt_location(instrument, id, link_text, args): tree = decide_govt_or_path(instrument.get_tree(), id, link_text) full_location, _, location = generate_path_string(tree[0]) tree = cull_tree(tree) return { 'html_content': etree.tostring(tohtml(tree), encoding='UTF-8', method="html"), 'title': instrument.title, 'full_title': full_location, 'document_id': instrument.id, 'doc_type': 'instrument', "latest": instrument.attributes['latest'], "path": instrument.attributes['path'], "date_as_at_str": format_govt_date(instrument.attributes['date_as_at']), 'format': 'fragment', 'query': { 'doc_type': 'instrument', 'document_id': instrument.id, 'find': 'govt_location', 'govt_location': id } }
def section_versions(args): document_id = int(args.get('document_id')) versions = get_versions(document_id) title = filter(lambda x: x['id'] == document_id, versions['versions'])[0]['title'] version_list = [] for v in versions['versions']: if v['id'] != document_id: v['url'] = 'query?%s' % urllib.urlencode( { 'location': args.get('target_path'), 'doc_type': 'instrument', 'find': 'location', 'document_id': v['id'] }) v['formatted_date'] = format_govt_date(v['date_as_at']) version_list.append(v) return { 'html': render_template('section_versions.html', versions=version_list, title='%s %s' % (title, args.get('target_path')), path=args.get('target_path')) }