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

Proposed by Henning Eggers
Status: Merged
Approved by: Eleanor Berger
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 Approve
Eleanor Berger (community) code Approve
Review via email: mp+12152@code.launchpad.net
To post a comment you must log in.
Revision history for this message
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.

Revision history for this message
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...

Revision history for this message
Henning Eggers (henninge) wrote :

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

Thanks, Tom, for the good idea! ;)

Henning

Revision history for this message
Eleanor Berger (intellectronica) :
review: Approve (code)
Revision history for this message
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
=== modified file 'lib/lp/registry/browser/root.py'
--- lib/lp/registry/browser/root.py 2009-09-19 08:41:49 +0000
+++ lib/lp/registry/browser/root.py 2009-09-21 09:30:32 +0000
@@ -12,6 +12,7 @@
1212
13import re13import re
14import sys14import sys
15import time
1516
16from zope.component import getUtility17from zope.component import getUtility
17from zope.error.interfaces import IErrorReportingUtility18from zope.error.interfaces import IErrorReportingUtility
@@ -55,8 +56,29 @@
5556
56 # The homepage has two columns to hold featured projects. This57 # The homepage has two columns to hold featured projects. This
57 # determines the number of projects we display in each column.58 # determines the number of projects we display in each column.
58 FEATURED_PROJECT_ROWS = 559 FEATURED_PROJECT_ROWS = 10
59 MAX_FEATURED_PROJECTS = FEATURED_PROJECT_ROWS * 2 + 160
61 featured_projects = []
62 featured_projects_top = None
63
64 def initialize(self):
65 """Set up featured projects list and the top featured project.
66
67
68 """
69 super(LaunchpadRootIndexView, self).initialize()
70 if self.request.has_key('assume_date'):
71 day_of_year = time.strptime(
72 self.request['assume_date'], "%Y-%m-%d")[7]
73 else:
74 day_of_year = time.gmtime()[7]
75 max_projects = self.FEATURED_PROJECT_ROWS * 2 + 1
76 self.featured_projects = list(
77 getUtility(IPillarNameSet).featured_projects)[:max_projects]
78 # Select and get the top featured project (project of the day) and
79 # remove it from the list.
80 top_project = day_of_year % len(self.featured_projects)
81 self.featured_projects_top = self.featured_projects.pop(top_project)
6082
61 def canRedirect(self):83 def canRedirect(self):
62 """Return True if the beta server is available to the user."""84 """Return True if the beta server is available to the user."""
@@ -77,26 +99,16 @@
77 getUtility(ILaunchpadCelebrities).ubuntu),99 getUtility(ILaunchpadCelebrities).ubuntu),
78 }100 }
79101
80 @cachedproperty
81 def featured_projects(self):
82 """Return a list of featured projects."""
83 return getUtility(IPillarNameSet).featured_projects
84
85 @property
86 def featured_projects_top(self):
87 """Return the topmost featured project."""
88 return self.featured_projects[0]
89
90 @property102 @property
91 def featured_projects_col_a(self):103 def featured_projects_col_a(self):
92 """Return a list of featured projects."""104 """Return a list of featured projects."""
93 return self.featured_projects[1:self.FEATURED_PROJECT_ROWS+1]105 return self.featured_projects[:self.FEATURED_PROJECT_ROWS]
94106
95 @property107 @property
96 def featured_projects_col_b(self):108 def featured_projects_col_b(self):
97 """The list of featured projects."""109 """The list of featured projects."""
98 index_from = self.FEATURED_PROJECT_ROWS+1110 index_from = self.FEATURED_PROJECT_ROWS
99 index_to = self.MAX_FEATURED_PROJECTS111 index_to = self.FEATURED_PROJECT_ROWS*2
100 return self.featured_projects[index_from:index_to]112 return self.featured_projects[index_from:index_to]
101113
102 @property114 @property
103115
=== modified file 'lib/lp/registry/stories/launchpad-root/xx-featuredprojects.txt'
--- lib/lp/registry/stories/launchpad-root/xx-featuredprojects.txt 2009-09-18 18:04:16 +0000
+++ lib/lp/registry/stories/launchpad-root/xx-featuredprojects.txt 2009-09-21 09:30:32 +0000
@@ -9,22 +9,43 @@
99
10== The home page listing ==10== The home page listing ==
1111
12Featured projects are visible to everyone on the home page:12Featured projects are visible to everyone on the home page. One poject is
13featured as "project of the day" depending on the current day. For the test
14we tell the page which date to assume.:
1315
14 >>> anon_browser.open('http://launchpad.dev/')16 >>> anon_browser.open('http://launchpad.dev/?assume_date=2009-09-21')
15 >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')17 >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')
16 >>> print extract_text(featured.h2)18 >>> print extract_text(featured.h2)
17 Featured projects19 Featured projects
1820
19We show the featured projects in our sample data:21We show the featured projects in our sample data, the "project of the day" is
2022"Gentoo" and it is listed first:
21 >>> for link in featured.findAll('a'):23
22 ... print extract_text(link)24 >>> for link in featured.findAll('a'):
23 Gnome Applets25 ... print extract_text(link)
24 Bazaar26 Gentoo
25 Mozilla Firefox27 Gnome Applets
26 Gentoo28 Bazaar
27 GNOME29 Mozilla Firefox
30 GNOME
31 GNOME Terminal
32 the Mozilla Project
33 Mozilla Thunderbird
34 Ubuntu
35 Browse all ... projects
36
37On the next day, another project (next in the list alphabetically) will be
38project of the day.
39
40 >>> anon_browser.open('http://launchpad.dev/?assume_date=2009-09-22')
41 >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')
42 >>> for link in featured.findAll('a'):
43 ... print extract_text(link)
44 GNOME
45 Gnome Applets
46 Bazaar
47 Mozilla Firefox
48 Gentoo
28 GNOME Terminal49 GNOME Terminal
29 the Mozilla Project50 the Mozilla Project
30 Mozilla Thunderbird51 Mozilla Thunderbird
@@ -76,16 +97,16 @@
76Just to be certain, we will iterate the list as we did before and see97Just to be certain, we will iterate the list as we did before and see
77that Apache has been added:98that Apache has been added:
7899
79 >>> anon_browser.open('http://launchpad.dev/')100 >>> anon_browser.open('http://launchpad.dev/?assume_date=2009-09-22')
80 >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')101 >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')
81 >>> for link in featured.findAll('a'):102 >>> for link in featured.findAll('a'):
82 ... print extract_text(link)103 ... print extract_text(link)
104 GNOME
83 Apache105 Apache
84 Gnome Applets106 Gnome Applets
85 Bazaar107 Bazaar
86 Mozilla Firefox108 Mozilla Firefox
87 Gentoo109 Gentoo
88 GNOME
89 GNOME Terminal110 GNOME Terminal
90 the Mozilla Project111 the Mozilla Project
91 Mozilla Thunderbird112 Mozilla Thunderbird
@@ -107,15 +128,15 @@
107Just to be certain, we will iterate the list as we did before and see128Just to be certain, we will iterate the list as we did before and see
108that Apache has been removed:129that Apache has been removed:
109130
110 >>> anon_browser.open('http://launchpad.dev/')131 >>> anon_browser.open('http://launchpad.dev/?assume_date=2009-09-22')
111 >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')132 >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')
112 >>> for link in featured.findAll('a'):133 >>> for link in featured.findAll('a'):
113 ... print extract_text(link)134 ... print extract_text(link)
135 GNOME
114 Gnome Applets136 Gnome Applets
115 Bazaar137 Bazaar
116 Mozilla Firefox138 Mozilla Firefox
117 Gentoo139 Gentoo
118 GNOME
119 GNOME Terminal140 GNOME Terminal
120 the Mozilla Project141 the Mozilla Project
121 Mozilla Thunderbird142 Mozilla Thunderbird

Subscribers

People subscribed via source and target branches

to status/vote changes: