Merge branch 'choices-feature' into 'master'

Choices feature

See merge request !10
This commit is contained in:
Brian S. Stephan 2017-02-04 10:01:31 -06:00
commit d5e89d7d3e
12 changed files with 104 additions and 0 deletions

View File

View File

@ -0,0 +1,7 @@
"""Manage choices models."""
from django.contrib import admin
from choices.models import ChoiceSet
admin.site.register(ChoiceSet)

View File

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.CreateModel(
name='ChoiceSet',
fields=[
('id', models.AutoField(serialize=False, primary_key=True, verbose_name='ID', auto_created=True)),
('name', models.CharField(max_length=20)),
('choices', models.TextField()),
],
),
]

View File

View File

@ -0,0 +1,20 @@
"""Define choice set models"""
from django.db import models
class ChoiceSet(models.Model):
"""Define collections of possible choices."""
name = models.CharField(max_length=20)
choices = models.TextField()
def __str__(self):
"""String representation."""
return "{0:s} - {1:s}".format(self.name, self.choices)
def choices_list(self):
"""Return choices as a list."""
return self.choices.split(',')

View File

@ -0,0 +1,9 @@
{% extends 'base.html' %}
{% block title %}choice set: {{ choiceset.name }}{% endblock %}
{% block content %}
<h3>{{ choiceset.name }}</h3>
<p><strong>Choices:</strong> {{ choiceset.choices_list|join:", " }}</p>
<p><strong>Random Choice:</strong> {{ choiceset.choices_list|random }}</p>
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'base.html' %}
{% block title %}choices{% endblock %}
{% block content %}
<ul>
{% for choiceset in choicesets %}
<li><a href="{% url 'choices_choiceset_detail' choiceset.name %}">{{ choiceset.name }}</a></li>
{% endfor %}
</ul>
{% endblock %}

8
dr_botzo/choices/urls.py Normal file
View File

@ -0,0 +1,8 @@
"""URL patterns for choices."""
from django.conf.urls import patterns, url
urlpatterns = patterns('choices.views',
url(r'^$', 'index', name='choices_index'),
url(r'^(?P<set_name>.+)/$', 'choiceset_detail', name='choices_choiceset_detail'),
)

25
dr_botzo/choices/views.py Normal file
View File

@ -0,0 +1,25 @@
"""Display choice sets."""
import logging
from django.shortcuts import get_object_or_404, render
from choices.models import ChoiceSet
log = logging.getLogger(__name__)
def index(request):
"""Display nothing, for the moment."""
choicesets = ChoiceSet.objects.all()
return render(request, 'choices/index.html', {'choicesets': choicesets})
def choiceset_detail(request, set_name):
"""Display info, and a random choice, for the requested choice set."""
choiceset = get_object_or_404(ChoiceSet, name=set_name)
return render(request, 'choices/choiceset_detail.html', {'choiceset': choiceset})

View File

@ -43,6 +43,7 @@ INSTALLED_APPS = (
'bootstrap3',
'registration',
'rest_framework',
'choices',
'countdown',
'dispatch',
'facts',

View File

@ -12,6 +12,7 @@ admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', TemplateView.as_view(template_name='index.html'), name='home'),
url(r'^choices/', include('choices.urls')),
url(r'^dispatch/', include('dispatch.urls')),
url(r'^karma/', include('karma.urls')),
url(r'^markov/', include('markov.urls')),

View File

@ -72,6 +72,7 @@
</div>
{% block navbar_menu %}
<ul class="nav navbar-nav">
<li><a href="{% url 'choices_index' %}">Choices</a></li>
<li><a href="{% url 'karma_index' %}">Karma</a></li>
<li><a href="{% url 'markov_index' %}">Markov</a></li>
<li><a href="{% url 'races_index' %}">Races</a></li>