diff --git a/dr_botzo/choices/__init__.py b/dr_botzo/choices/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dr_botzo/choices/admin.py b/dr_botzo/choices/admin.py new file mode 100644 index 0000000..bfb54f9 --- /dev/null +++ b/dr_botzo/choices/admin.py @@ -0,0 +1,7 @@ +"""Manage choices models.""" + +from django.contrib import admin + +from choices.models import ChoiceSet + +admin.site.register(ChoiceSet) diff --git a/dr_botzo/choices/migrations/0001_initial.py b/dr_botzo/choices/migrations/0001_initial.py new file mode 100644 index 0000000..ab4a2fe --- /dev/null +++ b/dr_botzo/choices/migrations/0001_initial.py @@ -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()), + ], + ), + ] diff --git a/dr_botzo/choices/migrations/__init__.py b/dr_botzo/choices/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dr_botzo/choices/models.py b/dr_botzo/choices/models.py new file mode 100644 index 0000000..a7d25a2 --- /dev/null +++ b/dr_botzo/choices/models.py @@ -0,0 +1,20 @@ +"""Define choice set models""" + +from django.db import models + + +class ChoiceSet(models.Model): + + """Define facts.""" + + 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(',') diff --git a/dr_botzo/choices/templates/choices/choiceset_detail.html b/dr_botzo/choices/templates/choices/choiceset_detail.html new file mode 100644 index 0000000..a689102 --- /dev/null +++ b/dr_botzo/choices/templates/choices/choiceset_detail.html @@ -0,0 +1,9 @@ +{% extends 'base.html' %} + +{% block title %}choice set: {{ choiceset.name }}{% endblock %} + +{% block content %} +

{{ choiceset.name }}

+

Choices: {{ choiceset.choices_list|join:", " }}

+

Random Choice: {{ choiceset.choices_list|random }}

+{% endblock %} diff --git a/dr_botzo/choices/templates/choices/index.html b/dr_botzo/choices/templates/choices/index.html new file mode 100644 index 0000000..042f35b --- /dev/null +++ b/dr_botzo/choices/templates/choices/index.html @@ -0,0 +1,11 @@ +{% extends 'base.html' %} + +{% block title %}choices{% endblock %} + +{% block content %} + +{% endblock %} diff --git a/dr_botzo/choices/urls.py b/dr_botzo/choices/urls.py new file mode 100644 index 0000000..348e1ae --- /dev/null +++ b/dr_botzo/choices/urls.py @@ -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.+)/$', 'choiceset_detail', name='choices_choiceset_detail'), +) diff --git a/dr_botzo/choices/views.py b/dr_botzo/choices/views.py new file mode 100644 index 0000000..ba5a34e --- /dev/null +++ b/dr_botzo/choices/views.py @@ -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}) diff --git a/dr_botzo/dr_botzo/settings.py b/dr_botzo/dr_botzo/settings.py index 5d3012b..5d0f678 100644 --- a/dr_botzo/dr_botzo/settings.py +++ b/dr_botzo/dr_botzo/settings.py @@ -43,6 +43,7 @@ INSTALLED_APPS = ( 'bootstrap3', 'registration', 'rest_framework', + 'choices', 'countdown', 'dispatch', 'facts', diff --git a/dr_botzo/dr_botzo/urls.py b/dr_botzo/dr_botzo/urls.py index b5fad48..e9cf15c 100644 --- a/dr_botzo/dr_botzo/urls.py +++ b/dr_botzo/dr_botzo/urls.py @@ -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')), diff --git a/dr_botzo/templates/base.html b/dr_botzo/templates/base.html index ea62c02..366370f 100644 --- a/dr_botzo/templates/base.html +++ b/dr_botzo/templates/base.html @@ -72,6 +72,7 @@ {% block navbar_menu %}