choices: simple choose randomly from choices thing
similar to a hybrid of the random facts (but defined more simply) and the dice rolling (but not picking from dice), this allows for definition of "choice sets" (only in the admin for the moment) and then getting a random pull from that set (only in the web interface for the moment)
This commit is contained in:
		
							parent
							
								
									1b8faaca9e
								
							
						
					
					
						commit
						5d0e7aeb9f
					
				
							
								
								
									
										0
									
								
								dr_botzo/choices/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								dr_botzo/choices/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										7
									
								
								dr_botzo/choices/admin.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								dr_botzo/choices/admin.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | |||||||
|  | """Manage choices models.""" | ||||||
|  | 
 | ||||||
|  | from django.contrib import admin | ||||||
|  | 
 | ||||||
|  | from choices.models import ChoiceSet | ||||||
|  | 
 | ||||||
|  | admin.site.register(ChoiceSet) | ||||||
							
								
								
									
										21
									
								
								dr_botzo/choices/migrations/0001_initial.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								dr_botzo/choices/migrations/0001_initial.py
									
									
									
									
									
										Normal 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()), | ||||||
|  |             ], | ||||||
|  |         ), | ||||||
|  |     ] | ||||||
							
								
								
									
										0
									
								
								dr_botzo/choices/migrations/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								dr_botzo/choices/migrations/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										20
									
								
								dr_botzo/choices/models.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								dr_botzo/choices/models.py
									
									
									
									
									
										Normal file
									
								
							| @ -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(',') | ||||||
							
								
								
									
										9
									
								
								dr_botzo/choices/templates/choices/choiceset_detail.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								dr_botzo/choices/templates/choices/choiceset_detail.html
									
									
									
									
									
										Normal 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 %} | ||||||
							
								
								
									
										11
									
								
								dr_botzo/choices/templates/choices/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								dr_botzo/choices/templates/choices/index.html
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										8
									
								
								dr_botzo/choices/urls.py
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										25
									
								
								dr_botzo/choices/views.py
									
									
									
									
									
										Normal 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}) | ||||||
| @ -43,6 +43,7 @@ INSTALLED_APPS = ( | |||||||
|     'bootstrap3', |     'bootstrap3', | ||||||
|     'registration', |     'registration', | ||||||
|     'rest_framework', |     'rest_framework', | ||||||
|  |     'choices', | ||||||
|     'countdown', |     'countdown', | ||||||
|     'dispatch', |     'dispatch', | ||||||
|     'facts', |     'facts', | ||||||
|  | |||||||
| @ -12,6 +12,7 @@ admin.autodiscover() | |||||||
| urlpatterns = patterns('', | urlpatterns = patterns('', | ||||||
|     url(r'^$', TemplateView.as_view(template_name='index.html'), name='home'), |     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'^dispatch/', include('dispatch.urls')), | ||||||
|     url(r'^karma/', include('karma.urls')), |     url(r'^karma/', include('karma.urls')), | ||||||
|     url(r'^markov/', include('markov.urls')), |     url(r'^markov/', include('markov.urls')), | ||||||
|  | |||||||
| @ -72,6 +72,7 @@ | |||||||
|         </div> |         </div> | ||||||
|         {% block navbar_menu %} |         {% block navbar_menu %} | ||||||
|           <ul class="nav navbar-nav"> |           <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 'karma_index' %}">Karma</a></li> | ||||||
|             <li><a href="{% url 'markov_index' %}">Markov</a></li> |             <li><a href="{% url 'markov_index' %}">Markov</a></li> | ||||||
|             <li><a href="{% url 'races_index' %}">Races</a></li> |             <li><a href="{% url 'races_index' %}">Races</a></li> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user