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
diff --git a/lib/lp/app/templates/base-layout.pt b/lib/lp/app/templates/base-layout.pt
index 08df3dc..4eb0133 100644
--- a/lib/lp/app/templates/base-layout.pt
+++ b/lib/lp/app/templates/base-layout.pt
@@ -50,8 +50,8 @@
50 tal:condition="view/page_description | nothing"50 tal:condition="view/page_description | nothing"
51 tal:attributes="content view/page_description/fmt:strip-email/fmt:shorten/500" />51 tal:attributes="content view/page_description/fmt:strip-email/fmt:shorten/500" />
52 <meta property="og:description"52 <meta property="og:description"
53 tal:condition="view/page_description | nothing"53 tal:condition="view/opengraph_description | nothing"
54 tal:attributes="content view/page_description/fmt:strip-email/fmt:shorten/500" />54 tal:attributes="content view/opengraph_description/fmt:strip-email/fmt:shorten/500" />
55 </tal:view>55 </tal:view>
5656
57 <tal:comment condition="nothing">57 <tal:comment condition="nothing">
diff --git a/lib/lp/code/browser/branchmergeproposal.py b/lib/lp/code/browser/branchmergeproposal.py
index 6d33f97..ff86b13 100644
--- a/lib/lp/code/browser/branchmergeproposal.py
+++ b/lib/lp/code/browser/branchmergeproposal.py
@@ -767,6 +767,12 @@ class BranchMergeProposalView(LaunchpadFormView, UnmergedRevisionsMixin,
767 mp, description, title, edit_view='+edit-description')767 mp, description, title, edit_view='+edit-description')
768768
769 @property769 @property
770 def opengraph_description(self):
771 if self.context.commit_message:
772 return self.context.commit_message
773 return self.page_description
774
775 @property
770 def edit_commit_message_link_class(self):776 def edit_commit_message_link_class(self):
771 if self.context.commit_message:777 if self.context.commit_message:
772 return "hidden"778 return "hidden"
diff --git a/lib/lp/code/browser/tests/test_branchmergeproposal.py b/lib/lp/code/browser/tests/test_branchmergeproposal.py
index e42a9c5..515b2d4 100644
--- a/lib/lp/code/browser/tests/test_branchmergeproposal.py
+++ b/lib/lp/code/browser/tests/test_branchmergeproposal.py
@@ -2203,6 +2203,20 @@ class TestBranchMergeProposal(BrowserTestCase):
2203 view = create_initialized_view(bmp, '+index')2203 view = create_initialized_view(bmp, '+index')
2204 self.assertFalse(view.show_rescan_link)2204 self.assertFalse(view.show_rescan_link)
22052205
2206 def test_opengraph_description_is_commit(self):
2207 bmp = self.factory.makeBranchMergeProposalForGit()
2208 target_job = getUtility(IGitRefScanJobSource).create(
2209 bmp.target_git_repository)
2210 removeSecurityProxy(target_job).job._status = JobStatus.COMPLETED
2211 source_job = getUtility(IGitRefScanJobSource).create(
2212 bmp.source_git_repository)
2213 removeSecurityProxy(source_job).job._status = JobStatus.COMPLETED
2214 view = create_initialized_view(bmp, '+index')
2215 self.assertEqual(
2216 view.opengraph_description, view.context.commit_message)
2217 self.assertEqual(
2218 view.page_description, bmp.description)
2219
22062220
2207class TestBranchMergeProposalRescanView(BrowserTestCase):2221class TestBranchMergeProposalRescanView(BrowserTestCase):
22082222
diff --git a/lib/lp/services/webapp/publisher.py b/lib/lp/services/webapp/publisher.py
index fccb857..a3b8e70 100644
--- a/lib/lp/services/webapp/publisher.py
+++ b/lib/lp/services/webapp/publisher.py
@@ -369,6 +369,17 @@ class LaunchpadView(UserAttributeCache):
369 return getattr(self.context, 'description', None)369 return getattr(self.context, 'description', None)
370370
371 @property371 @property
372 def opengraph_description(self):
373 """Return a string for the description used in the OpenGraph metadata
374
375 Some pages may wish to override the values used in the OpenGraph
376 metadata to provide more useful link previews.
377
378 Default to the page_description in the base views.
379 """
380 return self.page_description
381
382 @property
372 def template(self):383 def template(self):
373 """The page's template, if configured in zcml."""384 """The page's template, if configured in zcml."""
374 return self.index385 return self.index

Subscribers

People subscribed via source and target branches

to status/vote changes: