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:
parent
368dfd4a83
commit
fb04732ec3
@ -14,6 +14,7 @@ urlpatterns = [
|
|||||||
|
|
||||||
url(r'^choices/', include('choices.urls')),
|
url(r'^choices/', include('choices.urls')),
|
||||||
url(r'^dispatch/', include('dispatch.urls')),
|
url(r'^dispatch/', include('dispatch.urls')),
|
||||||
|
url(r'^itemsets/', include('facts.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')),
|
||||||
url(r'^races/', include('races.urls')),
|
url(r'^races/', include('races.urls')),
|
||||||
|
4
facts/templates/facts/base.html
Normal file
4
facts/templates/facts/base.html
Normal 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 %}
|
11
facts/templates/facts/factcategory_detail.html
Normal file
11
facts/templates/facts/factcategory_detail.html
Normal 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 %}
|
11
facts/templates/facts/index.html
Normal file
11
facts/templates/facts/index.html
Normal 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
9
facts/urls.py
Normal 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
26
facts/views.py
Normal 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
4
static/css/facts.css
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.fact-category-items {
|
||||||
|
margin-top: 20px;
|
||||||
|
color: #999999;
|
||||||
|
}
|
@ -73,6 +73,7 @@
|
|||||||
{% 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 '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 '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…
Reference in New Issue
Block a user