Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Publications/Document container restyling #240

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dragon-dxw
Copy link
Contributor

@dragon-dxw dragon-dxw commented May 20, 2022

We've restyled the attachment block. There's a couple of fiddly bits that are handled specially:

  • tags for PDF documents to name the filetype in full

  • Handling for different SVGs for different filetypes, unknown filetypes and things that we just have a URL for (although the SVGs do look almost identical at the moment)

  • Possibly needs an accessibility pass for the alt text on the images.

Before example:
image

We do this throughout the website -- this isn't just limited to
document collections/publications.

There's a new fixture containing links to external URLs, internal pages,
a 'pdf', 'docx' and random other file. (Really, the files are just
the string "x" because we're only checking the extension -- they're not
real so don't be surprised if you can't click through correctly.)

To do:
* Offsite link to image

To not do right now:
* remove Embed and Free Text components of the document group
* counting the pages in a PDF.
https://designnotes.blog.gov.uk/2016/11/28/removing-the-external-link-icon-from-gov-uk/
suggests there's no clear need for it, and the current half-working implementation looks
awful. We can add it back when we have more time.
Copy link
Member

@jacksonj04 jacksonj04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fundamentally sound, just a few quick tweaks and a clarifying comment.

self.assertEqual(title.text.strip(), "A Document With A Link To A Page")
self.assertEqual(
title.select_one("a")["href"],
"/blog-index-page/",
)

def test_publication_pdf(self):
return # TODO: remove
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs removing to reinstate this test path

@@ -41,6 +41,22 @@ class DocumentBlock(StructBlock):
title = RichTextBlock(required=False)
document = DocumentChooserBlock()
summary = RichTextBlock(required=False)
extension_data = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicky convention, since this is a constant

Suggested change
extension_data = {
EXTENSION_DATA = {

@@ -51,7 +67,9 @@ def get_context(self, value, parent_context):
context = super().get_context(value, parent_context)
context["file_ext"] = value["document"].file_extension
context["file_size"] = filesizeformat(value["document"].get_file_size())

context["ext_name"], context["ext_icon"] = self.extension_data.get(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
context["ext_name"], context["ext_icon"] = self.extension_data.get(
context["ext_name"], context["ext_icon"] = self.EXTENSION_DATA.get(

self.assertIn(">File<", self.unknown)

def test_internal_page(self):
self.assertIn("link.svg", self.internal_page) # is this correct behaviour?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct behaviour, but we should discourage this kind of thing in the operations manual.

str(attachment) for attachment in soup.select(".attachment")
]

def test_has_bytes(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not immediately clear what this is actually testing for, so it might be worth a clarifying comment.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
2 participants