Author: floguy
Date: Sun Oct 5 18:05:12 2008
New Revision: 1022
Added:
trunk/apps/core_apps/games/thing.py
Modified:
trunk/apps/core_apps/games/urls.py
trunk/apps/core_apps/games/views.py
trunk/projects/complete_project/templates/games/base.html
trunk/projects/complete_project/templates/games/category_list.html
trunk/projects/complete_project/templates/games/game_detail.html
trunk/projects/complete_project/templates/games/game_list.html
trunk/projects/complete_project/templates/site_base.html
Log:
Migrated the games section to use django-things instead of the custom code
that we used before.
Added: trunk/apps/core_apps/games/thing.py
==============================================================================
--- (empty file)
+++ trunk/apps/core_apps/games/thing.py Sun Oct 5 18:05:12 2008
@@ -0,0 +1,42 @@
+import things
+from arcade.models import ArcadeCategory, Game
+
+class GameThing(things.Thing):
+ game_plays = things.OrderField(
+ verbose_name_asc='Play Count',
+ verbose_name_desc='Play Count',
+ url_asc='most-played',
+ url_desc='least-played'
+ )
+ created = things.OrderField(
+ verbose_name_asc='Date Added',
+ verbose_name_desc='Date Added',
+ url_asc='newest',
+ url_desc='oldest'
+ )
+ name = things.OrderField(
+ verbose_name_asc='Alphabetical',
+ verbose_name_desc='Alphabetical',
+ )
+ template_dir = 'games'
+
+
+class GameThingGroup(things.ThingGroup):
+ template_dir = 'games'
+ template_name = 'category_list.html'
+
+def group_dicts(thing):
+ dicts = [
+ {
+ 'queryset': Game.objects.all(),
+ 'name': 'All',
+ 'url_name': 'all',
+ },
+ ]
+ for category in ArcadeCategory.objects.all():
+ dicts.append({
+ 'queryset': category.game_set.all(),
+ 'name': category.name,
+ 'url_name': category.slug,
+ })
+ return dicts
\ No newline at end of file
Modified: trunk/apps/core_apps/games/urls.py
==============================================================================
--- trunk/apps/core_apps/games/urls.py (original)
+++ trunk/apps/core_apps/games/urls.py Sun Oct 5 18:05:12 2008
@@ -1,10 +1,9 @@
+import things
from django.conf.urls.defaults import *
+from games.thing import GameThing, GameThingGroup, group_dicts
-urlpatterns = patterns('games',
- url(r'^game/(?P<slug>[a-zA-Z0-9_-]+)/$', 'views.game_detail',
name='games_detail'),
- url(r'^category/(?P<category>[a-zA-Z0-9_-]+)/$', 'views.game_list',
name='games_category'),
-
url(r'^category/(?P<category>[a-zA-Z0-9_-]+)/(?P<sort>[a-z-]+)/$',
'views.game_list',
name='games_category_list'),
- url(r'^categories/$', 'views.categories', name='games_categories'),
- url(r'^(?P<sort>[a-z-]+)/$', 'views.game_list', name='games_list'),
- url(r'^$', 'views.game_list', name='games_index'),
+thing = GameThingGroup(GameThing, group_func=group_dicts)
+
+urlpatterns = thing.urls(name_prefix='games') + patterns('games',
+ url(r'^game/(?P<slug>[a-zA-Z0-9_-]+)/$', 'views.game_detail',
name='game_detail'),
)
Modified: trunk/apps/core_apps/games/views.py
==============================================================================
--- trunk/apps/core_apps/games/views.py (original)
+++ trunk/apps/core_apps/games/views.py Sun Oct 5 18:05:12 2008
@@ -3,34 +3,6 @@
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
-def game_list(request, sort="most-played", category=None,
- template_name='games/game_list.html'):
- cats = ArcadeCategory.objects.all()
- cats = [(c, c.game_set.filter(downloaded=True).count()) for c in cats]
- games = Game.objects.filter(downloaded=True)
- if category is not None:
- category = get_object_or_404(ArcadeCategory, slug=category.lower())
- games = category.game_set.filter(downloaded=True)
- if sort == 'most-played':
- games = games.order_by('-game_plays')
- elif sort == 'alphabetical':
- games = games.order_by('name')
- elif sort == 'newest':
- games = games.order_by('-created')
- return render_to_response(template_name, {
- 'games': games,
- 'sort': sort,
- 'category': category,
- 'categories': cats,
- }, context_instance=RequestContext(request))
-
-def categories(request, template_name='games/category_list.html'):
- cats = ArcadeCategory.objects.all()
- cats = [(c, c.game_set.filter(downloaded=True).count()) for c in cats]
- return render_to_response(template_name, {
- 'categories': cats,
- }, context_instance=RequestContext(request))
-
def game_detail(request, slug='', template_name='games/game_detail.html'):
game = get_object_or_404(Game, slug=slug.lower())
if request.META.get('HTTP_REFERER', '') != request.path:
Modified: trunk/projects/complete_project/templates/games/base.html
==============================================================================
--- trunk/projects/complete_project/templates/games/base.html (original)
+++ trunk/projects/complete_project/templates/games/base.html Sun Oct 5
18:05:12 2008
@@ -7,8 +7,8 @@
{% block subnav %}
{% if user.is_authenticated %}
<ul>
- <li><a href="{% url games_categories %} ">{%
trans "Categories" %}</a></li>
- <li><a href="{% url games_index %} ">{% trans "All
Games" %}</a></li>
+ <li><a href="{% url games_group_list "" %}">{%
trans "Categories" %}</a></li>
+ <li><a href="{% url games_list "all/" %}">{% trans "All
Games" %}</a></li>
</ul>
{% else %}
Modified: trunk/projects/complete_project/templates/games/category_list.html
==============================================================================
--- trunk/projects/complete_project/templates/games/category_list.html
(original)
+++ trunk/projects/complete_project/templates/games/category_list.html Sun
Oct 5 18:05:12 2008
@@ -6,11 +6,9 @@
{% block head_title %}{% blocktrans %}Games{% endblocktrans %} : {%
blocktrans %}Categories{% endblocktrans %}{% endblock %}
{% block body %}
- {% autopaginate categories %}
<ul>
- {% for category, game_count in categories %}
- <li><a href="{% url games_category category.slug %}">{{
category.name }} ({{ game_count }} {% trans "Game" %}{{ game_count|
pluralize }})</a></li>
+ {% for group in groups %}
+ <li><a href="{{ group.url }}">{{ group.name }} ({{
group.queryset.count }} {% trans "Game" %}{{ group.queryset.count|pluralize
}})</a></li>
{% endfor %}
</ul>
- {% paginate %}
{% endblock %}
Modified: trunk/projects/complete_project/templates/games/game_detail.html
==============================================================================
--- trunk/projects/complete_project/templates/games/game_detail.html
(original)
+++ trunk/projects/complete_project/templates/games/game_detail.html Sun
Oct 5 18:05:12 2008
@@ -2,6 +2,7 @@
{% load i18n %}
{% load comments_tag %}
+{% load things_tags %}
{% block head_title %}{% blocktrans %}Game{% endblocktrans %} : {{
game.name }}{% endblock %}
@@ -10,7 +11,7 @@
<p><b>{% trans "By" %}:</b> {{ game.author }}</p>
<p>
<b>{% trans "Categories" %}:</b>
- {% for cat in game.categories.all %}<a href="{% url games_category
cat.slug %}">{{ cat.name }}</a> {% endfor %}
+ {% for cat in game.categories.all %}<a href="{% urlslash
games_list cat.slug %}">{{ cat.name }}</a> {% endfor %}
</p>
<embed src="{{ game.get_swf_url }}" width="{{ game.width }}"
height="{{ game.height }}"></embed>
<p><b>Description:</b> {{ game.description }}</p>
Modified: trunk/projects/complete_project/templates/games/game_list.html
==============================================================================
--- trunk/projects/complete_project/templates/games/game_list.html
(original)
+++ trunk/projects/complete_project/templates/games/game_list.html Sun Oct
5 18:05:12 2008
@@ -2,51 +2,22 @@
{% load i18n %}
{% load pagination_tags %}
+{% load things_tags %}
{% block head_title %}{% blocktrans %}Games{% endblocktrans %}{%
endblock %}
{% block body %}
- {% if category %}
- <h1>{% trans "Games for Category" %}: {{ category.name }}</h1>
- {% else %}
+ {% ifequal group_name "All" %}
<h1>{% trans "All Games" %}</h1>
- {% endif %}
- <p>{% trans "Sort by:" %}
- {% ifequal sort "most-played" %}
- <b>{% trans "Most Played" %}</b>
- {% else %}
- {% if category %}
- <a href="{% url games_category_list
category.slug,"most-played" %}">{% trans "Most Played" %}</a>
- {% else %}
- <a href="{% url games_list "most-played" %}">{%
trans "Most Played" %}</a>
- {% endif %}
- {% endifequal %}
- {% trans "or" %}
- {% ifequal sort "newest" %}
- <b>{% trans "Newest" %}</b>
- {% else %}
- {% if category %}
- <a href="{% url games_category_list
category.slug,"newest" %}">{% trans "Newest" %}</a>
- {% else %}
- <a href="{% url games_list "newest" %}">{%
trans "Newest" %}</a>
- {% endif %}
- {% endifequal %}
- {% trans "or" %}
- {% ifequal sort "alphabetical" %}
- <b>{% trans "Alphabetical" %}</b>
- {% else %}
- {% if category %}
- <a href="{% url games_category_list
category.slug,"alphabetical" %}">{% trans "Alphabetical" %}</a>
- {% else %}
- <a href="{% url games_list "alphabetical" %}">{%
trans "Alphabetical" %}</a>
- {% endif %}
- {% endifequal%}
- </p>
- {% autopaginate games 24 %}
- {% for game in games %}
+ {% else %}
+ <h1>{% trans "Games for Category" %}: {{ group_name }}</h1>
+ {% endifequal %}
+ {% autopaginate objects 24 %}
+ {% display_ordering %}
+ {% for game in objects %}
<div class="game_item">
- <a href="{% url games_detail game.slug %}" title="{{ game.name
}}: {{ game.description }}"><img src="{{ game.get_thumbnail_url }}" /></a>
- <span class="game_name"><b><a href="{% url games_detail
game.slug %}">{{ game.name }}</a></b></span>
+ <a href="{{ game.get_absolute_url }}" title="{{ game.name }}:
{{ game.description }}"><img src="{{ game.get_thumbnail_url }}" /></a>
+ <span class="game_name"><b><a href="{{ game.get_absolute_url
}}">{{ game.name }}</a></b></span>
<span class="game_plays">{{ game.game_plays }} Plays</span>
</div>
{% endfor %}
Modified: trunk/projects/complete_project/templates/site_base.html
==============================================================================
--- trunk/projects/complete_project/templates/site_base.html (original)
+++ trunk/projects/complete_project/templates/site_base.html Sun Oct 5
18:05:12 2008
@@ -42,7 +42,7 @@
<tr>
<td class="tab rtab_profile"><div><a href="{% url
profiles.views.profile user %}">{% trans "Profile" %}</a></div></td>
<td class="tab rtab_photos"><div><a href="{% url
photos.views.photos %}">{% trans "Photos" %}</a></div></td>
- <td class="tab rtab_games"><div><a href="{% url
games_index %}">{% trans "Games" %}</a></div></td>
+ <td class="tab rtab_games"><div><a href="{% url
games_list "all/" %}">{% trans "Games" %}</a></div></td>
<td class="tab rtab_blogs"><div><a href="{% url
blog.views.blogs %}">{% trans "Blogs" %}</a></div></td>
<td class="tab rtab_projects"><div><a href="{% url
project_thing_list "" %}">{% trans "Projects" %}</a></div></td>
<td class="tab rtab_tribes"><div><a href="{% url
tribe_thing_list "" %}">{% trans "Tribes" %}</a></div></td>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---