Merge lp:~henninge/launchpad/bug-516736-templatename into lp:launchpad

Proposed by Henning Eggers on 2010-04-19
Status: Merged
Approved by: Jeroen T. Vermeulen on 2010-04-19
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~henninge/launchpad/bug-516736-templatename
Merge into: lp:launchpad
Diff against target: 146 lines (+67/-13)
3 files modified
lib/lp/translations/browser/tests/test_translationimportqueueentry.py (+51/-4)
lib/lp/translations/browser/translationimportqueue.py (+12/-7)
lib/lp/translations/stories/importqueue/xx-translation-import-queue-edit-autofilling.txt (+4/-2)
To merge this branch: bzr merge lp:~henninge/launchpad/bug-516736-templatename
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) code 2010-04-19 Approve on 2010-04-19
Review via email: mp+23659@code.launchpad.net

Commit Message

Template name and translation domain are now suggested from the file path in translation import queue entry.

Description of the Change

= Bug 516736 =

Automates extraction of template names and translation domains from the path attribute of import queue entries. This saves having to cut and paste it from the path field, lowser case it and replace underscores with dashes. Very low hanging fruit.

== Test ==

bin/test -vvt TestTranslationImportQueueEntryView

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/lp/translations/browser/translationimportqueue.py
  lib/lp/translations/browser/tests/test_translationimportqueueentry.py

== Pylint notices ==

lib/lp/translations/browser/translationimportqueue.py
    17: [F0401] Unable to import 'zope.app.form.interfaces'
    18: [F0401] Unable to import 'zope.component'
    20: [F0401] Unable to import 'zope.schema.interfaces'
    21: [F0401] Unable to import 'zope.schema.vocabulary'

lib/lp/translations/browser/tests/test_translationimportqueueentry.py
    7: [F0401] Unable to import 'pytz'
    10: [F0401] Unable to import 'zope.component'
    11: [F0401] Unable to import 'zope.security.proxy'

To post a comment you must log in.
Jeroen T. Vermeulen (jtv) wrote :

Looks good. This could save queue reviewers a lot of time!

Jeroen

review: Approve (code)
Henning Eggers (henninge) wrote :

Look at the current queue and you'll see that I was worried about my time .... If only those edge updates were running again.

Cheers.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/browser/tests/test_translationimportqueueentry.py'
2--- lib/lp/translations/browser/tests/test_translationimportqueueentry.py 2010-02-11 13:17:27 +0000
3+++ lib/lp/translations/browser/tests/test_translationimportqueueentry.py 2010-04-19 15:26:34 +0000
4@@ -46,13 +46,14 @@
5 return view
6
7 def _makeEntry(self, productseries=None, distroseries=None,
8- sourcepackagename=None):
9- filename = self.factory.getUniqueString() + '.pot'
10+ sourcepackagename=None, filename=None, potemplate=None):
11+ if filename is None:
12+ filename = self.factory.getUniqueString() + '.pot'
13 contents = self.factory.getUniqueString()
14 entry = self.queue.addOrUpdateEntry(
15 filename, contents, False, self.uploader,
16 productseries=productseries, distroseries=distroseries,
17- sourcepackagename=sourcepackagename)
18+ sourcepackagename=sourcepackagename, potemplate=potemplate)
19 return removeSecurityProxy(entry)
20
21 def test_import_target_productseries(self):
22@@ -142,7 +143,6 @@
23 # status_change_date describes the date of the entry's last
24 # status change.
25 series = self._makeProductSeries()
26- product = series.product
27 entry = self._makeEntry(productseries=series)
28 view = self._makeView(entry)
29
30@@ -159,6 +159,53 @@
31 self.assertEqual(
32 "Last changed on 2007-08-14.", view.status_change_date)
33
34+ def test_initial_values_domain(self):
35+ # Without a given potemplate, a translation domain will be suggested
36+ # from the file name.
37+ series = self._makeProductSeries()
38+ entry = self._makeEntry(
39+ productseries=series, filename="My_Domain.pot")
40+ view = self._makeView(entry)
41+
42+ self.assertEqual(
43+ "My_Domain", view.initial_values['translation_domain'])
44+
45+ def test_initial_values_existing_domain(self):
46+ # With a given potemplate, its translation domain will be presented
47+ # as the initial value.
48+ domain = self.factory.getUniqueString()
49+ series = self._makeProductSeries()
50+ potemplate = self.factory.makePOTemplate(
51+ productseries=series, translation_domain=domain)
52+ entry = self._makeEntry(
53+ productseries=series, potemplate=potemplate)
54+ view = self._makeView(entry)
55+
56+ self.assertEqual(domain, view.initial_values['translation_domain'])
57+
58+ def test_initial_values_potemplate(self):
59+ # Without a given potemplate, a name will be suggested from the file
60+ # name. The name is converted to be suitable as a template name.
61+ series = self._makeProductSeries()
62+ entry = self._makeEntry(
63+ productseries=series, filename="My_Domain.pot")
64+ view = self._makeView(entry)
65+
66+ self.assertEqual("my-domain", view.initial_values['name'])
67+
68+ def test_initial_values_existing_potemplate(self):
69+ # With a given potemplate, its name will be presented
70+ # as the initial value.
71+ name = self.factory.getUniqueString()
72+ series = self._makeProductSeries()
73+ potemplate = self.factory.makePOTemplate(
74+ productseries=series, name=name)
75+ entry = self._makeEntry(
76+ productseries=series, potemplate=potemplate)
77+ view = self._makeView(entry)
78+
79+ self.assertEqual(name, view.initial_values['name'])
80+
81
82 def test_suite():
83 return TestLoader().loadTestsFromName(__name__)
84
85=== modified file 'lib/lp/translations/browser/translationimportqueue.py'
86--- lib/lp/translations/browser/translationimportqueue.py 2010-02-10 13:04:10 +0000
87+++ lib/lp/translations/browser/translationimportqueue.py 2010-04-19 15:26:34 +0000
88@@ -28,13 +28,14 @@
89 HasTranslationImportsView)
90 from lp.registry.interfaces.distroseries import IDistroSeries
91 from lp.registry.interfaces.sourcepackage import ISourcePackageFactory
92+from lp.services.worlddata.interfaces.language import ILanguageSet
93 from lp.translations.interfaces.translationimportqueue import (
94 ITranslationImportQueueEntry, IEditTranslationImportQueueEntry,
95 ITranslationImportQueue, RosettaImportStatus,
96 SpecialTranslationImportTargetFilter, TranslationFileType)
97-from lp.services.worlddata.interfaces.language import ILanguageSet
98 from lp.translations.interfaces.pofile import IPOFileSet
99 from lp.translations.interfaces.potemplate import IPOTemplateSet
100+from lp.translations.utilities.template import make_domain, make_name
101
102 from canonical.launchpad.webapp import (
103 action, canonical_url, GetitemNavigation, LaunchpadFormView)
104@@ -81,12 +82,16 @@
105 field_values['languagepack'] = (
106 self.context.potemplate.languagepack)
107 if (file_type in (TranslationFileType.POT,
108- TranslationFileType.UNSPEC) and
109- self.context.potemplate is not None):
110- field_values['name'] = (
111- self.context.potemplate.name)
112- field_values['translation_domain'] = (
113- self.context.potemplate.translation_domain)
114+ TranslationFileType.UNSPEC)):
115+ potemplate = self.context.potemplate
116+ if potemplate is None:
117+ domain = make_domain(self.context.path)
118+ field_values['name'] = make_name(domain)
119+ field_values['translation_domain'] = domain
120+ else:
121+ field_values['name'] = potemplate.name
122+ field_values['translation_domain'] = (
123+ potemplate.translation_domain)
124 if file_type in (TranslationFileType.PO, TranslationFileType.UNSPEC):
125 field_values['potemplate'] = self.context.potemplate
126 if self.context.pofile is not None:
127
128=== modified file 'lib/lp/translations/stories/importqueue/xx-translation-import-queue-edit-autofilling.txt'
129--- lib/lp/translations/stories/importqueue/xx-translation-import-queue-edit-autofilling.txt 2009-09-01 21:03:51 +0000
130+++ lib/lp/translations/stories/importqueue/xx-translation-import-queue-edit-autofilling.txt 2010-04-19 15:26:34 +0000
131@@ -25,11 +25,13 @@
132 <div...Thank you for your upload. 2 files from the tarball...
133
134 Let's check the values we get by default from the .pot file. The name field
135-is empty.
136+and the translation domain field are pre-filled from the name of the file.
137
138 >>> browser.open('http://translations.launchpad.dev/+imports/4')
139 >>> browser.getControl(name='field.name').value
140- ''
141+ 'test'
142+ >>> browser.getControl(name='field.translation_domain').value
143+ 'test'
144
145 But the path field has been preloaded with the value from the tar ball and
146 the file type has been determined correctly from it.