Merge lp:~henninge/launchpad/bug-433824 into lp:launchpad/db-devel

Proposed by Henning Eggers on 2009-09-21
Status: Merged
Approved by: Eleanor Berger on 2009-09-21
Approved revision: no longer in the source branch.
Merge reported by: Henning Eggers
Merged at revision: not available
Proposed branch: lp:~henninge/launchpad/bug-433824
Merge into: lp:launchpad/db-devel
Diff against target: None lines
To merge this branch: bzr merge lp:~henninge/launchpad/bug-433824
Reviewer Review Type Date Requested Status
Brad Crittenden (community) release-critical 2009-09-21 Approve on 2009-09-21
Eleanor Berger (community) code 2009-09-21 Approve on 2009-09-21
Review via email: mp+12152@code.launchpad.net
To post a comment you must log in.
Henning Eggers (henninge) wrote :

= Summary =

See bug 433824 description. Beuno asked for 'project of the day' implementation which this branch does.

It also sets the number of featured project rows back to 10, like it was pre-3.0. I had made it smaller during work because the list is shorter in the test data.

== Implementation notes ==

To be able to test the featured project list, the view accepts an "assume_date" parameter to use instead of the current date.

== Test ==

bin/test -vvct featuredproject

== Demo/QA ==

https://launchpad.dev/
https://launchpad.dev/?assume_date=2009-09-20

The latter should display Mozilla Firefox as the top project.

Henning Eggers (henninge) wrote :
Download full text (5.3 KiB)

=== modified file 'lib/lp/registry/browser/root.py'
--- lib/lp/registry/browser/root.py 2009-09-21 09:30:32 +0000
+++ lib/lp/registry/browser/root.py 2009-09-21 13:15:18 +0000
@@ -57,27 +57,32 @@
     # The homepage has two columns to hold featured projects. This
     # determines the number of projects we display in each column.
     FEATURED_PROJECT_ROWS = 10
+ FEATURED_PROJECT_COLS = 2

     featured_projects = []
     featured_projects_top = None

+ @staticmethod
+ def _get_day_of_year():
+ """Calculate the number of the current day.
+
+ This method gets overridden in tests to make the selection of the
+ top featured project deterministic.
+ """
+ return time.gmtime()[7]
+
     def initialize(self):
- """Set up featured projects list and the top featured project.
-
-
- """
+ """Set up featured projects list and the top featured project."""
         super(LaunchpadRootIndexView, self).initialize()
- if self.request.has_key('assume_date'):
- day_of_year = time.strptime(
- self.request['assume_date'], "%Y-%m-%d")[7]
- else:
- day_of_year = time.gmtime()[7]
- max_projects = self.FEATURED_PROJECT_ROWS * 2 + 1
+ # The maximum number of projects to be displayed as defined by the
+ # number and size of the columns plus one top featured project.
+ max_projects = (
+ self.FEATURED_PROJECT_ROWS * self.FEATURED_PROJECT_COLS + 1)
         self.featured_projects = list(
             getUtility(IPillarNameSet).featured_projects)[:max_projects]
         # Select and get the top featured project (project of the day) and
         # remove it from the list.
- top_project = day_of_year % len(self.featured_projects)
+ top_project = self._get_day_of_year() % len(self.featured_projects)
         self.featured_projects_top = self.featured_projects.pop(top_project)

     def canRedirect(self):
@@ -108,7 +113,7 @@
     def featured_projects_col_b(self):
         """The list of featured projects."""
         index_from = self.FEATURED_PROJECT_ROWS
- index_to = self.FEATURED_PROJECT_ROWS*2
+ index_to = self.FEATURED_PROJECT_ROWS * 2
         return self.featured_projects[index_from:index_to]

     @property

=== modified file 'lib/lp/registry/stories/launchpad-root/xx-featuredprojects.txt'
--- lib/lp/registry/stories/launchpad-root/xx-featuredprojects.txt 2009-09-21 09:30:32 +0000
+++ lib/lp/registry/stories/launchpad-root/xx-featuredprojects.txt 2009-09-21 11:18:24 +0000
@@ -10,35 +10,23 @@
 == The home page listing ==

 Featured projects are visible to everyone on the home page. One poject is
-featured as "project of the day" depending on the current day. For the test
-we tell the page which date to assume.:
+featured as "project of the day" depending on the current day. As we do not
+know the current day, we replace that selection method in the view with a
+constant value.

- >>> anon_browser.open('http://launchpad.dev/?assume_date=2009-09-21')
+ >>> def fake_get_day_of_year():
+ ... return 4
+ >>> from lp.registry.browser.root import LaunchpadRootIndexV...

Read more...

Henning Eggers (henninge) wrote :

That up there is the incremental diff after discussion with Tom on IRC.

Thanks, Tom, for the good idea! ;)

Henning

review: Approve (code)
Brad Crittenden (bac) wrote :

This branch looks good Henning.

Please merge release-critical=bac into devel.

review: Approve (release-critical)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/browser/root.py'
2--- lib/lp/registry/browser/root.py 2009-09-19 08:41:49 +0000
3+++ lib/lp/registry/browser/root.py 2009-09-21 09:30:32 +0000
4@@ -12,6 +12,7 @@
5
6 import re
7 import sys
8+import time
9
10 from zope.component import getUtility
11 from zope.error.interfaces import IErrorReportingUtility
12@@ -55,8 +56,29 @@
13
14 # The homepage has two columns to hold featured projects. This
15 # determines the number of projects we display in each column.
16- FEATURED_PROJECT_ROWS = 5
17- MAX_FEATURED_PROJECTS = FEATURED_PROJECT_ROWS * 2 + 1
18+ FEATURED_PROJECT_ROWS = 10
19+
20+ featured_projects = []
21+ featured_projects_top = None
22+
23+ def initialize(self):
24+ """Set up featured projects list and the top featured project.
25+
26+
27+ """
28+ super(LaunchpadRootIndexView, self).initialize()
29+ if self.request.has_key('assume_date'):
30+ day_of_year = time.strptime(
31+ self.request['assume_date'], "%Y-%m-%d")[7]
32+ else:
33+ day_of_year = time.gmtime()[7]
34+ max_projects = self.FEATURED_PROJECT_ROWS * 2 + 1
35+ self.featured_projects = list(
36+ getUtility(IPillarNameSet).featured_projects)[:max_projects]
37+ # Select and get the top featured project (project of the day) and
38+ # remove it from the list.
39+ top_project = day_of_year % len(self.featured_projects)
40+ self.featured_projects_top = self.featured_projects.pop(top_project)
41
42 def canRedirect(self):
43 """Return True if the beta server is available to the user."""
44@@ -77,26 +99,16 @@
45 getUtility(ILaunchpadCelebrities).ubuntu),
46 }
47
48- @cachedproperty
49- def featured_projects(self):
50- """Return a list of featured projects."""
51- return getUtility(IPillarNameSet).featured_projects
52-
53- @property
54- def featured_projects_top(self):
55- """Return the topmost featured project."""
56- return self.featured_projects[0]
57-
58 @property
59 def featured_projects_col_a(self):
60 """Return a list of featured projects."""
61- return self.featured_projects[1:self.FEATURED_PROJECT_ROWS+1]
62+ return self.featured_projects[:self.FEATURED_PROJECT_ROWS]
63
64 @property
65 def featured_projects_col_b(self):
66 """The list of featured projects."""
67- index_from = self.FEATURED_PROJECT_ROWS+1
68- index_to = self.MAX_FEATURED_PROJECTS
69+ index_from = self.FEATURED_PROJECT_ROWS
70+ index_to = self.FEATURED_PROJECT_ROWS*2
71 return self.featured_projects[index_from:index_to]
72
73 @property
74
75=== modified file 'lib/lp/registry/stories/launchpad-root/xx-featuredprojects.txt'
76--- lib/lp/registry/stories/launchpad-root/xx-featuredprojects.txt 2009-09-18 18:04:16 +0000
77+++ lib/lp/registry/stories/launchpad-root/xx-featuredprojects.txt 2009-09-21 09:30:32 +0000
78@@ -9,22 +9,43 @@
79
80 == The home page listing ==
81
82-Featured projects are visible to everyone on the home page:
83+Featured projects are visible to everyone on the home page. One poject is
84+featured as "project of the day" depending on the current day. For the test
85+we tell the page which date to assume.:
86
87- >>> anon_browser.open('http://launchpad.dev/')
88+ >>> anon_browser.open('http://launchpad.dev/?assume_date=2009-09-21')
89 >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')
90 >>> print extract_text(featured.h2)
91 Featured projects
92
93-We show the featured projects in our sample data:
94-
95- >>> for link in featured.findAll('a'):
96- ... print extract_text(link)
97- Gnome Applets
98- Bazaar
99- Mozilla Firefox
100- Gentoo
101- GNOME
102+We show the featured projects in our sample data, the "project of the day" is
103+"Gentoo" and it is listed first:
104+
105+ >>> for link in featured.findAll('a'):
106+ ... print extract_text(link)
107+ Gentoo
108+ Gnome Applets
109+ Bazaar
110+ Mozilla Firefox
111+ GNOME
112+ GNOME Terminal
113+ the Mozilla Project
114+ Mozilla Thunderbird
115+ Ubuntu
116+ Browse all ... projects
117+
118+On the next day, another project (next in the list alphabetically) will be
119+project of the day.
120+
121+ >>> anon_browser.open('http://launchpad.dev/?assume_date=2009-09-22')
122+ >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')
123+ >>> for link in featured.findAll('a'):
124+ ... print extract_text(link)
125+ GNOME
126+ Gnome Applets
127+ Bazaar
128+ Mozilla Firefox
129+ Gentoo
130 GNOME Terminal
131 the Mozilla Project
132 Mozilla Thunderbird
133@@ -76,16 +97,16 @@
134 Just to be certain, we will iterate the list as we did before and see
135 that Apache has been added:
136
137- >>> anon_browser.open('http://launchpad.dev/')
138+ >>> anon_browser.open('http://launchpad.dev/?assume_date=2009-09-22')
139 >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')
140 >>> for link in featured.findAll('a'):
141 ... print extract_text(link)
142+ GNOME
143 Apache
144 Gnome Applets
145 Bazaar
146 Mozilla Firefox
147 Gentoo
148- GNOME
149 GNOME Terminal
150 the Mozilla Project
151 Mozilla Thunderbird
152@@ -107,15 +128,15 @@
153 Just to be certain, we will iterate the list as we did before and see
154 that Apache has been removed:
155
156- >>> anon_browser.open('http://launchpad.dev/')
157+ >>> anon_browser.open('http://launchpad.dev/?assume_date=2009-09-22')
158 >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')
159 >>> for link in featured.findAll('a'):
160 ... print extract_text(link)
161+ GNOME
162 Gnome Applets
163 Bazaar
164 Mozilla Firefox
165 Gentoo
166- GNOME
167 GNOME Terminal
168 the Mozilla Project
169 Mozilla Thunderbird

Subscribers

People subscribed via source and target branches

to status/vote changes: