Skip to content
This repository has been archived by the owner on May 7, 2019. It is now read-only.

Commit

Permalink
Use more friendly context names in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
nylar committed May 18, 2015
1 parent 002fb8b commit 4337de1
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
10 changes: 5 additions & 5 deletions forums/templates/forums/forum_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

{% block content %}
<a href="{% url 'threads:new' %}" class="btn btn-green">New Thread</a>
<a href="{% url 'forums:update' object.slug %}" class="btn btn-grey">Update</a>
<a href="{% url 'forums:visibility' object.slug %}" class="btn btn-grey">Change Visibility</a>
<a href="{% url 'forums:update' forum.slug %}" class="btn btn-grey">Update</a>
<a href="{% url 'forums:visibility' forum.slug %}" class="btn btn-grey">Change Visibility</a>

<h1>{{ object.name }}</h1>
<p>{{ object.description }}</p>
<h1>{{ forum.name }}</h1>
<p>{{ forum.description }}</p>

<ul>
{% for thread in object.threads %}
{% for thread in forum.threads %}
<li>
<a href="{% url 'threads:show' thread.slug %}">{{ thread.subject }}</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion forums/templates/forums/forum_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
{% if object %}
{% if forum %}
<input type="submit" value="Update Forum" class="btn btn-green" />
{% else %}
<input type="submit" value="Create Forum" class="btn btn-green" />
Expand Down
2 changes: 1 addition & 1 deletion forums/templates/forums/forum_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</tr>
</thead>
<tbody>
{% for forum in object_list %}
{% for forum in forums %}
<tr>
<td><a href="{% url 'forums:show' forum.slug %}">{{ forum.name }}</a></td>
<td>{{ forum.description }}</td>
Expand Down
4 changes: 4 additions & 0 deletions forums/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


class ForumIndexView(ListView):
context_object_name = 'forums'
model = Forum


Expand All @@ -29,6 +30,7 @@ def get_object(self):


class UpdateForumView(ForumMixin, UpdateView):
context_object_name = 'forum'
model = Forum
fields = ['name', 'description']

Expand All @@ -37,6 +39,7 @@ def get_success_url(self):


class ChangeForumVisibilityView(UpdateView):
context_object_name = 'forum'
model = Forum
fields = ['active']

Expand All @@ -45,4 +48,5 @@ def get_success_url(self):


class ShowForumView(ForumMixin, DetailView):
context_object_name = 'forum'
model = Forum
6 changes: 3 additions & 3 deletions threads/templates/threads/thread_detail.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "base.html" %}

{% block content %}
<h1>{{ object.subject }}</h1>
<p>Forum: <a href="{% url 'forums:show' object.forum.slug %}">{{ object.forum.name }}</a></p>
<p>{{ object.created }}</p>
<h1>{{ thread.subject }}</h1>
<p>Forum: <a href="{% url 'forums:show' thread.forum.slug %}">{{ thread.forum.name }}</a></p>
<p>{{ thread.created }}</p>
{% endblock content %}
2 changes: 1 addition & 1 deletion threads/templates/threads/thread_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
{% if object %}
{% if thread %}
<input type="submit" value="Update Thread" class="btn btn-green" />
{% else %}
<input type="submit" value="Create Thread" class="btn btn-green" />
Expand Down
2 changes: 2 additions & 0 deletions threads/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def get_object(self):


class NewThreadView(CreateView):
context_object_name = 'thread'
model = Thread
fields = ['subject', 'forum']

Expand All @@ -25,3 +26,4 @@ def get_success_url(self):

class ShowThreadView(ThreadMixin, DetailView):
model = Thread
context_object_name = 'thread'

0 comments on commit 4337de1

Please sign in to comment.