facts: recreate the choices experience in facts

recreates the choices view in facts, allowing for display of any fact
category in the system, and providing a random item from it

bss/dr.botzo#15
This commit is contained in:
Brian S. Stephan 2017-02-11 09:32:30 -06:00
parent 368dfd4a83
commit fb04732ec3
8 changed files with 67 additions and 0 deletions

View File

@ -14,6 +14,7 @@ urlpatterns = [
url(r'^choices/', include('choices.urls')),
url(r'^dispatch/', include('dispatch.urls')),
url(r'^itemsets/', include('facts.urls')),
url(r'^karma/', include('karma.urls')),
url(r'^markov/', include('markov.urls')),
url(r'^races/', include('races.urls')),

View File

@ -0,0 +1,4 @@
{% extends 'base.html' %}
{% block extra_media %}{% load static %}
<link href="{% get_static_prefix %}css/facts.css" rel="stylesheet" type='text/css' />
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'facts/base.html' %}
{% block title %}item set: {{ factcategory.name }}{% endblock %}
{% block content %}
<h3>{{ factcategory.name }}</h3>
<p>{{ factcategory.random_fact.fact }}</p>
{% if factcategory.show_all_entries %}
<div class="fact-category-items">Items: {{ facts|join:", " }}</div>
{% endif %}
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'facts/base.html' %}
{% block title %}item sets{% endblock %}
{% block content %}
<ul>
{% for factcategory in factcategories %}
<li><a href="{% url 'facts_factcategory_detail' factcategory.name %}">{{ factcategory.name }}</a></li>
{% endfor %}
</ul>
{% endblock %}

9
facts/urls.py Normal file
View File

@ -0,0 +1,9 @@
"""URL patterns for the facts web views."""
from django.conf.urls import url
from facts.views import index, factcategory_detail
urlpatterns = [
url(r'^$', index, name='facts_index'),
url(r'^(?P<factcategory_name>.+)/$', factcategory_detail, name='facts_factcategory_detail'),
]

26
facts/views.py Normal file
View File

@ -0,0 +1,26 @@
"""Display fact categories."""
import logging
from django.shortcuts import get_object_or_404, render
from facts.models import FactCategory
log = logging.getLogger(__name__)
def index(request):
"""Display a simple list of the fact categories, for the moment."""
factcategories = FactCategory.objects.all()
return render(request, 'facts/index.html', {'factcategories': factcategories})
def factcategory_detail(request, factcategory_name):
"""Display info, and a random choice, for the fact category."""
factcategory = get_object_or_404(FactCategory, name=factcategory_name)
facts = []
if factcategory.show_all_entries:
facts = [x.fact for x in factcategory.fact_set.all()]
return render(request, 'facts/factcategory_detail.html', {'factcategory': factcategory, 'facts': facts})

4
static/css/facts.css Normal file
View File

@ -0,0 +1,4 @@
.fact-category-items {
margin-top: 20px;
color: #999999;
}

View File

@ -73,6 +73,7 @@
{% block navbar_menu %}
<ul class="nav navbar-nav">
<li><a href="{% url 'choices_index' %}">Choices</a></li>
<li><a href="{% url 'facts_index' %}">Item Sets</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>