Merge ~twom/launchpad:commit-to-MP-link-previews into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: cce4c58c0b28fea6bb54966af12a67c173871d5c
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:commit-to-MP-link-previews
Merge into: launchpad:master
Diff against target: 79 lines (+33/-2)
4 files modified
lib/lp/app/templates/base-layout.pt (+2/-2)
lib/lp/code/browser/branchmergeproposal.py (+6/-0)
lib/lp/code/browser/tests/test_branchmergeproposal.py (+14/-0)
lib/lp/services/webapp/publisher.py (+11/-0)
Reviewer Review Type Date Requested Status
Kristian Glass (community) Approve
Ioana Lasc (community) Approve
Review via email: mp+386840@code.launchpad.net

Commit message

Add opengraph_description as an overridable attribute

Description of the change

Some pages may wish to override the description displayed via opengraph to something that makes more sense in context.

Add this as an attribute on the base view, use the new property in the Merge Proposal template and view.

To post a comment you must log in.
Revision history for this message
Kristian Glass (doismellburning) wrote :

No objection, but I'd assumed people would just override `page_description` and would rarely want the two to be to be different (404 pages were the only real counter-example I had) - any particular reason to make the distinction here?

Revision history for this message
Ioana Lasc (ilasc) wrote :

I would add a unit test but apart from that it looks good to me.

review: Approve
Revision history for this message
Tom Wardill (twom) wrote :

My thought was that in general, the description tag makes more sense to be the 'description' field, it's slightly less surprising.
We're overriding it in this context specifically because it's shorter and makes a little more sense in an opengraph preview.
The 404 page having them different is a stronger argument, admittedly, but that gives us at least two instances that they might be different, so for the small overhead, they might as well be separate.

Revision history for this message
Kristian Glass (doismellburning) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/app/templates/base-layout.pt b/lib/lp/app/templates/base-layout.pt
2index 08df3dc..4eb0133 100644
3--- a/lib/lp/app/templates/base-layout.pt
4+++ b/lib/lp/app/templates/base-layout.pt
5@@ -50,8 +50,8 @@
6 tal:condition="view/page_description | nothing"
7 tal:attributes="content view/page_description/fmt:strip-email/fmt:shorten/500" />
8 <meta property="og:description"
9- tal:condition="view/page_description | nothing"
10- tal:attributes="content view/page_description/fmt:strip-email/fmt:shorten/500" />
11+ tal:condition="view/opengraph_description | nothing"
12+ tal:attributes="content view/opengraph_description/fmt:strip-email/fmt:shorten/500" />
13 </tal:view>
14
15 <tal:comment condition="nothing">
16diff --git a/lib/lp/code/browser/branchmergeproposal.py b/lib/lp/code/browser/branchmergeproposal.py
17index 6d33f97..ff86b13 100644
18--- a/lib/lp/code/browser/branchmergeproposal.py
19+++ b/lib/lp/code/browser/branchmergeproposal.py
20@@ -767,6 +767,12 @@ class BranchMergeProposalView(LaunchpadFormView, UnmergedRevisionsMixin,
21 mp, description, title, edit_view='+edit-description')
22
23 @property
24+ def opengraph_description(self):
25+ if self.context.commit_message:
26+ return self.context.commit_message
27+ return self.page_description
28+
29+ @property
30 def edit_commit_message_link_class(self):
31 if self.context.commit_message:
32 return "hidden"
33diff --git a/lib/lp/code/browser/tests/test_branchmergeproposal.py b/lib/lp/code/browser/tests/test_branchmergeproposal.py
34index e42a9c5..515b2d4 100644
35--- a/lib/lp/code/browser/tests/test_branchmergeproposal.py
36+++ b/lib/lp/code/browser/tests/test_branchmergeproposal.py
37@@ -2203,6 +2203,20 @@ class TestBranchMergeProposal(BrowserTestCase):
38 view = create_initialized_view(bmp, '+index')
39 self.assertFalse(view.show_rescan_link)
40
41+ def test_opengraph_description_is_commit(self):
42+ bmp = self.factory.makeBranchMergeProposalForGit()
43+ target_job = getUtility(IGitRefScanJobSource).create(
44+ bmp.target_git_repository)
45+ removeSecurityProxy(target_job).job._status = JobStatus.COMPLETED
46+ source_job = getUtility(IGitRefScanJobSource).create(
47+ bmp.source_git_repository)
48+ removeSecurityProxy(source_job).job._status = JobStatus.COMPLETED
49+ view = create_initialized_view(bmp, '+index')
50+ self.assertEqual(
51+ view.opengraph_description, view.context.commit_message)
52+ self.assertEqual(
53+ view.page_description, bmp.description)
54+
55
56 class TestBranchMergeProposalRescanView(BrowserTestCase):
57
58diff --git a/lib/lp/services/webapp/publisher.py b/lib/lp/services/webapp/publisher.py
59index fccb857..a3b8e70 100644
60--- a/lib/lp/services/webapp/publisher.py
61+++ b/lib/lp/services/webapp/publisher.py
62@@ -369,6 +369,17 @@ class LaunchpadView(UserAttributeCache):
63 return getattr(self.context, 'description', None)
64
65 @property
66+ def opengraph_description(self):
67+ """Return a string for the description used in the OpenGraph metadata
68+
69+ Some pages may wish to override the values used in the OpenGraph
70+ metadata to provide more useful link previews.
71+
72+ Default to the page_description in the base views.
73+ """
74+ return self.page_description
75+
76+ @property
77 def template(self):
78 """The page's template, if configured in zcml."""
79 return self.index

Subscribers

People subscribed via source and target branches

to status/vote changes: