Skip to content
This repository has been archived by the owner on Aug 27, 2019. It is now read-only.

Making the student flow work, and adding in an application for the game. #16

Merged
merged 12 commits into from
Jul 21, 2015
6 changes: 6 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[report]
omit =
bin/*
develop-eggs/*
eggs/*
*/site-packages/*
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: python

python:
- "3.4"

install:
- travis_retry pip install -r requirements.txt
- travis_retry pip install -r requirements-dev.txt

script:
- cd ekip
- coverage run --source=everykid manage.py test --settings=config.settings.test

after_success:
- coveralls
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
EKIP API
=======

[![Coverage Status](https://coveralls.io/repos/18F/ekip-api/badge.svg?branch=master&service=github)](https://coveralls.io/github/18F/ekip-api?branch=master)

# ticketing-system
A ticketing system.

Expand Down
1 change: 1 addition & 0 deletions ekip/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'nationalparks',
'redemption',
'everykid',
'game'
)

THIRD_PARTY_APPS = (
Expand Down
1 change: 1 addition & 0 deletions ekip/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
url(r'^accounts/login/$', auth_views.login),
url(r'^accounts/logout/$', auth_views.logout),
url(r'^redeem/', include('redemption.urls')),
url(r'^game/', include('game.urls')),
)
25 changes: 25 additions & 0 deletions ekip/everykid/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.utils.translation import ugettext_lazy as _

from localflavor.us.us_states import US_STATES
from localflavor.us.forms import USZipCodeField

from .models import Educator

Expand Down Expand Up @@ -34,3 +35,27 @@ class Meta:
'name', 'work_email', 'organization_name', 'address_line_1',
'address_line_2', 'city', 'state', 'zipcode', 'num_students',
'org_or_school']


class FourthGraderForm(forms.Form):
"""
A very simple, one field form that is used to confirm whether the
student is a 4th grader.
"""

STUDENT_CHOICES = (
('Y', _('Yes, I am in the 4th grader (or 10 years old)')),
('N', _('No')))

in_the_fourth_grade = forms.ChoiceField(
label=_("Are you a 4th grader?"),
widget=forms.RadioSelect,
choices=STUDENT_CHOICES)


class ZipCodeForm(forms.Form):
"""
This is the form that allows us to ask 4th graders for their ZIP code.
"""

zip_code = USZipCodeField(label=_("What is your ZIP code?"))
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h3>To all U.S. National Parks, Forests, National Lands and Waters</h3>

<div class="voucher">
<div class="voucher-barcode" data-endpoint="">
<span class="voucher-barcode-id">1111111</span>
<span class="voucher-barcode-id">{{locator}}</span>
<img alt="barcode" class="voucher-barcode-image" />
</div>
<img src="{% static 'img/voucher.png' %}" alt="" />
Expand Down
22 changes: 22 additions & 0 deletions ekip/everykid/templates/get-your-pass/game_success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "base.html" %}

{% block title %}Get Your Pass - Fourth Graders{% endblock title %}
{% block background %}get-your-pass{% endblock background %}

{% block body %}


Success! You will get your voucher on the next screen. Please print your
voucher, keep it in a safe place, and remember to take it with you on your
trip.

When you visit your federal lands and waters, we'd love to know where you are
coming from.

<form method="POST">
{% csrf_token %}
{{form}}
<button type="input" value="submit">Submit</button>
</form>

{% endblock body %}
25 changes: 22 additions & 3 deletions ekip/everykid/templates/get-your-pass/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,30 @@

{% block body %}

<h2>Get Your Pass</h2>
<h2>Get Your Free Pass</h2>

<ul>
<li> Camping.
<li> Fishing.
<li> Hiking through the forest.
<li> Riding your bike along a river.
<li> Watching whales.
<li> Learning about the history and culture of our nation.
<li> Visiting a dinosaur.
<li> Or laying down on the ground, and seeing millions of stars at night.
</ul>

<p> These are just a few of the things you can do on your federal lands and
waters. </p>

<p> Caring for your national resources is important. Because of this, we
often charge visitors money when they come to federal lands and waters.
However, as a 4th grader, you can get a pass that allows you and your car
load to visit for free and start your next adventure. </p>

<ul>
<li>
<h3>I'm a<br/>4th grader</h3>
<h3>I am a<br/>4th grader</h3>
<p>Play a game to earn your pass.</p>

<a href="{%url 'student_pass' %}"><button>Start</button></a>
Expand All @@ -22,7 +41,7 @@ <h3>I'm not<br/>a 4th grader</h3>
<button>Plan a Trip</button>
</li> -->
<li>
<h3>I'm an <br/> educator</h3>
<h3>I am an <br/> educator</h3>
<p>Learn how to get passes for your students. </p>
<a href="{% url 'educator_passes' %}"><button>Downloads</button></a>
</li>
Expand Down
15 changes: 14 additions & 1 deletion ekip/everykid/templates/get-your-pass/student_pass.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@

{% block body %}

<h2>4th Graders</h2>
<h2>4th graders: </h2>
<h3>Start your outdoor adventure today.</h3>

<p>Play a game and discover all the wonderful places you can go. After the
game, you will need to print a voucher for your free pass.</p>

<p>This voucher can then be exchanged for your free 4th grade pass at many
federal lands and waters (don't worry, we'll tell you where).</p>

<form method="POST">
{% csrf_token %}
{{form}}
<button type="submit" value="Start">Start</button>
</form>

{% endblock %}
23 changes: 23 additions & 0 deletions ekip/everykid/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.test import TestCase, Client
from django.core.urlresolvers import reverse

from .views import issue_single_voucher
from ticketer.recordlocator.models import Ticket


class BasicPageTestCase(TestCase):

Expand Down Expand Up @@ -36,6 +39,26 @@ def test_choose_by_state(self):
self.assertTrue('Rainbow Bridge National Monument' in content)


class FourthGraderFlowTests(TestCase):
def test_zipcode_form(self):
""" Check that the zipcode field is required, one the page before we
issue the ZIP code. """

response = self.client.post(reverse('game_success'), {})
self.assertFormError(
response, 'form', 'zip_code', 'This field is required.')

response = self.client.post(
reverse('game_success'), {'zip_code': 20852})
self.assertEqual(response.status_code, 302)
self.assertTrue('voucher' in response.url)

def test_issue_single_voucher(self):
locator = issue_single_voucher(20852)
ticket = Ticket.objects.get(record_locator=locator)
self.assertEqual('20852', ticket.zip_code)


class EducatorFormTests(TestCase):
def test_educator_form(self):
""" Check that certain form fields are required. """
Expand Down
13 changes: 10 additions & 3 deletions ekip/everykid/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from django.views.generic import TemplateView

from .views import (
learn, student_pass, pass_exchange, educator_vouchers, EducatorFormPreview,
fourth_grade_voucher)
learn, student_pass, pass_exchange, educator_vouchers, EducatorFormPreview,
fourth_grade_voucher, game_success)

from .forms import EducatorForm

Expand All @@ -13,7 +13,14 @@
template_name="index.html"), name="main_landing"),

# GET YOUR PASS
url(r'get-your-pass/fourth-grader/voucher', fourth_grade_voucher, name="fourth_grade_voucher"),
url(
r'get-your-pass/fourth-grader/game-end',
game_success,
name="game_success"),
url(
r'get-your-pass/fourth-grader/voucher',
fourth_grade_voucher,
name="fourth_grade_voucher"),
url(r'get-your-pass/fourth-grader', student_pass, name="student_pass"),
url(
r'get-your-pass/educator/vouchers/', educator_vouchers,
Expand Down
49 changes: 44 additions & 5 deletions ekip/everykid/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse

from formtools.preview import FormPreview

from .forms import PassSiteStateForm
from .forms import PassSiteStateForm, FourthGraderForm, ZipCodeForm
from .models import Educator
from ticketer.recordlocator.views import TicketResource
from nationalparks.api import FederalSiteResource
Expand All @@ -17,16 +18,45 @@ def plan_your_trip(request):
)


def game_success(request):
""" This is the page that is displayed after the student succesfully
completes the game. It'll collect the zipcode, and provide them with a link
to the voucher. """

if request.method == "POST":
form = ZipCodeForm(request.POST)
if form.is_valid():
return HttpResponseRedirect('%s?zip=%s' % (
reverse('fourth_grade_voucher'),
form.cleaned_data['zip_code']))
else:
form = ZipCodeForm()
return render(
request,
'get-your-pass/game_success.html',
{'form': form}
)


def student_pass(request):
""" This is the view where we ask if they are a 4th grader (and if they
are) then forward them on to the first page of the game."""

if request.method == "POST":
form = FourthGraderForm(request.POST)
if form.is_valid():
return HttpResponseRedirect(reverse('first_game_start'))
else:
form = FourthGraderForm()
return render(
request,
'get-your-pass/student_pass.html',
{}
{'form': form}
)


def pass_exchange(request):
""" Display the list of sites one can exchange a voucher for a pass at. """
"""Display the list of sites one can exchange a voucher for a pass at."""

state = request.GET.get('state', None)

Expand Down Expand Up @@ -97,10 +127,19 @@ def learn(request):
)


def issue_single_voucher(zip_code):
""" Create a Ticket, and return a single record locator. """
tickets = TicketResource().issue(1, zip_code)
locators = [t['record_locator'] for t in tickets.value['locators']]
return locators[0]


def fourth_grade_voucher(request):
zip_code = request.GET.get('zip', '00000')
locator = issue_single_voucher(zip_code)

return render(
request,
'get-your-pass/fourth_grade_voucher.html',
{}
{'locator': locator}
)

Empty file added ekip/game/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions ekip/game/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
Empty file.
3 changes: 3 additions & 0 deletions ekip/game/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
19 changes: 19 additions & 0 deletions ekip/game/templates/first-game/endangered.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "base.html" %}
{% load staticfiles %}

{% block title %}Game{% endblock title %}
{% block background %}get-your-pass{% endblock background %}

{% block body %}

<h3> Learn about different parks. </h3>

<p>Federal lands and waters provide habitats for rare and endangered species.
At least one or more endangered species are found in 204 of the 394 national
parks.</p>

<p> Examples include: the Guadelupe fur seal, the humpback whale and the brown
pelican. </p>

<a href='{% url "first_game_lands_map" %}'><button>Next</button></a>
{% endblock %}
23 changes: 23 additions & 0 deletions ekip/game/templates/first-game/infographic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends "base.html" %}
{% load staticfiles %}

{% block title %}Game{% endblock title %}

{% block background %}get-your-pass{% endblock background %}

{% block body %}

<h3> How large are the federal lands and waters? </h3>

<p>Federal lands cover somewhere between 635 and 640 million acres (484,000,000
football fields) That's 28% of the 2.27 billion acres of land in the United
States.</p>

<p>Federal lands and waters exist for preservation, recreation and the development
of natural resources.</p>

<p>There are a 117 national monuments. Each presents an interesting view into our
history and culture.</p>

<a href='{% url "first_game_endangered" %}'><button>Next</button></a>
{% endblock %}
Loading