changeset 197:2baadae33f2e

Got autocomplete working for the member search. Updated django and ran into a bug where url tags with comma separated kwargs starting consuming tons of CPU throughput. The work-around is to cut over to using spaces between arguments. This is now allowed to be consistent with other tags. Did some query optimization for the news app.
author Brian Neal <bgneal@gmail.com>
date Sat, 10 Apr 2010 04:32:24 +0000
parents 893b6d462cf9
children 7e3ed3eb9b99
files gpp/bio/forms.py gpp/news/views.py gpp/templates/bio/members.html gpp/templates/downloads/download_list.html gpp/templates/downloads/index.html gpp/templates/news/archive_index.html gpp/templates/news/category_index.html gpp/templates/news/index.html gpp/templates/news/story.html gpp/templates/news/story_summary.html gpp/templates/news/tag_index.html gpp/templates/weblinks/index.html gpp/templates/weblinks/view_links.html
diffstat 13 files changed, 33 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/bio/forms.py	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/bio/forms.py	Sat Apr 10 04:32:24 2010 +0000
@@ -120,6 +120,12 @@
     """
     username = forms.CharField(max_length=30, widget=AutoCompleteUserInput())
 
+    class Media:
+        css = {
+          'all': settings.GPP_THIRD_PARTY_CSS['jquery-ui']
+        }
+        js = settings.GPP_THIRD_PARTY_JS['jquery-ui']
+
     def clean_username(self):
       username = self.cleaned_data['username']
       try:
--- a/gpp/news/views.py	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/news/views.py	Sat Apr 10 04:32:24 2010 +0000
@@ -40,7 +40,7 @@
 #######################################################################
 
 def index(request, page=1):
-   stories = Story.objects.all()
+   stories = Story.objects.all().select_related()
    paginator = create_paginator(stories)
    try:
       the_page = paginator.page(int(page))
@@ -87,10 +87,10 @@
 #######################################################################
 
 def category_index(request):
-   categories = Category.objects.all()
+   categories = Category.objects.all().select_related()
    cat_list = []
    for cat in categories:
-      cat_list.append((cat, cat.story_set.all()[:10]))
+      cat_list.append((cat, cat.story_set.defer('tags')[:10]))
 
    return render_to_response('news/category_index.html', {
       'cat_list': cat_list, 
@@ -215,7 +215,7 @@
 
 def tag(request, tag_name, page=1):
    tag = get_object_or_404(Tag, name=tag_name)
-   stories = TaggedItem.objects.get_by_model(Story, tag)
+   stories = TaggedItem.objects.get_by_model(Story.objects.all().select_related(), tag)
    paginator = create_paginator(stories)
    try:
       the_page = paginator.page(int(page))
@@ -227,7 +227,7 @@
       'page': the_page,
       'search_form': SearchNewsForm(),
       }, 
-      context_instance = RequestContext(request))
+      context_instance=RequestContext(request))
 
 #######################################################################
 
--- a/gpp/templates/bio/members.html	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/templates/bio/members.html	Sat Apr 10 04:32:24 2010 +0000
@@ -11,9 +11,9 @@
 particular user? Try our <a href="{% url bio-member_search %}">member search</a>.</p>
 {% if page.object_list %}
 <ul class="tab-nav">
-   <li><a href="{% url bio-members_full type="user",page="1" %}"
+   <li><a href="{% url bio-members_full type='user' page=1 %}"
       {% ifequal type "user" %}class="active" {% endifequal %}>User</a></li>
-   <li><a href="{% url bio-members_full type="date",page="1" %}"
+   <li><a href="{% url bio-members_full type='date' page=1 %}"
       {% ifequal type "date" %}class="active" {% endifequal %}>Date</a></li>
 </ul>
 
--- a/gpp/templates/downloads/download_list.html	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/templates/downloads/download_list.html	Sat Apr 10 04:32:24 2010 +0000
@@ -16,13 +16,13 @@
 
 {% if page.object_list %}
 <ul class="tab-nav">
-   <li><a href="{% url downloads-category category=category.id,sort="title",page="1" %}"
+   <li><a href="{% url downloads-category category=category.id sort="title" page="1" %}"
       {% ifequal s "title" %}class="active" {% endifequal %}>Title</a></li>
-   <li><a href="{% url downloads-category category=category.id,sort="date",page="1" %}"
+   <li><a href="{% url downloads-category category=category.id sort="date" page="1" %}"
       {% ifequal s "date" %}class="active"{% endifequal %}>Date</a></li>
-   <li><a href="{% url downloads-category category=category.id,sort="rating",page="1" %}"
+   <li><a href="{% url downloads-category category=category.id sort="rating" page="1" %}"
       {% ifequal s "rating" %}class="active"{% endifequal %}>Rating</a></li>
-   <li><a href="{% url downloads-category category=category.id,sort="hits",page="1" %}"
+   <li><a href="{% url downloads-category category=category.id sort="hits" page="1" %}"
       {% ifequal s "hits" %}class="active"{% endifequal %}>Hits</a></li>
 </ul>
 
--- a/gpp/templates/downloads/index.html	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/templates/downloads/index.html	Sat Apr 10 04:32:24 2010 +0000
@@ -13,7 +13,7 @@
 <dl>
 {% for category in categories %}
 <dt>
-<a href="{% url downloads-category category=category.pk,sort="title",page=1 %}">{{ category.title }}</a>
+<a href="{% url downloads-category category=category.pk sort="title" page=1 %}">{{ category.title }}</a>
 ({{ category.count }})
 </dt>
 <dd><p>{{ category.description }}</p></dd>
--- a/gpp/templates/news/archive_index.html	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/templates/news/archive_index.html	Sat Apr 10 04:32:24 2010 +0000
@@ -10,7 +10,7 @@
 {% if dates %}
 <ul>
 {% for date in dates %}
-   <li><a href="{% url news-archive_page year=date.year,month=date.month,page=1 %}">
+   <li><a href="{% url news-archive_page year=date.year month=date.month page=1 %}">
       {{ date|date:"F, Y" }}</a></li>
 {% endfor %}
 </ul>
--- a/gpp/templates/news/category_index.html	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/templates/news/category_index.html	Sat Apr 10 04:32:24 2010 +0000
@@ -12,7 +12,7 @@
 
 {% for category, story_set in cat_list %}
    <h3>{{ category.title }}</h3>
-   <p><a href="{% url news.views.category category=category.id,page=1 %}">
+   <p><a href="{% url news.views.category category=category.id page=1 %}">
       <img src="{{ category.icon.url }}" alt="{{ category.title }}" title="{{ category.title }}" />
       </a>
    </p>
--- a/gpp/templates/news/index.html	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/templates/news/index.html	Sat Apr 10 04:32:24 2010 +0000
@@ -1,5 +1,4 @@
 {% extends 'news/base.html' %}
-{% load tagging_tags %}
 {% block title %}News: {{ title }}{% endblock %}
 {% block news_css %}
 <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/pagination.css" />
@@ -15,7 +14,6 @@
 
 {% if page.object_list %}
 {% for story in page.object_list %}
-   {% tags_for_object story as story_tags %}
    {% include 'news/story_summary.html' %}
 {% endfor %}
 <div style="clear:right;"></div>
--- a/gpp/templates/news/story.html	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/templates/news/story.html	Sat Apr 10 04:32:24 2010 +0000
@@ -19,7 +19,7 @@
 </div>
 <hr />
 <div class="news-content">
-   <a href="{% url news.views.category category=story.category.id,page=1 %}">
+   <a href="{% url news.views.category category=story.category.id page=1 %}">
    <img src="{{ story.category.icon.url }}" alt="{{ story.category.title }}" title="{{ story.category.title }}" 
       class="news-icon" /></a>
    {{ story.short_text|safe }}
@@ -29,7 +29,7 @@
    {% if story_tags %}
    <hr />
    <p>
-   Category: <a href="{% url news.views.category category=story.category.id,page=1 %}">{{ story.category.title }}</a>
+   Category: <a href="{% url news.views.category category=story.category.id page=1 %}">{{ story.category.title }}</a>
    <a href="{{ story.get_absolute_url }}"><img src="{{ MEDIA_URL }}icons/link.png"
       alt="Story Permalink" title="Story Permalink" /></a>
 {% if user.is_authenticated %}
@@ -41,7 +41,7 @@
       <img src="{{ MEDIA_URL }}icons/tag_blue.png" alt="Tags" title="Tags" /> Tags:
       <ul>
          {% for tag in story_tags %}
-            <li><a href="{% url news-tag_page tag_name=tag.name,page=1 %}">{{ tag.name }}</a></li>
+            <li><a href="{% url news-tag_page tag_name=tag.name page=1 %}">{{ tag.name }}</a></li>
          {% endfor %}
       </ul>
    </div>
--- a/gpp/templates/news/story_summary.html	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/templates/news/story_summary.html	Sat Apr 10 04:32:24 2010 +0000
@@ -9,7 +9,7 @@
 <div class="news-details">
    Submitted by {{ story.submitter.username }} on {{ story.date_published|date:"F d, Y" }}.
 </div>
-<a href="{% url news.views.category category=story.category.id,page=1 %}">
+<a href="{% url news.views.category category=story.category.id page=1 %}">
 <img src="{{ story.category.icon.url }}" alt="{{ story.category.title }}" title="{{ story.category.title }}" 
    class="news-icon" /></a>
 <div class="news-content">
@@ -23,7 +23,7 @@
 {% endif %}
 <hr />
 <p>
-Category: <a href="{% url news.views.category category=story.category.id,page=1 %}">{{ story.category.title }}</a>
+Category: <a href="{% url news.views.category category=story.category.id page=1 %}">{{ story.category.title }}</a>
 <img src="{{ MEDIA_URL }}icons/comments.png" alt="Comments" title="Comments" />
 <a href="{{ story.get_absolute_url }}">{{ comment_count }} comment{{ comment_count|pluralize }}</a>
 <a href="{{ story.get_absolute_url }}"><img src="{{ MEDIA_URL }}icons/link.png" alt="Permalink" title="Permalink" /></a>
@@ -32,12 +32,12 @@
    alt="Send this story to a friend" title="Send this story to a friend" /></a>
 {% endif %}
 </p>
-{% if story_tags %}
+{% if story.tags %}
 <div class="news-tags">
    <img src="{{ MEDIA_URL }}icons/tag_blue.png" alt="Tags" title="Tags" /> Tags:
    <ul>
-      {% for tag in story_tags %}
-         <li><a href="{% url news-tag_page tag_name=tag.name,page=1 %}">{{ tag.name }}</a></li>
+      {% for tag in story.tags %}
+         <li><a href="{% url news-tag_page tag_name=tag page=1 %}">{{ tag }}</a></li>
       {% endfor %}
    </ul>
 </div>
--- a/gpp/templates/news/tag_index.html	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/templates/news/tag_index.html	Sat Apr 10 04:32:24 2010 +0000
@@ -12,7 +12,7 @@
    <div class="news-tag-cloud">
    <ul>
    {% for tag in tags %}
-      <li><a href="{% url news-tag_page tag_name=tag.name,page=1 %}">
+      <li><a href="{% url news-tag_page tag_name=tag.name page=1 %}">
          <font size="{{ tag.font_size }}">{{ tag.name }}</font></a></li>
    {% endfor %}
    </ul>
--- a/gpp/templates/weblinks/index.html	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/templates/weblinks/index.html	Sat Apr 10 04:32:24 2010 +0000
@@ -6,7 +6,7 @@
       <p>We have {{ total_links }} links in {{ categories.count }} categories.</p>
       <dl>
       {% for category in categories %}
-      <dt><a href="{% url weblinks-view_links category=category.id,sort="title",page=1 %}">{{ category.title }}</a>
+      <dt><a href="{% url weblinks-view_links category=category.id sort="title" page=1 %}">{{ category.title }}</a>
        ({{ category.count }})</dt>
          <dd><p>{{ category.description }}</p></dd>
       {% endfor %}
--- a/gpp/templates/weblinks/view_links.html	Wed Apr 07 01:59:09 2010 +0000
+++ b/gpp/templates/weblinks/view_links.html	Sat Apr 10 04:32:24 2010 +0000
@@ -12,11 +12,11 @@
 
 {% if page.object_list %}
 <ul class="tab-nav">
-   <li><a href="{% url weblinks-view_links category=category.id,sort="title",page="1" %}"
+   <li><a href="{% url weblinks-view_links category=category.id sort="title" page="1" %}"
       {% ifequal s "title" %}class="active" {% endifequal %}>Title</a></li>
-   <li><a href="{% url weblinks-view_links category=category.id,sort="date",page="1" %}"
+   <li><a href="{% url weblinks-view_links category=category.id sort="date" page="1" %}"
       {% ifequal s "date" %}class="active"{% endifequal %}>Date</a></li>
-   <li><a href="{% url weblinks-view_links category=category.id,sort="hits",page="1" %}"
+   <li><a href="{% url weblinks-view_links category=category.id sort="hits" page="1" %}"
       {% ifequal s "hits" %}class="active"{% endifequal %}>Hits</a></li>
 </ul>