Skip to content

Commit

Permalink
Use waffle almost everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Socol committed Mar 17, 2011
1 parent 3d50fc3 commit e35b455
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 19 deletions.
7 changes: 4 additions & 3 deletions apps/games/templates/games/finalists.html
@@ -1,18 +1,19 @@
{% load waffle_tags %}
{% extends "games/base.html" %}

{% block content %}
<h3>
{% if settings.FINALIST_LIST %}
<a href="{% url games.view_list %}">See all the entries &raquo;</a><br/>
{% endif %}
{% if settings.ALLOW_VOTING %}
{% waffle allow_voting %}
<a href="{% url vote.ballot %}">Vote on the Community Prize &raquo;</a>
{% endif %}
{% endwaffle %}
</h3>
<h1>Finalists</h1>
<article class="tile-list">
{% for game in games %}
{% include "games/game_listing.html" %}
{% endfor %}
</article>
{% endblock %}
{% endblock %}
5 changes: 3 additions & 2 deletions apps/games/templates/games/mine.html
@@ -1,3 +1,4 @@
{% load waffle_tags %}
{% extends "games/base.html" %}

{% block content %}
Expand All @@ -9,7 +10,7 @@ <h1>My Games</h1>
<h2>You haven't submitted any games yet.</h2>
{% endfor %}
</article>
{% if settings.ALLOW_SUBMISSIONS %}
{% waffle allow_submissions %}
<h3><a href='{% url games.create %}'>Submit a new game</a></h3>
{% endif %}
{% endwaffle %}
{% endblock %}
15 changes: 8 additions & 7 deletions apps/games/views.py
Expand Up @@ -8,13 +8,14 @@
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404

from core.decorators import enabled_or_404
from waffle.decorators import waffle

from core.template import render
from games.forms import GameForm, ScreenshotForm
from games.models import Game, Screenshot


@enabled_or_404('ALLOW_SUBMISSIONS')
@waffle('allow_submissions')
@login_required
def create(request):
"""Create a new game."""
Expand All @@ -33,7 +34,7 @@ def create(request):
return render(request, 'games/create.html', {'form': form})


@enabled_or_404('ALLOW_EDITING')
@waffle('allow_editing')
@login_required
def edit(request, game_id):
"""Edit an existing game."""
Expand All @@ -60,7 +61,7 @@ def edit(request, game_id):
return render(request, 'games/edit.html', c)


@enabled_or_404('ALLOW_DELETING')
@waffle('allow_deleting')
@login_required
def delete(request, game_id):
"""Delete an existing game."""
Expand Down Expand Up @@ -92,7 +93,7 @@ def view(request, game_id, slug=None):
return render(request, 'games/view.html', {'game': game})


@enabled_or_404('ALLOW_GALLERY')
@waffle('allow_gallery')
def view_list(request):
"""View a list of games."""
# TODO: Paginate.
Expand All @@ -107,15 +108,15 @@ def view_list(request):
return render(request, 'games/list.html', {'games': games})


@enabled_or_404('ALLOW_GALLERY')
@waffle('allow_gallery')
def finalists(request):
"""View the list of finalists."""
games = (Game.objects.filter(id__in=settings.FINALIST_LIST)
.order_by('name'))
return render(request, 'games/finalists.html', {'games': games})


@enabled_or_404('ALLOW_GALLERY')
@waffle('allow_gallery')
def winners(request):
"""View the list of winners."""
return render(request, 'games/winners.html')
Expand Down
7 changes: 4 additions & 3 deletions apps/vote/views.py
Expand Up @@ -3,14 +3,15 @@
from django.shortcuts import get_object_or_404
from django.views.decorators.http import require_POST

from waffle.decorators import waffle

from core.template import render
from core.decorators import enabled_or_404
from games.models import Game
from vote.forms import VoteForm
from vote.models import Ballot, Vote


@enabled_or_404('ALLOW_VOTING')
@waffle('allow_voting')
@login_required
def ballot(request):
"""Display the list of games this user can vote on."""
Expand All @@ -19,7 +20,7 @@ def ballot(request):
return render(request, 'vote/ballot.html', {'ballot': ballot})


@enabled_or_404('ALLOW_VOTING')
@waffle('allow_voting')
@login_required
@require_POST
def vote(request):
Expand Down
8 changes: 8 additions & 0 deletions migrations/09-add-flags.sql
@@ -0,0 +1,8 @@
INSERT INTO waffle_flag
(name, everyone, percent, superusers, staff, authenticated, rollout)
VALUES
('allow_submissions', NULL, NULL, 0, 0, 0, 0),
('allow_editing', NULL, NULL, 0, 0, 0, 0),
('allow_deleting', NULL, NULL, 0, 0, 0, 0),
('allow_gallery', NULL, NULL, 0, 0, 0, 0),
('allow_voting', NULL, NULL, 0, 0, 0, 0);
13 changes: 9 additions & 4 deletions templates/base.html
@@ -1,5 +1,6 @@
{% load tags %}
{% load bundler_tags %}
{% load waffle_tags %}
<!-- You are in a twisting series of little tubes, all alike. -->
<!DOCTYPE html>
<html lang="en">
Expand All @@ -25,12 +26,16 @@
<section id="auth">
{% if user.is_authenticated %}
signed in as {{ user.username }} |
{% if settings.ALLOW_SUBMISSIONS or user.game_set.all %}
{% waffle allow_submissions %}
<a href="{% url games.mine %}">your games</a>|
{% endif %}
{% if settings.ALLOW_VOTING %}
{% else %}
{% if user.game_set.exists %}
<a href="{% url games.mine %}">your games</a>|
{% endif %}
{% endwaffle %}
{% waffle allow_voting %}
<a href="{% url vote.ballot %}">your votes</a>|
{% endif %}
{% endwaffle %}
<a href="{% url auth_logout %}?next=/">logout</a>
{% else %}
<a class="login" href="{% url auth_login %}">login</a>
Expand Down

0 comments on commit e35b455

Please sign in to comment.