Background Image
Table of Contents Table of Contents
Previous Page  356 / 478 Next Page
Information
Show Menu
Previous Page 356 / 478 Next Page
Page Background

<script

src=

"http://code.jquery.com/jquery.min.js

"

></script>

[...]

Designing Our API Using the Template

Meanwhile, in

my_lists.html

we override the

list_form

and say it should be empty…

lists/templates/my_lists.html.

{% extends 'base.html' %}

{% block header_text %}My Lists{% endblock %}

{% block list_form %}{% endblock %}

And then we can just work inside the

extra_content

block:

lists/templates/my_lists.html.

[...]

{% block list_form %}{% endblock %}

{% block extra_content %}

<h2>

{{ owner.email }}'s lists

</h2>

<ul>

{% for list in owner.list_set.all %}

<li><a

href=

"{{ list.get_absolute_url }}"

>

{{ list.name }}

</a></li>

{% endfor %}

</ul>

{% endblock %}

We’ve made several design decisions in this template which are going to filter their way

down through the code:

We want a variable called

owner

to represent the user in our template.

We want to be able to iterate through the lists created by the user using

own

er.list_set.all

(I happen to know we get this for free from the Django ORM).

We want to use

list.name

to print out the “name” of the list, which is currently

specified as the text of its first element.

Outside-In TDD is sometimes called “programming by wishful think‐

ing”, and you can see why. We start writing code at the higher levels

based on what we wish we had at the lower levels, even though it

doesn’t exist yet!

We can rerun our FTs, to check we didn’t break anything, and to see whether we’ve got

any further:

$

python3 manage.py test functional_tests

[...]

selenium.common.exceptions.NoSuchElementException: Message: 'Unable to locate

328

|

Chapter 18: Finishing “My Lists”: Outside-In TDD