From 70f652deb27d5e7b11ed54e9e418331ebb1bbae7 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 9 Apr 2019 12:14:56 -0700 Subject: temporary hack to remove ext-link XML in refs --- python/fatcat_web/hacks.py | 15 +++++++++++++++ python/fatcat_web/routes.py | 10 ++++++++++ 2 files changed, 25 insertions(+) create mode 100644 python/fatcat_web/hacks.py diff --git a/python/fatcat_web/hacks.py b/python/fatcat_web/hacks.py new file mode 100644 index 00000000..51b97142 --- /dev/null +++ b/python/fatcat_web/hacks.py @@ -0,0 +1,15 @@ + +import re + +STRIP_EXTLINK_XML_RE = re.compile(r"") + +def strip_extlink_xml(unstr): + unstr = unstr.replace("", "") + unstr = STRIP_EXTLINK_XML_RE.sub("", unstr) + return unstr + +def test_strip_extlink_xml(): + assert strip_extlink_xml("asdf") == "asdf" + assert strip_extlink_xml("""LOCKSS (2014) Available: http://lockss.org/. Accessed: 2014 November 1.""") == \ + """LOCKSS (2014) Available: http://lockss.org/. Accessed: 2014 November 1.""" + diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py index c3467a61..eb53c2ef 100644 --- a/python/fatcat_web/routes.py +++ b/python/fatcat_web/routes.py @@ -13,6 +13,7 @@ from fatcat_web import app, api, auth_api, priv_api from fatcat_web.auth import handle_token_login, handle_logout, load_user, handle_ia_xauth from fatcat_web.cors import crossdomain from fatcat_web.search import * +from fatcat_web.hacks import strip_extlink_xml ### Views ################################################################### @@ -280,6 +281,15 @@ def release_view(ident): entity.es = release_to_elasticsearch(entity, force_bool=False) for fs in filesets: fs.total_size = sum([f.size for f in fs.manifest]) + for ref in entity.refs: + # this is a UI hack to get rid of XML crud in unstructured refs like: + # LOCKSS (2014) Available: http://lockss.org/. Accessed: 2014 + # November 1. + if ref.extra and ref.extra.get('unstructured'): + ref.extra['unstructured'] = strip_extlink_xml(ref.extra['unstructured']) entity.filesets = filesets authors = [c for c in entity.contribs if c.role in ('author', None)] authors = sorted(authors, key=lambda c: c.index or 99999999) -- cgit v1.2.3