From 309939b5dff6c90f478fed413faa39023ac43524 Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Tue, 21 Nov 2023 08:10:11 -0800 Subject: [PATCH 01/11] update vocabulary-theme to 1.3.1 --- .../static/wp-content/themes/vocabulary-theme/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cc_legal_tools/static/wp-content/themes/vocabulary-theme/style.css b/cc_legal_tools/static/wp-content/themes/vocabulary-theme/style.css index fa3ab860..ad2001ab 100644 --- a/cc_legal_tools/static/wp-content/themes/vocabulary-theme/style.css +++ b/cc_legal_tools/static/wp-content/themes/vocabulary-theme/style.css @@ -3,7 +3,7 @@ Theme Name: CC Vocabulary Theme Author: the Creative Commons team; possumbilities, Timid Robot Author URI: https://opensource.creativecommons.org/ Description: Theme based on the Vocabulary Design System -Version: 1.3 +Version: 1.3.1 Requires at least: 5.0 Tested up to: 6.2.2 Requires PHP: 7.0 From dafa19bd1b63cd22894b638125ba8c41aeb4d686 Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Tue, 21 Nov 2023 08:12:39 -0800 Subject: [PATCH 02/11] clarify Not the live site --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 546aad60..8e85c5cc 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ repository. ## Not the live site This project is not intended to serve the legal tools directly. Instead, a -command line tool can be used to save all the rendered HTML pages as files. -Then those files are used as part of the real creativecommons.org site, just -served as static files. +command line tool can be used to save all the rendered HTML and RDF/XML pages +as files. Then those files are used as part of the real CreativeCommons.org +site (served as static files). ## Software Versions From 126f71b792f9ffd04fd5a9dfc4bb6c40b3cbf3ef Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Tue, 21 Nov 2023 08:35:11 -0800 Subject: [PATCH 03/11] rename canonical_url to canonical_url_html and add canonical_url_cc --- legal_tools/views.py | 17 ++++++++++++++--- templates/base.html | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/legal_tools/views.py b/legal_tools/views.py index 2592c74b..5cef3899 100644 --- a/legal_tools/views.py +++ b/legal_tools/views.py @@ -414,11 +414,12 @@ def view_list(request, category, language_code=None): request_path=request.path, selected_language_code=language_code, ) + canonical_url_html = os.path.join(settings.CANONICAL_SITE, request.path) html_response = render( request, template_name=f"list-{category}.html", context={ - "canonical_url": f"{settings.CANONICAL_SITE}{request.path}", + "canonical_url_html": canonical_url_html, "category": category, "category_title": category_title, "category_list": category_list, @@ -505,13 +506,16 @@ def view_deed( else: body_template = "includes/deed_body_unimplemented.html" + canonical_url_html = os.path.join(settings.CANONICAL_SITE, request.path) + canonical_url_cc = os.path.join(os.path.dirname(canonical_url_html), "") html_response = render( request, template_name="deed.html", context={ "additional_classes": "", "body_template": body_template, - "canonical_url": f"{settings.CANONICAL_SITE}{request.path}", + "canonical_url_cc": canonical_url_cc, + "canonical_url_html": canonical_url_html, "category": category, "category_title": category_title, "identifier": tool.identifier(), @@ -607,10 +611,17 @@ def view_legal_code( language_default, ) + canonical_url_html = os.path.join( + settings.CANONICAL_SITE, request.path + ) + canonical_url_cc = os.path.join( + os.path.dirname(canonical_url_html), "" + ) kwargs = dict( template_name="legalcode.html", context={ - "canonical_url": f"{settings.CANONICAL_SITE}{request.path}", + "canonical_url_cc": canonical_url_cc, + "canonical_url_html": canonical_url_html, "category": category, "category_title": category_title, "deed_rel_path": deed_rel_path, diff --git a/templates/base.html b/templates/base.html index ea8e4353..907f74f4 100644 --- a/templates/base.html +++ b/templates/base.html @@ -9,7 +9,7 @@ {% block title %}{% endblock %} | Creative Commons - + {% block head_meta %} {% endblock %} From 9bffc15d00f6b4621df3695628eba60a43f49c19 Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Tue, 21 Nov 2023 09:04:32 -0800 Subject: [PATCH 04/11] use urllib.parse.urljoin --- legal_tools/views.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/legal_tools/views.py b/legal_tools/views.py index 5cef3899..625c56a1 100644 --- a/legal_tools/views.py +++ b/legal_tools/views.py @@ -3,6 +3,7 @@ import re from operator import itemgetter from typing import Iterable +from urllib import parse # Third-party import git @@ -414,7 +415,7 @@ def view_list(request, category, language_code=None): request_path=request.path, selected_language_code=language_code, ) - canonical_url_html = os.path.join(settings.CANONICAL_SITE, request.path) + canonical_url_html = parse.urljoin(settings.CANONICAL_SITE, request.path) html_response = render( request, template_name=f"list-{category}.html", @@ -506,7 +507,7 @@ def view_deed( else: body_template = "includes/deed_body_unimplemented.html" - canonical_url_html = os.path.join(settings.CANONICAL_SITE, request.path) + canonical_url_html = parse.urljoin(settings.CANONICAL_SITE, request.path) canonical_url_cc = os.path.join(os.path.dirname(canonical_url_html), "") html_response = render( request, @@ -611,7 +612,7 @@ def view_legal_code( language_default, ) - canonical_url_html = os.path.join( + canonical_url_html = parse.urljoin( settings.CANONICAL_SITE, request.path ) canonical_url_cc = os.path.join( From 0b02962f6dbe6eaccd6b1790301426527700212c Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Tue, 21 Nov 2023 10:28:54 -0800 Subject: [PATCH 05/11] simplify canonical path handling and add view_legacy_plaintext --- legal_tools/urls.py | 23 +++++++++++------ legal_tools/views.py | 61 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/legal_tools/urls.py b/legal_tools/urls.py index e8d4cef4..0e37f281 100644 --- a/legal_tools/urls.py +++ b/legal_tools/urls.py @@ -19,6 +19,7 @@ view_deed, view_dev_index, view_image_rdf, + view_legacy_plaintext, view_legal_code, view_legal_tool_rdf, view_list, @@ -246,6 +247,20 @@ def to_url(self, value): name="view_deed_unported", ), # LEGALCODE PAGES ######################################################### + # Legalcode: plain text + path( + "///legalcode.txt", + view_legacy_plaintext, + name="view_legacy_plaintext", + ), + # NOTE: programmatic plaintext functionality disabled + # # Plaintext Legalcode: no Jurisdiction (int/unported), no language_code + # path( + # "///legalcode.txt", + # view_legal_code, + # kwargs=dict(jurisdiction="", is_plain_text=True), + # name="view_legal_code_unported", + # ), # Legalcode: with Jurisdiction (ported), with language_code path( "//" @@ -275,14 +290,6 @@ def to_url(self, value): kwargs=dict(jurisdiction=""), name="view_legal_code_unported", ), - # NOTE: plaintext functionality disabled - # # Plaintext Legalcode: no Jurisdiction (int/unported), no language_code - # path( - # "///legalcode.txt", - # view_legal_code, - # kwargs=dict(jurisdiction="", is_plain_text=True), - # name="view_legal_code_unported", - # ), # CCREL DOCUMENTS ######################################################### # Legal tool RDF/XML: no Jurisdiction (international/unported) path( diff --git a/legal_tools/views.py b/legal_tools/views.py index 625c56a1..95983771 100644 --- a/legal_tools/views.py +++ b/legal_tools/views.py @@ -1,9 +1,8 @@ # Standard library -import os.path +import os import re from operator import itemgetter from typing import Iterable -from urllib import parse # Third-party import git @@ -38,6 +37,21 @@ ) NUM_COMMITS = 3 +PLAIN_TEXT_TOOL_IDENTIFIERS = [ + "CC BY 3.0", + "CC BY-NC 3.0", + "CC BY-NC-ND 3.0", + "CC BY-NC-SA 3.0", + "CC BY-ND 3.0", + "CC BY-SA 3.0", + "CC BY 4.0", + "CC BY-NC 4.0", + "CC BY-NC-ND 4.0", + "CC BY-NC-SA 4.0", + "CC BY-ND 4.0", + "CC BY-SA 4.0", + "CC0 1.0", +] # For removing the deed.foo section of a deed url REMOVE_DEED_URL_RE = re.compile(r"^(.*?/)(?:deed)?(?:\..*)?$") @@ -415,7 +429,9 @@ def view_list(request, category, language_code=None): request_path=request.path, selected_language_code=language_code, ) - canonical_url_html = parse.urljoin(settings.CANONICAL_SITE, request.path) + canonical_url_html = os.path.join( + settings.CANONICAL_SITE, request.path.lstrip(os.sep) + ) html_response = render( request, template_name=f"list-{category}.html", @@ -507,7 +523,9 @@ def view_deed( else: body_template = "includes/deed_body_unimplemented.html" - canonical_url_html = parse.urljoin(settings.CANONICAL_SITE, request.path) + canonical_url_html = os.path.join( + settings.CANONICAL_SITE, request.path.lstrip(os.sep) + ) canonical_url_cc = os.path.join(os.path.dirname(canonical_url_html), "") html_response = render( request, @@ -546,6 +564,7 @@ def view_legal_code( language_code=None, is_plain_text=False, ): + plain_text_url = None request.path, language_code = normalize_path_and_lang( request.path, jurisdiction, language_code ) @@ -612,8 +631,11 @@ def view_legal_code( language_default, ) - canonical_url_html = parse.urljoin( - settings.CANONICAL_SITE, request.path + if tool.identifier() in PLAIN_TEXT_TOOL_IDENTIFIERS: + plain_text_url = "legalcode.txt" + + canonical_url_html = os.path.join( + settings.CANONICAL_SITE, request.path.lstrip(os.sep) ) canonical_url_cc = os.path.join( os.path.dirname(canonical_url_html), "" @@ -631,6 +653,7 @@ def view_legal_code( "legal_code": legal_code, "list_licenses": list_licenses, "list_publicdomain": list_publicdomain, + "plain_text_url": plain_text_url, "replaced_path": replaced_path, "replaced_title": replaced_title, "tool": tool, @@ -809,3 +832,29 @@ def view_image_rdf(request): serialized_rdf_content, content_type="application/rdf+xml" ) return response + + +def view_legacy_plaintext( + request, + unit, + version, + category=None, +): + """ + Display plain text file, if it exists (this view is only used in + development). + """ + published_docs_path = os.path.abspath( + os.path.realpath(os.path.join("..", "cc-legal-tools-data", "docs")) + ) + plain_text_path = os.path.join( + published_docs_path, request.path.lstrip(os.sep) + ) + if os.path.isfile(plain_text_path): + with open(plain_text_path, "rt") as file_obj: + content = file_obj.read() + response = HttpResponse(content, content_type="text/plain") + else: + raise Http404("plain text file does not exist") + + return response From 402a397322d11c5b9675f4b9814218e962a46cee Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Tue, 21 Nov 2023 10:40:14 -0800 Subject: [PATCH 06/11] add view_legacy_plaintext tests --- legal_tools/tests/test_views.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/legal_tools/tests/test_views.py b/legal_tools/tests/test_views.py index 575a92a5..0e6ec19d 100644 --- a/legal_tools/tests/test_views.py +++ b/legal_tools/tests/test_views.py @@ -1399,3 +1399,22 @@ def test_view_legal_tool_rdf_images_mixin(self): " \n", content, ) + + +class ViewLegacyPlaintext(ToolsTestsMixin, TestCase): + def test_view_legacy_plaintext_file_exists(self): + tool = Tool.objects.get(unit="by", version="4.0") + url = build_path(base_url=tool.base_url, document="legalcode") + url = f"{url}.txt" + response = self.client.get(url) + content = response.content.decode() + self.assertEqual(f"{response.status_code} {url}", f"200 {url}") + self.assertEqual(response.headers["Content-Type"], "text/plain") + self.assertIn("Attribution 4.0 International", content) + + def test_view_legacy_plaintext_file_does_not_exist(self): + tool = Tool.objects.get(unit="by", version="2.0") + url = build_path(base_url=tool.base_url, document="legalcode") + url = f"{url}.txt" + response = self.client.get(url) + self.assertEqual(f"{response.status_code} {url}", f"404 {url}") From dfcb94a6a697d7f1eb99342d9cf097f0167356be Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Tue, 21 Nov 2023 11:13:58 -0800 Subject: [PATCH 07/11] make header more consistent across pages types and add tool-meta styling --- cc_legal_tools/static/cc-legal-tools/base.css | 78 ++++++++++++++++++- cc_legal_tools/static/cc-legal-tools/deed.css | 4 - 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/cc_legal_tools/static/cc-legal-tools/base.css b/cc_legal_tools/static/cc-legal-tools/base.css index d2fe3982..febf13c1 100644 --- a/cc_legal_tools/static/cc-legal-tools/base.css +++ b/cc_legal_tools/static/cc-legal-tools/base.css @@ -50,11 +50,21 @@ div.masthead > nav.ancilliary-menu span.locale.icon-attach:before { /* header title */ +/* TODO: resolve with vocabulary-theme */ +.cc-legal-tools main > header { + padding: 3em 0; +} .cc-legal-tools main > header > span.tool-icons > span.cc-icon > svg { display: inline; height: 4em; width: 4em; } +.cc-legal-tools main > header > h1 { + margin: 0.2em 0; +} +.cc-legal-tools main > header > h2 { + margin: 0; +} /* right nav */ @@ -99,7 +109,6 @@ main > aside > nav ul > li { /* TODO: resolve with vocabulary-theme */ padding: 0.5em; margin: 0; } - .cc-legal-tools table tr > th { } .cc-legal-tools table > tbody > tr:nth-child(3n) { @@ -107,6 +116,73 @@ main > aside > nav ul > li { /* TODO: resolve with vocabulary-theme */ } +/*.tool-meta */ +.cc-legal-tools .tool-meta { + display: flex; + justify-content: space-between; + align-items: baseline; + vertical-align: bottom; + position: relative; + margin-bottom: 1em; +} +.cc-legal-tools .tool-meta div { + list-style: none; + background-color: var(--vocabulary-brand-color-soft-turquoise); + border-radius: 5px; + padding: 0.8em; + display: inline-block; + position: relative; + padding-top: 1em; + padding-right: 1.4em; +} +.cc-legal-tools .tool-meta div a { + --underline-background-color: var(--vocabulary-brand-color-soft-turquoise); + font-family: 'Source Sans Pro'; +} +.cc-legal-tools .tool-meta h2 { + font-size: 1em; + margin: 0; + font-family: 'Source Sans Pro'; + margin-left: 0.6em; + display: inline; +} +.cc-legal-tools .tool-meta h2:after { + content: ':'; +} +.cc-legal-tools article.canonical-url { + margin-bottom: 0.5em; +} +.cc-legal-tools article.canonical-url h2 { + margin-bottom: 0.6em; +} +.cc-legal-tools article.canonical-url a { + font-family: monospace; +} +.cc-legal-tools .tool-meta .formats ul { + list-style: none; + display: inline-flex; + margin: 0; + font-size: 1em; +} +.cc-legal-tools .tool-meta .formats ul li { + padding: 0.3em; +} +.cc-legal-tools .tool-meta .formats ul li:first-child { + padding-left: 0; +} +.cc-legal-tools a.alt-view { + font-family: 'Source Sans Pro'; + font-size: 1.5em; + font-style: normal; + font-weight: 700; + line-height: 150%; + vertical-align: bottom; + position: absolute; + bottom: 1em; + right: 0; + } + + /* Notices */ .cc-legal-tools div.notice-bottom, .cc-legal-tools div.notice-top { padding: 1em; diff --git a/cc_legal_tools/static/cc-legal-tools/deed.css b/cc_legal_tools/static/cc-legal-tools/deed.css index e81fc73b..1aa22d31 100644 --- a/cc_legal_tools/static/cc-legal-tools/deed.css +++ b/cc_legal_tools/static/cc-legal-tools/deed.css @@ -1,7 +1,3 @@ -.cc-legal-tools main > header > h1 { - margin: 0.5em 0; -} - .cc-legal-tools div.content div#deed-body { border-top: 10px solid var(--vocabulary-brand-color-turquoise); border-bottom: 5px solid var(--vocabulary-neutral-color-dark-gray); From 2dd1a7744f42b7dc40302c5c9d294d94301ecb93 Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Tue, 21 Nov 2023 11:16:17 -0800 Subject: [PATCH 08/11] add tool-meta section to legal tools templates (deed & legal code) --- templates/deed.html | 17 ++++++++++++++--- templates/legalcode.html | 27 ++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/templates/deed.html b/templates/deed.html index 97786774..9acb7a2d 100644 --- a/templates/deed.html +++ b/templates/deed.html @@ -36,12 +36,23 @@ {% include 'includes/notice_newer_license.html' %} {% endif %} +
+ +
+ +
+ {% if not tool.deed_only %} - + +{% trans "See the legal code" %} + {% endif %} +
+ {% include body_template %} {% if category == "licenses" and tool.version == "4.0" %} diff --git a/templates/legalcode.html b/templates/legalcode.html index 0b13c6a5..278d4580 100644 --- a/templates/legalcode.html +++ b/templates/legalcode.html @@ -24,9 +24,30 @@ {% block content %} - + +
+ +
+ + +{% if plain_text_url %} + +{% endif %} + +
+ +{% trans "See the deed" %} + +
+

{% trans "Version" %} {{ legal_code.tool.version }} • {% blocktrans trimmed %} From 06a044296a5baeffb7f6ddac1ed6d807e194f3c6 Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Tue, 21 Nov 2023 11:28:16 -0800 Subject: [PATCH 09/11] translate "Formats" and add RDF/XML format --- templates/legalcode.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/templates/legalcode.html b/templates/legalcode.html index 278d4580..86296a4c 100644 --- a/templates/legalcode.html +++ b/templates/legalcode.html @@ -33,14 +33,15 @@

{% trans "Canonical URL" %}

{{ canonical_url_cc }} -{% if plain_text_url %} -{% endif %} From 1604523191f10b7ddb4a12363d87e574455e8fe9 Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Wed, 22 Nov 2023 08:26:30 -0800 Subject: [PATCH 10/11] update tool-meta styling/layout --- cc_legal_tools/static/cc-legal-tools/base.css | 89 +++++++++---------- templates/deed.html | 6 +- templates/legalcode.html | 7 +- 3 files changed, 50 insertions(+), 52 deletions(-) diff --git a/cc_legal_tools/static/cc-legal-tools/base.css b/cc_legal_tools/static/cc-legal-tools/base.css index febf13c1..42e19e7c 100644 --- a/cc_legal_tools/static/cc-legal-tools/base.css +++ b/cc_legal_tools/static/cc-legal-tools/base.css @@ -118,69 +118,64 @@ main > aside > nav ul > li { /* TODO: resolve with vocabulary-theme */ /*.tool-meta */ .cc-legal-tools .tool-meta { - display: flex; - justify-content: space-between; - align-items: baseline; - vertical-align: bottom; - position: relative; - margin-bottom: 1em; -} -.cc-legal-tools .tool-meta div { - list-style: none; - background-color: var(--vocabulary-brand-color-soft-turquoise); - border-radius: 5px; - padding: 0.8em; - display: inline-block; - position: relative; - padding-top: 1em; - padding-right: 1.4em; -} -.cc-legal-tools .tool-meta div a { - --underline-background-color: var(--vocabulary-brand-color-soft-turquoise); - font-family: 'Source Sans Pro'; + display: flex; + flex-wrap: wrap; + gap: 1em; +} +.cc-legal-tools .tool-meta div.meta-box { + list-style: none; + background-color: var(--vocabulary-brand-color-soft-turquoise); + border-radius: 5px; + padding: 0.8em; + padding-top: 1em; + padding-right: 1.4em; +} +.cc-legal-tools .tool-meta div.meta-box a { + --underline-background-color: var(--vocabulary-brand-color-soft-turquoise); + font-family: 'Source Sans Pro'; } .cc-legal-tools .tool-meta h2 { - font-size: 1em; - margin: 0; - font-family: 'Source Sans Pro'; - margin-left: 0.6em; - display: inline; + font-size: 1em; + margin: 0; + font-family: 'Source Sans Pro'; + margin-left: 0.6em; + display: inline; } .cc-legal-tools .tool-meta h2:after { - content: ':'; + content: ':'; } .cc-legal-tools article.canonical-url { - margin-bottom: 0.5em; + margin-bottom: 0.5em; } .cc-legal-tools article.canonical-url h2 { - margin-bottom: 0.6em; + margin-bottom: 0.6em; } .cc-legal-tools article.canonical-url a { - font-family: monospace; + font-family: monospace; } .cc-legal-tools .tool-meta .formats ul { - list-style: none; - display: inline-flex; - margin: 0; - font-size: 1em; + list-style: none; + display: inline-flex; + margin: 0; + font-size: 1em; } .cc-legal-tools .tool-meta .formats ul li { - padding: 0.3em; + padding: 0.3em; } .cc-legal-tools .tool-meta .formats ul li:first-child { - padding-left: 0; -} -.cc-legal-tools a.alt-view { - font-family: 'Source Sans Pro'; - font-size: 1.5em; - font-style: normal; - font-weight: 700; - line-height: 150%; - vertical-align: bottom; - position: absolute; - bottom: 1em; - right: 0; - } + padding-left: 0; +} +.cc-legal-tools .alt-view { + align-self: center; + margin-left: auto; +} +.cc-legal-tools .alt-view a { + font-family: 'Source Sans Pro'; + font-size: 1.5em; + font-style: normal; + font-weight: 700; + line-height: 150%; +} /* Notices */ diff --git a/templates/deed.html b/templates/deed.html index 9acb7a2d..3ab89396 100644 --- a/templates/deed.html +++ b/templates/deed.html @@ -38,7 +38,7 @@
-
+
{% if not tool.deed_only %} - + {% endif %}
diff --git a/templates/legalcode.html b/templates/legalcode.html index 86296a4c..f67a92bd 100644 --- a/templates/legalcode.html +++ b/templates/legalcode.html @@ -27,7 +27,7 @@
-
+
-
-{% trans "See the deed" %} +
From f143f80a589042db63cdeb7491abd299d55c65fc Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Wed, 22 Nov 2023 08:32:19 -0800 Subject: [PATCH 11/11] update string to Other formats --- templates/legalcode.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/legalcode.html b/templates/legalcode.html index f67a92bd..7cd58b54 100644 --- a/templates/legalcode.html +++ b/templates/legalcode.html @@ -34,7 +34,7 @@

{% trans "Canonical URL" %}