Code review comment for lp:~henninge/launchpad/bug-433824

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

=== 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 LaunchpadRootIndexView
+ >>> LaunchpadRootIndexView._get_day_of_year = staticmethod(
+ ... fake_get_day_of_year)
+ >>> anon_browser.open('http://launchpad.dev/')
     >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')
     >>> print extract_text(featured.h2)
     Featured projects

 We show the featured projects in our sample data, the "project of the day" is
-"Gentoo" and it is listed first:
-
- >>> for link in featured.findAll('a'):
- ... print extract_text(link)
- Gentoo
- Gnome Applets
- Bazaar
- Mozilla Firefox
- GNOME
- GNOME Terminal
- the Mozilla Project
- Mozilla Thunderbird
- Ubuntu
- Browse all ... projects
-
-On the next day, another project (next in the list alphabetically) will be
-project of the day.
-
- >>> anon_browser.open('http://launchpad.dev/?assume_date=2009-09-22')
- >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')
+"GNOME" and it is listed first:
+
     >>> for link in featured.findAll('a'):
     ... print extract_text(link)
     GNOME
@@ -95,18 +83,19 @@
     True

 Just to be certain, we will iterate the list as we did before and see
-that Apache has been added:
+that Apache has been added. Because the list has changed, a different project
+is now at index '4' and is therefore displayed as the top project:

- >>> anon_browser.open('http://launchpad.dev/?assume_date=2009-09-22')
+ >>> anon_browser.open('http://launchpad.dev/')
     >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')
     >>> for link in featured.findAll('a'):
     ... print extract_text(link)
- GNOME
+ Gentoo
     Apache
     Gnome Applets
     Bazaar
     Mozilla Firefox
- Gentoo
+ GNOME
     GNOME Terminal
     the Mozilla Project
     Mozilla Thunderbird
@@ -128,7 +117,7 @@
 Just to be certain, we will iterate the list as we did before and see
 that Apache has been removed:

- >>> anon_browser.open('http://launchpad.dev/?assume_date=2009-09-22')
+ >>> anon_browser.open('http://launchpad.dev/')
     >>> featured = find_tag_by_id(anon_browser.contents, 'homepage-featured')
     >>> for link in featured.findAll('a'):
     ... print extract_text(link)

« Back to merge proposal