From e03e7da93c342a1db107dacf6a44fe1446deff6e Mon Sep 17 00:00:00 2001 From: Ross Jones Date: Tue, 17 Nov 2015 19:17:38 +0000 Subject: [PATCH] Remove old RDF rendering of dataset page As ckanext-dcat is now a thing, and the old templates are removed, we no longer need to support .rdf extensions or conneg - and so this PR removes them. --- ckan/config/routing.py | 1 - ckan/controllers/package.py | 34 +-------------- ckan/lib/accept.py | 62 ---------------------------- ckan/tests/legacy/lib/test_accept.py | 50 ---------------------- 4 files changed, 1 insertion(+), 146 deletions(-) delete mode 100644 ckan/lib/accept.py delete mode 100644 ckan/tests/legacy/lib/test_accept.py diff --git a/ckan/config/routing.py b/ckan/config/routing.py index 15b904666e5..b1985ec1653 100644 --- a/ckan/config/routing.py +++ b/ckan/config/routing.py @@ -234,7 +234,6 @@ def make_map(): m.connect('/dataset/activity/{id}/{offset}', action='activity') m.connect('dataset_groups', '/dataset/groups/{id}', action='groups', ckan_icon='group') - m.connect('/dataset/{id}.{format}', action='read') m.connect('dataset_resources', '/dataset/resources/{id}', action='resources', ckan_icon='reorder') m.connect('dataset_read', '/dataset/{id}', action='read', diff --git a/ckan/controllers/package.py b/ckan/controllers/package.py index 4d6f6367c38..473eba5aa31 100644 --- a/ckan/controllers/package.py +++ b/ckan/controllers/package.py @@ -13,7 +13,6 @@ import ckan.lib.maintain as maintain import ckan.lib.i18n as i18n import ckan.lib.navl.dictization_functions as dict_fns -import ckan.lib.accept as accept import ckan.lib.helpers as h import ckan.model as model import ckan.lib.datapreview as datapreview @@ -306,22 +305,6 @@ def pager_url(q=None, page=None): return render(self._search_template(package_type), extra_vars={'dataset_type': package_type}) - def _content_type_from_extension(self, ext): - ct, ext = accept.parse_extension(ext) - if not ct: - return None, None - return ct, ext - - def _content_type_from_accept(self): - """ - Given a requested format this method determines the content-type - to set and the genshi template loader to use in order to render - it accurately. TextTemplate must be used for non-xml templates - whilst all that are some sort of XML should use MarkupTemplate. - """ - ct, ext = accept.parse_header(request.headers.get('Accept', '')) - return ct, ext - def resources(self, id): context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, @@ -350,20 +333,7 @@ def resources(self, id): return render('package/resources.html', extra_vars={'dataset_type': package_type}) - def read(self, id, format='html'): - if not format == 'html': - ctype, extension = \ - self._content_type_from_extension(format) - if not ctype: - # An unknown format, we'll carry on in case it is a - # revision specifier and re-constitute the original id - id = "%s.%s" % (id, format) - ctype, format = "text/html; charset=utf-8", "html" - else: - ctype, format = self._content_type_from_accept() - - response.headers['Content-Type'] = ctype - + def read(self, id): context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj} @@ -415,8 +385,6 @@ def read(self, id, format='html'): package_type=package_type) template = self._read_template(package_type) - template = template[:template.index('.') + 1] + format - try: return render(template, extra_vars={'dataset_type': package_type}) diff --git a/ckan/lib/accept.py b/ckan/lib/accept.py deleted file mode 100644 index f6f53f2b001..00000000000 --- a/ckan/lib/accept.py +++ /dev/null @@ -1,62 +0,0 @@ -""" -Simple accept header parsing to determins which content type we should deliver -back to the caller. This is mostly used by the rdf export functionality -""" -import re -import operator - -# For parsing {name};q=x and {name} style fields from the accept header -accept_re = re.compile("^(?P[^;]+)[ \t]*(;[ \t]*q=(?P[0-9.]+)){0,1}$") - -accept_types = { - # Name : ContentType, Extension - "text/html": ("text/html; charset=utf-8", 'html'), - "text/n3": ("text/n3; charset=utf-8", 'n3'), - "application/rdf+xml": ("application/rdf+xml; charset=utf-8", 'rdf'), -} -accept_by_extension = { - "rdf": "application/rdf+xml", - "n3": "text/n3" -} - - -def parse_extension(file_ext): - """ - If provided an extension, this function will return the details - for that extension, if we know about it. - """ - ext = accept_by_extension.get(file_ext, None) - if ext: - return accept_types[ext] - return (None, None) - - -def parse_header(accept_header=''): - """ - Parses the supplied accept header and tries to determine - which content types we can provide the response in that will keep the - client happy. - - We will always provide html as the default if we can't see anything else - but we will also need to take into account the q score. - - The return values are be content-type,is-markup,extension - """ - if accept_header is None: - accept_header = "" - - acceptable = {} - for typ in accept_header.split(','): - m = accept_re.match(typ) - if m: - key = m.groups(0)[0] - qscore = m.groups(0)[2] or 1.0 - acceptable[key] = float(qscore) - - for ctype in sorted(acceptable.iteritems(), - key=operator.itemgetter(1), - reverse=True): - if ctype[0] in accept_types: - return accept_types[ctype[0]] - - return accept_types["text/html"] diff --git a/ckan/tests/legacy/lib/test_accept.py b/ckan/tests/legacy/lib/test_accept.py deleted file mode 100644 index 68fc4dd1831..00000000000 --- a/ckan/tests/legacy/lib/test_accept.py +++ /dev/null @@ -1,50 +0,0 @@ -from nose.tools import assert_equal - -import ckan.lib.accept as accept - -class TestAccept: - def test_accept_invalid(self): - ct, ext = accept.parse_header(None) - assert_equal( ct, "text/html; charset=utf-8") - assert_equal( ext, "html") - - def test_accept_invalid2(self): - ct, ext = accept.parse_header("") - assert_equal( ct, "text/html; charset=utf-8") - assert_equal( ext, "html") - - def test_accept_invalid3(self): - ct, ext = accept.parse_header("wombles") - assert_equal( ct, "text/html; charset=utf-8") - assert_equal( ext, "html") - - - def test_accept_valid(self): - a = "text/turtle,application/turtle,application/rdf+xml,text/plain;q=0.8,*/*;q=.5" - ct, ext = accept.parse_header(a) - assert_equal( ct, "application/rdf+xml; charset=utf-8") - assert_equal( ext, "rdf") - - def test_accept_valid2(self): - a = "text/turtle,application/turtle,application/rdf+xml;q=0.9,text/plain;q=0.8,*/*;q=.5" - ct, ext = accept.parse_header(a) - assert_equal( ct, "application/rdf+xml; charset=utf-8") - assert_equal( ext, "rdf") - - def test_accept_valid4(self): - a = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" - ct, ext = accept.parse_header(a) - assert_equal( ct, "text/html; charset=utf-8") - assert_equal( ext, "html") - - def test_accept_valid5(self): - a = "application/rdf+xml;q=0.5,application/xhtml+xml,text/html;q=0.9" - ct, ext = accept.parse_header(a) - assert_equal( ct, "text/html; charset=utf-8") - assert_equal( ext, "html") - - def test_accept_valid6(self): - a = "application/rdf+xml;q=0.9,application/xhtml+xml,text/html;q=0.5" - ct, ext = accept.parse_header(a) - assert_equal( ct, "application/rdf+xml; charset=utf-8") - assert_equal( ext, "rdf")