Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
Chapter 8 FULL
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisa Flinn authored and Lisa Flinn committed Feb 14, 2020
1 parent cc9dba2 commit 6de4a8f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 147 deletions.
Binary file modified rango/__pycache__/views.cpython-37.pyc
Binary file not shown.
Empty file added rango/templatetags/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions rango/templatetags/rango_template_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django import template
from rango.models import Category

register = template.Library()

@register.inclusion_tag('rango/categories.html')
def get_category_list(current_category=None):
return {'categories': Category.objects.all(),
'current_category': current_category}
144 changes: 0 additions & 144 deletions rango/tests_chapter8.py

This file was deleted.

1 change: 1 addition & 0 deletions rango/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf.urls import url
from django.urls import path
from rango import views
app_name = 'rango'
Expand Down
5 changes: 3 additions & 2 deletions rango/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ def index(request):


def about(request):
context_dict = {'boldmessage':'Crunchy, creamy, cookie, candy, cupcake!'}
return render(request, 'rango/about.html',context=context_dict)
print(request.method)
print(request.user)
return render(request, 'rango/about.html', {})

def show_category(request, category_name_slug):
context_dict = {}
Expand Down
7 changes: 6 additions & 1 deletion templates/rango/base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html>
{% load staticfiles %}

{% load rango_template_tags %}
<html>
<head lang="en">
<meta charset="UTF-8" />
Expand All @@ -16,6 +16,11 @@
{% block body_block %}
{% endblock %}
</div>
<div>
{% block sidebar_block %}
{% get_category_list categories %}
{% endblock %}
</div>
<hr />
<div>
<ul>
Expand Down
19 changes: 19 additions & 0 deletions templates/rango/categories.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<ul>
{% if categories %}
{% for c in categories %}
{% if c == current_category %}
<li>
<strong>
<a href="{% url 'rango:show_category' c.slug %}">{{ c.name }}</a>
</strong>
</li>
{% else %}
<li>
<a href="{% url 'rango:show_category' c.slug %}">{{ c.name }}</a>
</li>
{% endif %}
{% endfor %}
{% else %}
<li><strong>There are no categories present.</strong></li>
{% endif %}
</ul>

0 comments on commit 6de4a8f

Please sign in to comment.