Daniel Holbach has proposed merging lp:~dholbach/loco-directory/geo-grouping 
into lp:loco-directory.

Requested reviews:
  loco-directory-dev (loco-directory-dev)
Related bugs:
  #596823 list teams by continent and country
  https://bugs.launchpad.net/bugs/596823
  #596826 list venues by continent and country
  https://bugs.launchpad.net/bugs/596826

-- 
https://code.launchpad.net/~dholbach/loco-directory/geo-grouping/+merge/31288
Your team loco-directory-dev is requested to review the proposed merge of 
lp:~dholbach/loco-directory/geo-grouping into lp:loco-directory.
=== modified file 'loco_directory/common/context_processors.py'
--- loco_directory/common/context_processors.py	2010-06-17 19:11:30 +0000
+++ loco_directory/common/context_processors.py	2010-07-29 13:56:44 +0000
@@ -31,5 +31,4 @@
 
 def url_base(request):
     url = request.get_full_path().split('/')
-    return {'url_base': url[1]}
-    
\ No newline at end of file
+    return {'url_base': url[1]} 

=== modified file 'loco_directory/common/utils.py'
--- loco_directory/common/utils.py	2010-06-17 01:38:28 +0000
+++ loco_directory/common/utils.py	2010-07-29 13:56:44 +0000
@@ -1,6 +1,14 @@
 import email
 import os
 
+def flat_list(some_list):
+    """
+    >>> reduce(lambda a,b: a.extend(b) or a, [[2,3],[6],[66,34]])
+    [2, 3, 6, 66, 34]
+    """
+    return reduce(lambda a,b: a.extend(b) or a, some_list)
+    
+
 def redirect(to, *args, **kwargs):
     from distutils.version import LooseVersion as V
     import django

=== modified file 'loco_directory/events/forms.py'
--- loco_directory/events/forms.py	2010-06-19 21:35:39 +0000
+++ loco_directory/events/forms.py	2010-07-29 13:56:44 +0000
@@ -6,8 +6,6 @@
 from models import BaseEvent, GlobalEvent, TeamEvent, Attendee, TeamEventComment
 from venues.models import Venue
 
-import re
-
 def validate_tag(tag):
     if tag.startswith('#'):
         tag = tag[1:]

=== modified file 'loco_directory/teams/management/commands/init-ld.py'
--- loco_directory/teams/management/commands/init-ld.py	2010-07-01 06:27:09 +0000
+++ loco_directory/teams/management/commands/init-ld.py	2010-07-29 13:56:44 +0000
@@ -3,7 +3,6 @@
 from django.core.management.base import NoArgsCommand
 from django.contrib.auth.models import Group
 
-from teams import models
 import settings
 
 import subprocess

=== modified file 'loco_directory/teams/models.py'
--- loco_directory/teams/models.py	2010-07-15 14:28:03 +0000
+++ loco_directory/teams/models.py	2010-07-29 13:56:44 +0000
@@ -1,6 +1,8 @@
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
 
+from common.utils import flat_list
+
 class Language(models.Model):
     class Meta:
         ordering = ('name',)
@@ -24,6 +26,18 @@
     def __unicode__(self):
         return u'%s' % (self.name)
 
+    @property
+    def related_countries(self):
+        return self.country_set.all()
+
+    @property
+    def related_venues(self):
+        return flat_list([a.related_venues for a in self.related_countries])
+    
+    @property
+    def related_teams(self):
+        return flat_list([a.related_teams for a in self.related_countries])
+
 class Country(models.Model):
     name = models.TextField(_("Name"), max_length=100)
     continents = models.ManyToManyField(Continent)
@@ -31,6 +45,25 @@
     def __unicode__(self):
         return u'%s' % (self.name)
 
+    @property
+    def related_teams(self):
+        return self.team_set.all()
+    
+    @property
+    def related_venues(self):
+        return self.venue_set.all()
+
+def countries_without_continent():
+    return Country.objects.filter(continents__isnull=True)
+
+def countries_without_continent_have_venues():
+    list_of_venues = [list(a.related_venues) for a in countries_without_continent()]
+    return len(flat_list(list_of_venues))>0
+
+def countries_without_continent_have_teams():
+    list_of_teams = [list(a.related_teams) for a in countries_without_continent()]
+    return len(flat_list(list_of_teams))>0
+
 class Team(models.Model):
     lp_name = models.SlugField(_("Launchpad Team ID"), max_length=40, null=True)
     name = models.CharField(_("Team Name"), max_length=80, null=True)
@@ -69,4 +102,5 @@
     def get_absolute_url(self):
         return ('team-detail', [str(self.lp_name)])
 
-    
+def teams_without_country():
+    return Team.objects.filter(countries__isnull=True)

=== modified file 'loco_directory/teams/views.py'
--- loco_directory/teams/views.py	2010-07-15 13:37:00 +0000
+++ loco_directory/teams/views.py	2010-07-29 13:56:44 +0000
@@ -1,7 +1,6 @@
 # -*- coding: utf-8 -*-
 
 from django.template import RequestContext
-from django.utils.translation import ugettext_lazy as _
 from django.utils.translation import ugettext
 from django.core import serializers
 
@@ -16,7 +15,7 @@
 from common.utils import redirect
 from common import launchpad
 
-from models import Team
+from teams.models import Continent, Team, countries_without_continent, countries_without_continent_have_teams, teams_without_country
 
 import forms
 
@@ -54,6 +53,10 @@
     context = {
         'team_list': team_list,
         'form': form,
+        'continents': Continent.objects.all().order_by('name'),
+        'countries_without_continent': countries_without_continent().order_by('name'),
+        'countries_without_continent_have_teams': countries_without_continent_have_teams(),
+        'teams_without_country': teams_without_country().order_by('name'),
     }
     return render_to_response('teams/team_list.html', context,
                   RequestContext(request))

=== modified file 'loco_directory/templates/teams/team_list.html'
--- loco_directory/templates/teams/team_list.html	2010-07-15 07:56:44 +0000
+++ loco_directory/templates/teams/team_list.html	2010-07-29 13:56:44 +0000
@@ -20,13 +20,49 @@
 {% block content %}
 <article id="main-content" class="main-content">
 {% if team_list %}
-<ul>
-{% for team in team_list %}
-<li title="{% if team.approved %}{% blocktrans with team.name as teamname %}{{ teamname }} approved{% endblocktrans %}{% else %}{% blocktrans with team.name as teamname %}{{ teamname }} not approved{% endblocktrans %}{% endif %}" class="{% if team.approved %}approved{% else %}unapproved{% endif %} {% cycle 'col_left' 'col_right' %}"><a href="{{ team.get_absolute_url }}">{{ team.name }}</a></li>
-{% endfor %}
-</ul>
-<br class="clear" />
+  {% for continent in continents %}
+    {% if continent.related_teams %}
+      <h2>{{continent.name}}</h2>
+      {% for country in continent.related_countries %}
+        {% if country.related_teams %}
+          <h3>{{country.name}}</h3>
+          <ul>
+          {% for team in country.related_teams %}
+            <li title="{% if team.approved %}{% blocktrans with team.name as teamname %}{{ teamname }} approved{% endblocktrans %}{% else %}{% blocktrans with team.name as teamname %}{{ teamname }} not approved{% endblocktrans %}{% endif %}" class="{% if team.approved %}approved{% else %}unapproved{% endif %} {% cycle 'col_left' 'col_right' %}"><a href="{{ team.get_absolute_url }}">{{ team.name }}</a></li>
+          {% endfor %}
+          </ul>
+          <br class="clear" />
+        {% endif %}
+      {% endfor %}  
+    {% endif %}
+  {% endfor %}
+
+  {% if countries_without_continent_have_teams %}
+    <h2>{% trans "Countries without continent" %}</h2>
+    {% for country in countries_without_continent %}
+      {% if country.related_teams %}
+        <h3>{{country.name}}</h3>
+        <ul>
+        {% for team in country.related_teams %}
+          <li title="{% if team.approved %}{% blocktrans with team.name as teamname %}{{ teamname }} approved{% endblocktrans %}{% else %}{% blocktrans with team.name as teamname %}{{ teamname }} not approved{% endblocktrans %}{% endif %}" class="{% if team.approved %}approved{% else %}unapproved{% endif %} {% cycle 'col_left' 'col_right' %}"><a href="{{ team.get_absolute_url }}">{{ team.name }}</a></li>
+        {% endfor %}
+        </ul>
+        <br class="clear" />
+      {% endif %}    
+    {% endfor %}
+  {% endif %}
+
+  {% if teams_without_country %}
+    <h2>{% trans "Teams without country" %}</h2>
+    <ul>
+    {% for team in teams_without_country %}
+      <li title="{% if team.approved %}{% blocktrans with team.name as teamname %}{{ teamname }} approved{% endblocktrans %}{% else %}{% blocktrans with team.name as teamname %}{{ teamname }} not approved{% endblocktrans %}{% endif %}" class="{% if team.approved %}approved{% else %}unapproved{% endif %} {% cycle 'col_left' 'col_right' %}"><a href="{{ team.get_absolute_url }}">{{ team.name }}</a></li>
+    {% endfor %}
+    </ul>
+    <br class="clear" />
+  {% endif %}
+
+{% endif %}
 </article>
-{% endif %}
 
 {% endblock %}

=== modified file 'loco_directory/templates/venues/venue_list.html'
--- loco_directory/templates/venues/venue_list.html	2010-06-24 19:18:57 +0000
+++ loco_directory/templates/venues/venue_list.html	2010-07-29 13:56:44 +0000
@@ -22,18 +22,50 @@
 <h2>{% trans "Ubuntu LoCo Venues" %}</h2>
 
 {% if venue_list %}
-<p>{% trans "Select a Venue below to see more information about it:" %}</p>
-
-{% regroup venue_list by country as venue_country_list %}    
-{% for country in venue_country_list %}
-    <h3>{{ country.grouper }}</h3>
+  <p>{% trans "Select a Venue below to see more information about it:" %}</p>
+
+  {% for continent in continents %}
+    {% if continent.related_venues %}
+      <h2>{{continent.name}}</h2>
+      {% for country in continent.related_countries %}
+        {% if country.related_venues %}
+          <h3>{{country.name}}</h3>
+          <ul>
+          {% for venue in country.related_venues %}
+            <li class="{% if forloop.counter|divisibleby:2 %}col_right{% else %}col_left{% endif %}"><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{{ venue.name }}{% if venue.city %}, {{ venue.city }}{% endif %}</a></li>
+          {% endfor %}
+          </ul>
+          <br style="clear:left;">
+        {% endif %}
+      {% endfor %}
+    {% endif %}
+  {% endfor %}
+
+  {% if countries_without_continent_have_venues %}
+    <h2>{% trans "Countries without Continent" %}</h3>
+    {% for country in countries_without_continent %}
+      {% if country.related_venues %}
+        <h3>{{country.name}}</h3>
+        <ul>
+        {% for venue in country.related_venues %}
+          <li class="{% if forloop.counter|divisibleby:2 %}col_right{% else %}col_left{% endif %}"><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{{ venue.name }}{% if venue.city %}, {{ venue.city }}{% endif %}</a></li>
+        {% endfor %}
+        </ul>
+        <br style="clear:left;">
+      {% endif %}
+    {% endfor %}
+  {% endif %}
+
+  {% if venues_without_country %}
+    <h2>{% trans "Venues without Country" %}</h2>
     <ul>
-        {% for venue in country.list %}
-        <li class="{% if forloop.counter|divisibleby:2 %}col_right{% else %}col_left{% endif %}"><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{{ venue.name }}{% if venue.city %}, {{ venue.city }}{% endif %}</a></li>
-        {% endfor %}    
+    {% for venue in venues_without_country %}
+      <li class="{% if forloop.counter|divisibleby:2 %}col_right{% else %}col_left{% endif %}"><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{{ venue.name }}{% if venue.city %}, {{ venue.city }}{% endif %}</a></li>
+    {% endfor %}
     </ul>
     <br style="clear:left;">
-{% endfor %}
+  {% endif %}
+
 
 {% else %}
 <p>{% trans "There are currently no LoCo Venues :(" %}</p>

=== modified file 'loco_directory/venues/models.py'
--- loco_directory/venues/models.py	2010-06-09 01:36:18 +0000
+++ loco_directory/venues/models.py	2010-07-29 13:56:44 +0000
@@ -40,3 +40,5 @@
         """ get the absolute url for the venue """
         return ('venue-detail', [self.id])
 
+def venues_without_country():
+    return Venue.objects.filter(country__isnull=True)

=== modified file 'loco_directory/venues/views.py'
--- loco_directory/venues/views.py	2010-06-19 20:20:12 +0000
+++ loco_directory/venues/views.py	2010-07-29 13:56:44 +0000
@@ -7,7 +7,8 @@
 from django.utils.translation import ugettext as _
 from django.db.models import Q
 
-from models import Venue
+from teams.models import Continent, countries_without_continent, countries_without_continent_have_venues
+from models import Venue, venues_without_country
 from forms import VenueForm, VenueSearchForm
 
 
@@ -27,6 +28,11 @@
     context = {
         'form': form,
         'venue_list': venue_list,
+        'continents': Continent.objects.all().order_by('name'),
+        'countries_without_continent': countries_without_continent().order_by('name'),
+        'countries_without_continent_have_venues': countries_without_continent_have_venues(),
+        'venues_without_country': venues_without_country().order_by('name'),
+
     }
     return render_to_response('venues/venue_list.html', context,
                   RequestContext(request))

_______________________________________________
Mailing list: https://launchpad.net/~loco-directory-dev
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~loco-directory-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to