Merge lp:~adiroiban/launchpad/bug-135008 into lp:launchpad

Proposed by Adi Roiban
Status: Merged
Approved by: Aaron Bentley
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~adiroiban/launchpad/bug-135008
Merge into: lp:launchpad
Diff against target: 97 lines (+36/-10)
3 files modified
lib/lp/translations/browser/language.py (+25/-6)
lib/lp/translations/stories/standalone/xx-language.txt (+2/-2)
lib/lp/translations/templates/languageset-index.pt (+9/-2)
To merge this branch: bzr merge lp:~adiroiban/launchpad/bug-135008
Reviewer Review Type Date Requested Status
Aaron Bentley (community) code Approve
Review via email: mp+15347@code.launchpad.net

Commit message

Auto-focus the search field when translations.lp.net/+languages is loaded.

To post a comment you must log in.
Revision history for this message
Adi Roiban (adiroiban) wrote :

= Bug 135008 =
== Proposed fix ==

Right now when you access the translations.lp.net/+languages page, the search field is not focused and you will need click the search field first.

The fix should focus the search field when the page is loaded.
Also after a search strings was entered and it matched some languages, the field is not focused and you can use the up/down key to scroll the page.

If the search string did not match any language, the search field will be focused and highlighted for entering a new search string.

== Implementation details ==

Update LanguageSetView to be a LaunchpadFormView and also do the required changes in languageset-index.pt.

== Tests ==

bin/test -ct language

== Demo and Q/A ==

Go to https://translations.launchpad.dev/+languages

On a browser with javascript enabled you should see that the search
field is focused and you can start typing right away.

Now type a search string, ex "es" and then Enter or push the button.

You should see a series of results and the search field no longer being focused.

That's all.

= 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/services/worlddata/interfaces/language.py
  lib/lp/translations/browser/language.py
  lib/lp/translations/stories/standalone/xx-language.txt
  lib/lp/translations/templates/languageset-index.pt

== Pylint notices ==

lib/lp/services/worlddata/interfaces/language.py
    18: [F0401] Unable to import 'lazr.enum' (No module named enum)
    20: [F0401] Unable to import 'lazr.restful.declarations' (No module named restful)

Revision history for this message
Aaron Bentley (abentley) wrote :

search_lang should not be part of the ILanguageSet interface, because ILanguageSet is meant to be the interface of a model object. I recommend adding an ISearchLanguage interface in lib/lp/translations/browser/language.py instead. This will remove the need for LanguageSetView.field_names.

review: Needs Resubmitting (code)
Revision history for this message
Adi Roiban (adiroiban) wrote :

I have pushed the required changes.

lib/lp/services/worlddata/interfaces/language.py should be clean.

Please take a look and give the required feedback,

Many thanks!

Revision history for this message
Aaron Bentley (abentley) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/browser/language.py'
2--- lib/lp/translations/browser/language.py 2009-10-31 11:06:44 +0000
3+++ lib/lp/translations/browser/language.py 2009-12-07 08:29:12 +0000
4@@ -17,6 +17,9 @@
5 from zope.lifecycleevent import ObjectCreatedEvent
6 from zope.component import getUtility
7 from zope.event import notify
8+from zope.app.form.browser import TextWidget
9+from zope.interface import Interface
10+from zope.schema import TextLine
11
12 from canonical.cachedproperty import cachedproperty
13 from canonical.launchpad.webapp.breadcrumb import Breadcrumb
14@@ -79,16 +82,32 @@
15 return Link('+admin', text, icon='edit')
16
17
18-class LanguageSetView:
19+class ILanguageSetSearch(Interface):
20+ """The collection of languages."""
21+
22+ search_lang = TextLine(
23+ title=u'Name of the language to search for.',
24+ required=True)
25+
26+class LanguageSetView(LaunchpadFormView):
27 """View class to render main ILanguageSet page."""
28 label = "Languages in Launchpad"
29 page_title = "Languages"
30
31- def __init__(self, context, request):
32- self.context = context
33- self.request = request
34- form = self.request.form
35- self.language_search = form.get('find')
36+ schema = ILanguageSetSearch
37+
38+ custom_widget('search_lang', TextWidget, displayWidth=30)
39+
40+ def initialize(self):
41+ """See `LaunchpadFormView`."""
42+ LaunchpadFormView.initialize(self)
43+
44+ self.language_search = None
45+
46+ search_lang_widget = self.widgets.get('search_lang')
47+ if (search_lang_widget is not None and
48+ search_lang_widget.hasValidInput()):
49+ self.language_search = search_lang_widget.getInputValue()
50 self.search_requested = self.language_search is not None
51
52 @cachedproperty
53
54=== modified file 'lib/lp/translations/stories/standalone/xx-language.txt'
55--- lib/lp/translations/stories/standalone/xx-language.txt 2009-10-31 11:06:44 +0000
56+++ lib/lp/translations/stories/standalone/xx-language.txt 2009-12-07 08:29:12 +0000
57@@ -76,11 +76,11 @@
58 >>> print browser.url
59 http://translations.launchpad.dev/+languages
60
61- >>> text_search = browser.getControl(name='find')
62+ >>> text_search = browser.getControl(name='field.search_lang')
63 >>> text_search.value = 'Spanish'
64 >>> browser.getControl('Find language', index=0).click()
65 >>> print browser.url
66- http://translations.launchpad.dev/+languages/+index?find=Spanish
67+ http://translations.launchpad.dev/+languages/+index?field.search_lang=Spanish
68
69 And following one of the found languages, we can see a brief information
70 about the selected language.
71
72=== modified file 'lib/lp/translations/templates/languageset-index.pt'
73--- lib/lp/translations/templates/languageset-index.pt 2009-10-31 11:06:44 +0000
74+++ lib/lp/translations/templates/languageset-index.pt 2009-12-07 08:29:12 +0000
75@@ -33,13 +33,20 @@
76 Language name/code contains:
77 </label>
78 <input
79- name="find" size="30"
80- tal:attributes="value view/language_search" />
81+ size="30"
82+ tal:replace="structure view/widgets/search_lang"
83+ />
84 <input
85 type="submit"
86 value="Find language"
87 />
88 </p>
89+ <tal:none condition="not: view/search_matches">
90+ <script type="text/javascript"
91+ tal:define="script view/focusedElementScript"
92+ tal:condition="script"
93+ tal:content="structure script" />
94+ </tal:none>
95 </form>
96 <div tal:condition="context/required:launchpad.Admin">
97 <a tal:attributes="href context/fmt:url/+add"