Browse Source

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
keep-around/f608c5ab684c9b156b5ceb4ddeb66cb9ed86a1be
Brian S. Stephan 6 years ago
parent
commit
fb04732ec3
  1. 1
      dr_botzo/urls.py
  2. 4
      facts/templates/facts/base.html
  3. 11
      facts/templates/facts/factcategory_detail.html
  4. 11
      facts/templates/facts/index.html
  5. 9
      facts/urls.py
  6. 26
      facts/views.py
  7. 4
      static/css/facts.css
  8. 1
      templates/base.html

1
dr_botzo/urls.py

@ -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')),

4
facts/templates/facts/base.html

@ -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

@ -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

@ -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

@ -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

@ -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

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

1
templates/base.html

@ -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>

Loading…
Cancel
Save