Merge lp:~thumper/launchpad/code-imports-for-products into lp:launchpad

Proposed by Tim Penhey on 2010-01-14
Status: Merged
Approved by: Michael Hudson-Doyle on 2010-01-14
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~thumper/launchpad/code-imports-for-products
Merge into: lp:launchpad
Diff against target: 154 lines (+43/-9)
5 files modified
lib/lp/code/browser/branchlisting.py (+1/-1)
lib/lp/code/browser/codeimport.py (+25/-3)
lib/lp/code/browser/configure.zcml (+6/-0)
lib/lp/code/stories/codeimport/xx-create-codeimport.txt (+6/-2)
lib/lp/code/templates/codeimport-new.pt (+5/-3)
To merge this branch: bzr merge lp:~thumper/launchpad/code-imports-for-products
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle 2010-01-14 Approve on 2010-01-14
Review via email: mp+17338@code.launchpad.net

Commit Message

Have a +new-import view hang off product which doesn't ask for the product name.

To post a comment you must log in.
Tim Penhey (thumper) wrote :

When requesting a code import for a known product, you shouldn't be asked to type in the product name again.

stories/codeimport/xx-create-codeimport.txt

Michael Hudson-Doyle (mwhudson) wrote :

Looks fine! yay.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/browser/branchlisting.py'
2--- lib/lp/code/browser/branchlisting.py 2009-11-11 01:53:33 +0000
3+++ lib/lp/code/browser/branchlisting.py 2010-01-14 02:09:16 +0000
4@@ -1128,7 +1128,7 @@
5 def code_import(self):
6 text = 'Import your project'
7 enabled = not self.context.official_codehosting
8- return Link('/+code-imports/+new', text, icon='add', enabled=enabled)
9+ return Link('+new-import', text, icon='add', enabled=enabled)
10
11
12 class ProductBranchListingView(BranchListingView):
13
14=== modified file 'lib/lp/code/browser/codeimport.py'
15--- lib/lp/code/browser/codeimport.py 2009-12-08 02:32:03 +0000
16+++ lib/lp/code/browser/codeimport.py 2010-01-14 02:09:16 +0000
17@@ -40,6 +40,7 @@
18 ICodeImport, ICodeImportSet)
19 from lp.code.interfaces.codeimportmachine import ICodeImportMachineSet
20 from lp.code.interfaces.branch import BranchExists, IBranch
21+from lp.registry.interfaces.product import IProduct
22 from canonical.launchpad.webapp import (
23 action, canonical_url, custom_widget, LaunchpadFormView, LaunchpadView,
24 Navigation, stepto)
25@@ -218,7 +219,6 @@
26 """The view to request a new code import."""
27
28 for_input = True
29- label = 'Request a code import'
30 field_names = [
31 'product', 'rcs_type', 'svn_branch_url', 'cvs_root', 'cvs_module',
32 'git_repo_url',
33@@ -232,12 +232,26 @@
34 }
35
36 @property
37+ def context_is_product(self):
38+ return IProduct.providedBy(self.context)
39+
40+ @property
41+ def label(self):
42+ if self.context_is_product:
43+ return 'Request a code import for %s' % self.context.displayname
44+ else:
45+ return 'Request a code import'
46+
47+ @property
48 def cancel_url(self):
49 """Cancel should take the user back to the root site."""
50 return '/'
51
52 def setUpFields(self):
53 CodeImportBaseView.setUpFields(self)
54+ if self.context_is_product:
55+ self.form_fields = self.form_fields.omit('product')
56+
57 # Add in the field for the branch name.
58 name_field = form.Fields(
59 TextLine(
60@@ -270,9 +284,10 @@
61
62 def _create_import(self, data, status):
63 """Create the code import."""
64+ product = self.getProduct(data)
65 return getUtility(ICodeImportSet).new(
66 registrant=self.user,
67- product=data['product'],
68+ product=product,
69 branch_name=data['branch_name'],
70 rcs_type=data['rcs_type'],
71 svn_branch_url=data['svn_branch_url'],
72@@ -338,12 +353,19 @@
73 self.request.response.addNotification(
74 "New reviewed code import created.")
75
76+ def getProduct(self, data):
77+ """If the context is a product, use that, otherwise get from data."""
78+ if self.context_is_product:
79+ return self.context
80+ else:
81+ return data.get('product')
82+
83 def validate(self, data):
84 """See `LaunchpadFormView`."""
85 # Make sure that the user is able to create branches for the specified
86 # namespace.
87 celebs = getUtility(ILaunchpadCelebrities)
88- product = data.get('product')
89+ product = self.getProduct(data)
90 if product is not None:
91 namespace = get_branch_namespace(celebs.vcs_imports, product)
92 policy = IBranchNamespacePolicy(namespace)
93
94=== modified file 'lib/lp/code/browser/configure.zcml'
95--- lib/lp/code/browser/configure.zcml 2009-12-10 01:33:59 +0000
96+++ lib/lp/code/browser/configure.zcml 2010-01-14 02:09:16 +0000
97@@ -686,6 +686,12 @@
98 name="+new"
99 template="../templates/codeimport-new.pt"
100 permission="launchpad.AnyPerson"/>
101+ <browser:page
102+ for="lp.registry.interfaces.product.IProduct"
103+ class="lp.code.browser.codeimport.CodeImportNewView"
104+ name="+new-import"
105+ template="../templates/codeimport-new.pt"
106+ permission="launchpad.AnyPerson"/>
107 </facet>
108 <browser:navigation
109 module="lp.code.browser.codeimport"
110
111=== modified file 'lib/lp/code/stories/codeimport/xx-create-codeimport.txt'
112--- lib/lp/code/stories/codeimport/xx-create-codeimport.txt 2009-12-08 02:32:03 +0000
113+++ lib/lp/code/stories/codeimport/xx-create-codeimport.txt 2010-01-14 02:09:16 +0000
114@@ -22,7 +22,12 @@
115 >>> browser.getLink('Cancel').click()
116 >>> print browser.url
117 http://code.launchpad.dev/
118- >>> browser.getLink(id="new-code-import").click()
119+
120+For projects that don't officially use Launchpad for code, there is also a
121+link on the main branch listing page for the product.
122+
123+ >>> browser.open('http://code.launchpad.dev/firefox')
124+ >>> browser.getLink('Import your project').click()
125
126
127 Requesting a Subversion import
128@@ -38,7 +43,6 @@
129 The user is required to enter a project that the import is for,
130 a name for the import branch, and a subversion branch location.
131
132- >>> browser.getControl('Project').value = "firefox"
133 >>> browser.getControl('Branch Name').value = "imported"
134 >>> browser.getControl('Branch URL').value = (
135 ... "http://svn.example.com/firefox/trunk")
136
137=== modified file 'lib/lp/code/templates/codeimport-new.pt'
138--- lib/lp/code/templates/codeimport-new.pt 2009-12-08 02:32:03 +0000
139+++ lib/lp/code/templates/codeimport-new.pt 2010-01-14 02:09:16 +0000
140@@ -30,9 +30,11 @@
141
142 <table class="form">
143
144- <tal:widget define="widget nocall:view/widgets/product">
145- <metal:block use-macro="context/@@launchpad_form/widget_row" />
146- </tal:widget>
147+ <tal:show-product condition="not: view/context_is_product">
148+ <tal:widget define="widget nocall:view/widgets/product">
149+ <metal:block use-macro="context/@@launchpad_form/widget_row" />
150+ </tal:widget>
151+ </tal:show-product>
152 <tal:widget define="widget nocall:view/widgets/branch_name">
153 <metal:block use-macro="context/@@launchpad_form/widget_row" />
154 </tal:widget>