Comment 5 for bug 477453

Revision history for this message
Curtis Hovey (sinzui) wrote : Re: deletion of all featured projects causes broken main page

Hi Loki

While looking into this I got so angry at what I found that I am going to fix this now. This is what I was typing before I hit the point where I decided to JFDI. I'll fix your bug and my own dislike of this implementation.

Wow. This code really sucks.
    * Why does the template use ids for the layout? Ids are forbidden in the global stylesheet.
    * Why are non reusable styles in the global stylesheet?
    * The styles look like a private implementation of .two-column-list
    * The view's implementation imposes a design that does not exist (it assumes a table layout).
    * The template should use view/features_projects and iterate to create an <li>

The correct fix is to
    * inline the #homepage and .homepage styles in the template's head_epilogue slot
    * Change the template to use the approved two-column-list
    * Update the template to use view/featured projects
    * Delete the crack properties (featured_projects_col_a, featured_projects_col_b)

The top_project in your case is conditional so we need to check the length of projects before trying to pop it. The template needs a simple condition to not render the top project.

=== modified file 'lib/canonical/launchpad/templates/root-index.pt'
--- lib/canonical/launchpad/templates/root-index.pt 2009-10-30 17:37:45 +0000
+++ lib/canonical/launchpad/templates/root-index.pt 2009-11-13 15:20:05 +0000
@@ -163,7 +163,8 @@
             <div id="homepage-featured" class="homepage-portlet">
               <h2>Featured projects</h2>
               <div id="homepage-featured-top"
- tal:define="topproject view/featured_projects_top">
+ tal:define="topproject view/featured_projects_top"
+ tal:condition="topproject">
                 <a tal:attributes="href topproject/fmt:url">
                   <img tal:replace="structure topproject/image:logo" />
                   <div id="homepage-featured-top-title">

=== modified file 'lib/lp/registry/browser/root.py'
--- lib/lp/registry/browser/root.py 2009-09-22 20:47:30 +0000
+++ lib/lp/registry/browser/root.py 2009-11-13 15:18:17 +0000
@@ -82,8 +82,11 @@
             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 = self._get_day_of_year() % len(self.featured_projects)
- self.featured_projects_top = self.featured_projects.pop(top_project)
+ project_count = len(self.featured_projects)
+ if project_count > 0:
+ top_project = self._get_day_of_year() % project_count
+ self.featured_projects_top = self.featured_projects.pop(
+ top_project)

     def canRedirect(self):
         """Return True if the beta server is available to the user."""