=== 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
+ @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]
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.
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:
=== modified file 'lib/lp/ registry/ browser/ root.py' registry/ browser/ root.py 2009-09-21 09:30:32 +0000 registry/ browser/ root.py 2009-09-21 13:15:18 +0000 PROJECT_ ROWS = 10 PROJECT_ COLS = 2
--- lib/lp/
+++ lib/lp/
@@ -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_
+ FEATURED_
featured_ projects = [] projects_ top = None
featured_
+ @staticmethod
super( LaunchpadRootIn dexView, self).initialize() has_key( 'assume_ date'): 'assume_ date'], "%Y-%m-%d")[7] PROJECT_ ROWS * 2 + 1 PROJECT_ ROWS * self.FEATURED_ PROJECT_ COLS + 1)
self. featured_ projects = list(
getUtilit y(IPillarNameSe t).featured_ projects) [:max_projects] featured_ projects) day_of_ year() % len(self. featured_ projects)
self. featured_ projects_ top = self.featured_ projects. pop(top_ project)
+ 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."""
- if self.request.
- day_of_year = time.strptime(
- self.request[
- else:
- day_of_year = time.gmtime()[7]
- max_projects = self.FEATURED_
+ # 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_
# Select and get the top featured project (project of the day) and
# remove it from the list.
- top_project = day_of_year % len(self.
+ top_project = self._get_
def canRedirect(self): projects_ col_b(self) : PROJECT_ ROWS PROJECT_ ROWS*2 PROJECT_ ROWS * 2 projects[ index_from: index_to]
@@ -108,7 +113,7 @@
def featured_
"""The list of featured projects."""
index_from = self.FEATURED_
- index_to = self.FEATURED_
+ index_to = self.FEATURED_
return self.featured_
@property
=== modified file 'lib/lp/ registry/ stories/ launchpad- root/xx- featuredproject s.txt' registry/ stories/ launchpad- root/xx- featuredproject s.txt 2009-09-21 09:30:32 +0000 registry/ stories/ launchpad- root/xx- featuredproject s.txt 2009-09-21 11:18:24 +0000
--- lib/lp/
+++ lib/lp/
@@ -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') day_of_ year(): browser. root import LaunchpadRootIn dexView dexView. _get_day_ of_year = staticmethod( day_of_ year) launchpad. dev/') by_id(anon_ browser. contents, 'homepage- featured' ) text(featured. h2)
+ >>> def fake_get_
+ ... return 4
+ >>> from lp.registry.
+ >>> LaunchpadRootIn
+ ... fake_get_
+ >>> anon_browser.open('http://
>>> featured = find_tag_
>>> print extract_
Featured projects
We show the featured projects in our sample data, the "project of the day" is findAll( 'a'): launchpad. dev/?assume_ date=2009- 09-22') by_id(anon_ browser. contents, 'homepage- featured' ) findAll( 'a'):
-"Gentoo" and it is listed first:
-
- >>> for link in featured.
- ... 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://
- >>> featured = find_tag_
+"GNOME" and it is listed first:
+
>>> for link in featured.
... 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') launchpad. dev/') by_id(anon_ browser. contents, 'homepage- featured' ) findAll( 'a'):
+ >>> anon_browser.open('http://
>>> featured = find_tag_
>>> for link in featured.
... 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') launchpad. dev/') by_id(anon_ browser. contents, 'homepage- featured' ) findAll( 'a'):
+ >>> anon_browser.open('http://
>>> featured = find_tag_
>>> for link in featured.
... print extract_text(link)