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
=== modified file 'lib/lp/translations/browser/language.py'
--- lib/lp/translations/browser/language.py 2009-10-31 11:06:44 +0000
+++ lib/lp/translations/browser/language.py 2009-12-07 08:29:12 +0000
@@ -17,6 +17,9 @@
17from zope.lifecycleevent import ObjectCreatedEvent17from zope.lifecycleevent import ObjectCreatedEvent
18from zope.component import getUtility18from zope.component import getUtility
19from zope.event import notify19from zope.event import notify
20from zope.app.form.browser import TextWidget
21from zope.interface import Interface
22from zope.schema import TextLine
2023
21from canonical.cachedproperty import cachedproperty24from canonical.cachedproperty import cachedproperty
22from canonical.launchpad.webapp.breadcrumb import Breadcrumb25from canonical.launchpad.webapp.breadcrumb import Breadcrumb
@@ -79,16 +82,32 @@
79 return Link('+admin', text, icon='edit')82 return Link('+admin', text, icon='edit')
8083
8184
82class LanguageSetView:85class ILanguageSetSearch(Interface):
86 """The collection of languages."""
87
88 search_lang = TextLine(
89 title=u'Name of the language to search for.',
90 required=True)
91
92class LanguageSetView(LaunchpadFormView):
83 """View class to render main ILanguageSet page."""93 """View class to render main ILanguageSet page."""
84 label = "Languages in Launchpad"94 label = "Languages in Launchpad"
85 page_title = "Languages"95 page_title = "Languages"
8696
87 def __init__(self, context, request):97 schema = ILanguageSetSearch
88 self.context = context98
89 self.request = request99 custom_widget('search_lang', TextWidget, displayWidth=30)
90 form = self.request.form100
91 self.language_search = form.get('find')101 def initialize(self):
102 """See `LaunchpadFormView`."""
103 LaunchpadFormView.initialize(self)
104
105 self.language_search = None
106
107 search_lang_widget = self.widgets.get('search_lang')
108 if (search_lang_widget is not None and
109 search_lang_widget.hasValidInput()):
110 self.language_search = search_lang_widget.getInputValue()
92 self.search_requested = self.language_search is not None111 self.search_requested = self.language_search is not None
93112
94 @cachedproperty113 @cachedproperty
95114
=== modified file 'lib/lp/translations/stories/standalone/xx-language.txt'
--- lib/lp/translations/stories/standalone/xx-language.txt 2009-10-31 11:06:44 +0000
+++ lib/lp/translations/stories/standalone/xx-language.txt 2009-12-07 08:29:12 +0000
@@ -76,11 +76,11 @@
76 >>> print browser.url76 >>> print browser.url
77 http://translations.launchpad.dev/+languages77 http://translations.launchpad.dev/+languages
7878
79 >>> text_search = browser.getControl(name='find')79 >>> text_search = browser.getControl(name='field.search_lang')
80 >>> text_search.value = 'Spanish'80 >>> text_search.value = 'Spanish'
81 >>> browser.getControl('Find language', index=0).click()81 >>> browser.getControl('Find language', index=0).click()
82 >>> print browser.url82 >>> print browser.url
83 http://translations.launchpad.dev/+languages/+index?find=Spanish83 http://translations.launchpad.dev/+languages/+index?field.search_lang=Spanish
8484
85And following one of the found languages, we can see a brief information85And following one of the found languages, we can see a brief information
86about the selected language.86about the selected language.
8787
=== modified file 'lib/lp/translations/templates/languageset-index.pt'
--- lib/lp/translations/templates/languageset-index.pt 2009-10-31 11:06:44 +0000
+++ lib/lp/translations/templates/languageset-index.pt 2009-12-07 08:29:12 +0000
@@ -33,13 +33,20 @@
33 Language name/code contains:33 Language name/code contains:
34 </label>34 </label>
35 <input35 <input
36 name="find" size="30"36 size="30"
37 tal:attributes="value view/language_search" />37 tal:replace="structure view/widgets/search_lang"
38 />
38 <input39 <input
39 type="submit"40 type="submit"
40 value="Find language"41 value="Find language"
41 />42 />
42 </p>43 </p>
44 <tal:none condition="not: view/search_matches">
45 <script type="text/javascript"
46 tal:define="script view/focusedElementScript"
47 tal:condition="script"
48 tal:content="structure script" />
49 </tal:none>
43 </form>50 </form>
44 <div tal:condition="context/required:launchpad.Admin">51 <div tal:condition="context/required:launchpad.Admin">
45 <a tal:attributes="href context/fmt:url/+add"52 <a tal:attributes="href context/fmt:url/+add"