Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions documentcloud/documents/oembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def response(self, request, query, max_width=None, max_height=None, **kwargs):
context = {
"src": src,
"title": note.title,
"style": self.get_style(document, note, max_width, max_height),
"style": self.get_style(max_width, max_height),
"width": note_width,
"height": note_height,
"resize_script": RESIZE_SCRIPT,
Expand All @@ -183,13 +183,11 @@ def get_dimensions(self, document, note):

return (note_width, note_height)

def get_style(self, document, note, max_width=None, max_height=None):

note_width, note_height = self.get_dimensions(document, note)
def get_style(self, max_width=None, max_height=None):

style = (
f"border: 1px solid #d8dee2; border-radius: 0.5rem; width: 100%;"
f" height: 100%; aspect-ratio: {note_width} / {note_height};"
"border: 1px solid #d8dee2; border-radius: 0.5rem;"
" width: 100%; height: 300px;"
)
if max_width:
style += f" max-width: {max_width}px;"
Expand Down
8 changes: 2 additions & 6 deletions documentcloud/documents/tests/test_oembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,6 @@ def test_note_oembed_response(self):
response = self.note_oembed.response(
request, query, max_width=600, max_height=None, doc_pk=123, pk=456
)
note_width, note_height = self.note_oembed.get_dimensions(
self.document, self.note
)

# Check response properties
assert response["version"] == "1.0"
Expand All @@ -370,10 +367,9 @@ def test_note_oembed_response(self):
"?embed=1&responsive=1"
) in response["html"]
assert 'title="Test Note (Hosted by DocumentCloud)"' in response["html"]
assert f'width="{note_width}" height="{note_height}"' in response["html"]
assert (
f"border: 1px solid #d8dee2; border-radius: 0.5rem; width: 100%;"
f" height: 100%; aspect-ratio: {note_width} / {note_height};"
"border: 1px solid #d8dee2; border-radius: 0.5rem;"
" width: 100%; height: 300px;"
) in response["html"]
assert 'sandbox="allow-scripts allow-same-origin' in response["html"]

Expand Down