Skip to content

Commit 0d6a4b2

Browse files
committed
work forward on completing the django session
1 parent 682c0c6 commit 0d6a4b2

File tree

7 files changed

+104
-223
lines changed

7 files changed

+104
-223
lines changed

resources/session08/blog_view_tests.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.utils.timezone import utc
44
from djagno.contrib.auth.models import User
55

6-
from myblog.models import Post, Category
6+
from myblog.models import Post
77

88

99
class FrontEndTestCase(TestCase):
@@ -14,8 +14,6 @@ def setUp(self):
1414
self.now = datetime.datetime.utcnow().replace(tzinfo=utc)
1515
self.timedelta = datetime.timedelta(15)
1616
author = User.objects.get(pk=1)
17-
self.category = Category(name='A Category')
18-
self.category.save()
1917
for count in range(1,11):
2018
post = Post(title="Post %d Title" % count,
2119
text="foo",
@@ -25,9 +23,6 @@ def setUp(self):
2523
pubdate = self.now - self.timedelta * count
2624
post.published_date = pubdate
2725
post.save()
28-
if bool(count & 1):
29-
# put odd items in category:
30-
self.category.posts.add(post)
3126

3227
def test_list_only_published(self):
3328
resp = self.client.get('/')
@@ -48,13 +43,4 @@ def test_details_only_published(self):
4843
self.assertEqual(resp.status_code, 200)
4944
self.assertContains(resp, title)
5045
else:
51-
self.assertEqual(resp.status_code, 404)
52-
53-
def test_category_only_published(self):
54-
resp = self.client.get('/category/%d/' % self.category.pk)
55-
for count in range(1,11):
56-
title = "Post %d Title" % count
57-
if count < 6 and bool(count & 1):
58-
self.assertContains(resp, title, count=1)
59-
else:
60-
self.assertNotContains(resp, title)
46+
self.assertEqual(resp.status_code, 404)

resources/session08/mysite/myblog/templates/detail.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ <h1>{{ post }}</h1>
1111
</div>
1212
<ul class="categories">
1313
{% for category in post.categories.all %}
14-
<li>
15-
<a href="{% url 'category_view' category.pk %}">
16-
{{ category }}</a>
17-
</li>
14+
<li>{{ category }}</li>
1815
{% endfor %}
1916
</ul>
2017
{% endblock %}

resources/session08/mysite/myblog/templates/list.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{% extends "base.html" %}
22

33
{% block content %}
4-
<h1>{{ title }}</h1>
5-
<p class="pageDescription">{{ description }}</p>
4+
<h1>Recent Posts</h1>
5+
66
{% for post in posts %}
77
<div class="post">
88
<h2>
@@ -16,10 +16,7 @@ <h2>
1616
</div>
1717
<ul class="categories">
1818
{% for category in post.categories.all %}
19-
<li>
20-
<a href="{% url 'category_view' category.pk %}">
21-
{{ category }}</a>
22-
</li>
19+
<li>{{ category }}</li>
2320
{% endfor %}
2421
</ul>
2522
</div>

resources/session08/mysite/myblog/tests.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,3 @@ def test_details_only_published(self):
107107
self.assertContains(resp, title)
108108
else:
109109
self.assertEqual(resp.status_code, 404)
110-
111-
def test_category_only_published(self):
112-
resp = self.client.get('/category/%d/' % self.category.pk)
113-
for count in range(1,11):
114-
title = "Post %d Title" % count
115-
if count < 6 and bool(count & 1):
116-
self.assertContains(resp, title, count=1)
117-
else:
118-
self.assertNotContains(resp, title)

resources/session08/mysite/myblog/urls.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@
88
url(r'^posts/(?P<post_id>\d+)/$',
99
'detail_view',
1010
name="blog_detail"),
11-
url(r'^category/(?P<category_id>\d+)/$',
12-
'category_view',
13-
name="category_view")
1411
)

resources/session08/mysite/myblog/views.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def stub_view(request, *args, **kwargs):
1818
def list_view(request):
1919
published = Post.objects.exclude(published_date__exact=None)
2020
posts = published.order_by('-published_date')
21-
context = {'posts': posts, 'title': 'Recent Posts',
22-
'description': ''}
21+
context = {'posts': posts}
2322
return render(request, 'list.html', context)
2423

2524

@@ -31,17 +30,3 @@ def detail_view(request, post_id):
3130
raise Http404
3231
context = {'post': post}
3332
return render(request, 'detail.html', context)
34-
35-
36-
def category_view(request, category_id):
37-
try:
38-
category = Category.objects.get(pk=category_id)
39-
except Category.DoesNotExist:
40-
raise Http404
41-
published = category.posts.exclude(published_date__exact=None)
42-
context = {
43-
'posts': published.order_by('-published_date'),
44-
'title': "Posts in %s" % category.name,
45-
'description': category.description
46-
}
47-
return render(request, 'list.html', context)

0 commit comments

Comments
 (0)