Ronnie has proposed merging
lp:~ronnie.vd.c/loco-team-portal/reduced_venue_page_queries into
lp:loco-team-portal.
Requested reviews:
LoCo Team Portal Developers (loco-directory-dev)
For more details, see:
https://code.launchpad.net/~ronnie.vd.c/loco-team-portal/reduced_venue_page_queries/+merge/82058
Reduced the amount of queries from 800+ to 10 on the event venue list page
Viewing the amount of queries can be done with this example:
http://stackoverflow.com/questions/1074212/show-the-sql-django-is-running/3930290#3930290
--
https://code.launchpad.net/~ronnie.vd.c/loco-team-portal/reduced_venue_page_queries/+merge/82058
Your team LoCo Team Portal Developers is requested to review the proposed merge
of lp:~ronnie.vd.c/loco-team-portal/reduced_venue_page_queries into
lp:loco-team-portal.
=== modified file 'loco_directory/templates/venues/venue_list.html'
--- loco_directory/templates/venues/venue_list.html 2011-10-05 00:50:53 +0000
+++ loco_directory/templates/venues/venue_list.html 2011-11-12 23:22:24 +0000
@@ -12,45 +12,42 @@
<h2>{% trans "Ubuntu LoCo Event Venues" %}</h2>
- {% if venue_list %}
+ {% if continent_list or venues_with_country or venues_without_country %}
<p>{% trans "Select a Venue below to see more information about it:" %}</p>
-
- {% for continent in continents %}
- {% if continent.related_venues %}
- <div class="venue-list">
- <h3>{{continent.name}}</h3>
- <ul>
- {% for country in continent.related_countries %}
- {% if country.related_venues %}
- <li><h3>{{country.name}}</h3>
- {% for venue in country.related_venues %}
- <p><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{{ venue.name }}{% if venue.city %}, {{ venue.city }}{% endif %}{% if venue.spr %}, {{ venue.spr }}{% endif %}</a></p>
- {% endfor %}
- </li>
- {% endif %}
- {% endfor %}
- </ul>
- </div>
- {% endif %}
- {% endfor %}
-
- {% if countries_without_continent_have_venues %}
- <div class="venue-list">
- <h3>{% trans "Countries without Continent" %}</h3>
- <ul>
- {% for country in countries_without_continent %}
- {% if country.related_venues %}
- <li><h3>{{country.name}}</h3>
- {% for venue in country.related_venues %}
- <p><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{{ venue.name }}{% if venue.city %}, {{ venue.city }}{% endif %}{% if venue.spr %}, {{ venue.spr }}{% endif %}</a></p>
- {% endfor %}
- </li>
- {% endif %}
- {% endfor %}
- </ul>
- </div>
- {% endif %}
-
+ {% if continent_list %}
+ {% for continent in continent_list %}
+ <div class="venue-list">
+ <h3>{{ continent.name }}</h3>
+ <ul>
+ {% regroup continent.venue_list by country as country_list %}
+ {% for country in country_list %}
+ <li><h3>{{ country.grouper }}</h3>
+ {% for venue in country.list %}
+ <p><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{{ venue.name }}{% if venue.city %}, {{ venue.city }}{% endif %}{% if venue.spr %}, {{ venue.spr }}{% endif %}</a></p>
+ {% endfor %}
+ </li>
+ {% endfor %}
+ </ul>
+ </div>
+ {% endfor %}
+ {% endif %}
+
+ {% if venues_with_country %}
+ <div class="venue-list">
+ <h3>{% trans "Countries without Continent" %}</h3>
+ <ul>
+ {% regroup venues_with_country by country as country_list %}
+ {% for country in country_list %}
+ <li><h3>{{ country.grouper }}</h3>
+ {% for venue in country.list %}
+ <p><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{{ venue.name }}{% if venue.city %}, {{ venue.city }}{% endif %}{% if venue.spr %}, {{ venue.spr }}{% endif %}</a></p>
+ {% endfor %}
+ </li>
+ {% endfor %}
+ </ul>
+ </div>
+ {% endif %}
+
{% if venues_without_country %}
<div class="venue-list">
<h3>{% trans "Venues without Country" %}</h3>
@@ -63,11 +60,8 @@
</ul>
</div>
{% endif %}
-
-
{% else %}
<p>{% trans "There are currently no LoCo Venues :(" %}</p>
{% endif %}
-
</article>
{% endblock %}
=== modified file 'loco_directory/venues/views.py'
--- loco_directory/venues/views.py 2011-03-18 13:37:13 +0000
+++ loco_directory/venues/views.py 2011-11-12 23:22:24 +0000
@@ -18,14 +18,20 @@
"""
a list with all venues
"""
- venue_list = Venue.objects.all().order_by('country')
+ venue_base_query = Venue.objects.select_related('country').order_by('country')
+
+ continent_list = []
+ for continent in Continent.objects.filter(country__venue__isnull=False).distinct():
+ continent.venue_list = venue_base_query.filter(country__continents=continent)
+ continent_list.append(continent)
+
+ venues_with_country = venue_base_query.filter(country__isnull=False, country__continents__isnull=True)
+ venues__without_country = venue_base_query.filter(country__isnull=True)
context = {
- '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'),
+ 'continent_list': continent_list,
+ 'venues_with_country': venues_with_country,
+ 'venues_without_country': venues__without_country,
'colcycle' : simple_iterator('col_left', 'col_right'),
}
_______________________________________________
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