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 diff --git a/cc_legal_tools/static/cc-legal-tools/base.css b/cc_legal_tools/static/cc-legal-tools/base.css index d2fe3982..42e19e7c 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,68 @@ main > aside > nav ul > li { /* TODO: resolve with vocabulary-theme */ } +/*.tool-meta */ +.cc-legal-tools .tool-meta { + 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; +} +.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 .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 */ .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); 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 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}") 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 2592c74b..95983771 100644 --- a/legal_tools/views.py +++ b/legal_tools/views.py @@ -1,5 +1,5 @@ # Standard library -import os.path +import os import re from operator import itemgetter from typing import Iterable @@ -37,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)?(?:\..*)?$") @@ -414,11 +429,14 @@ 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.lstrip(os.sep) + ) 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 +523,18 @@ def view_deed( else: body_template = "includes/deed_body_unimplemented.html" + 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, 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(), @@ -541,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 ) @@ -607,10 +631,20 @@ def view_legal_code( language_default, ) + 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), "" + ) 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, @@ -619,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, @@ -797,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 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 %} diff --git a/templates/deed.html b/templates/deed.html index 97786774..3ab89396 100644 --- a/templates/deed.html +++ b/templates/deed.html @@ -36,12 +36,25 @@ {% include 'includes/notice_newer_license.html' %} {% endif %} +
+ +
+ +
+ {% if not tool.deed_only %} - + {% endif %} +
+ {% include body_template %} {% if category == "licenses" and tool.version == "4.0" %} diff --git a/templates/legalcode.html b/templates/legalcode.html index 0b13c6a5..7cd58b54 100644 --- a/templates/legalcode.html +++ b/templates/legalcode.html @@ -24,9 +24,32 @@ {% block content %} -
+ +
+ + + +
+ + + +
+

{% trans "Version" %} {{ legal_code.tool.version }} • {% blocktrans trimmed %}