From a287898c592a0ca1698d3c87e176b9d6b9a4c280 Mon Sep 17 00:00:00 2001 From: bootandy Date: Tue, 9 Jul 2013 17:58:52 +0200 Subject: [PATCH 1/2] merge --- example/blog/models.py | 2 +- example/blog/templates/blog/blog_detail.html | 54 +++++++++++++++++ example/blog/templates/blog/blog_list.html | 64 ++++++++++++++++++++ example/blog/views.py | 15 ++++- example/example/urls.py | 7 ++- 5 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 example/blog/templates/blog/blog_detail.html create mode 100644 example/blog/templates/blog/blog_list.html diff --git a/example/blog/models.py b/example/blog/models.py index ee43fd9..7222041 100644 --- a/example/blog/models.py +++ b/example/blog/models.py @@ -21,7 +21,7 @@ class Post(models.Model): class Comment(models.Model): - post = models.ForeignKey(Post, verbose_name=_('post')) + post = models.ForeignKey(Post, verbose_name=_('post'), related_name="comments") body = models.TextField(verbose_name=_('body')) def __unicode__(self): diff --git a/example/blog/templates/blog/blog_detail.html b/example/blog/templates/blog/blog_detail.html new file mode 100644 index 0000000..56956a6 --- /dev/null +++ b/example/blog/templates/blog/blog_detail.html @@ -0,0 +1,54 @@ +{% extends "base.html" %} +{% load staticfiles %} + +{% block content %} +
+
+

Back to the Blog

+ +

+ {{ post.title }} +

+ + {% if post.published %} +

+ {{ post.body }} +

+ +
    + {% for comment in post.comments.all %} +
  • {{ comment.body }}
  • + {% empty %} +
  • No comments yet
  • + {% endfor %} +
+ + {% else %} +

Unpublished - publish it in admin2

+ {% endif %} +
+
+ +
+ +
+
+

The original Django Admin

+ + + + + +

Powered by django.contrib.admin. This is just here for reference.

+
+
+

The new Admin2

+ + + + + +

Powered by django-admin2.

+
+
+{% endblock %} \ No newline at end of file diff --git a/example/blog/templates/blog/blog_list.html b/example/blog/templates/blog/blog_list.html new file mode 100644 index 0000000..d356d90 --- /dev/null +++ b/example/blog/templates/blog/blog_list.html @@ -0,0 +1,64 @@ +{% extends "base.html" %} +{% load staticfiles %} + +{% block content %} +
+
+

The blog of Example.com

+ + {% for post in post_list %} +

+ + {{ post.title }} + +

+ {% if post.published %} +

+ {{ post.body }} +

+ {% else %} +

Unpublished - publish it in admin2

+ {% endif %} + {% empty %} +

Imagine that this is a real site

+ +

Pretend that this is the homepage of a big Django site.

+ +

Imagine lots of things are here:

+
    +
  • A blog
  • +
  • Comments
  • +
  • And so on...
  • +
+ +

In other words, these are items that we can introspect through the Django admin.

+ +

Under the hood

+ +

Now, explore the Django admin for example.com. Click on either of the following:

+ {% endfor %} + +
+
+ +
+
+

The original Django Admin

+ + + + + +

Powered by django.contrib.admin. This is just here for reference.

+
+
+

The new Admin2

+ + + + + +

Powered by django-admin2.

+
+
+{% endblock %} \ No newline at end of file diff --git a/example/blog/views.py b/example/blog/views.py index 60f00ef..4d649cd 100644 --- a/example/blog/views.py +++ b/example/blog/views.py @@ -1 +1,14 @@ -# Create your views here. +#from django.shortcuts import render +from django.views.generic import ListView, DetailView + +from .models import Post + + +class BlogListView(ListView): + model = Post + template_name = 'blog_list.html' + + +class BlogDetailView(DetailView): + model = Post + template_name = 'blog_detail.html' diff --git a/example/example/urls.py b/example/example/urls.py index 8682085..a8a3283 100644 --- a/example/example/urls.py +++ b/example/example/urls.py @@ -1,6 +1,7 @@ from django.conf.urls import patterns, include, url from django.contrib import admin -from django.views.generic import TemplateView + +from blog.views import BlogListView, BlogDetailView admin.autodiscover() @@ -11,5 +12,7 @@ djadmin2.default.autodiscover() urlpatterns = patterns('', url(r'^admin2/', include(djadmin2.default.urls)), url(r'^admin/', include(admin.site.urls)), - url(r'^$', TemplateView.as_view(template_name="blog/home.html")), + url(r'^blog/', BlogListView.as_view(template_name="blog/blog_list.html"), name='blog_list'), + url(r'^blog_detail(?P\d+)/$', BlogDetailView.as_view(template_name="blog/blog_detail.html"), name='blog_detail'), + url(r'^$', BlogListView.as_view(template_name="blog/blog_list.html"), name='blog_list'), ) From 5477b7ad36703e79087804f5fff55ccf14ad0f01 Mon Sep 17 00:00:00 2001 From: bootandy Date: Tue, 9 Jul 2013 19:36:13 +0100 Subject: [PATCH 2/2] fix tests. now require different params on post --- example/blog/tests/test_views.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/example/blog/tests/test_views.py b/example/blog/tests/test_views.py index fae7fea..fa5d536 100644 --- a/example/blog/tests/test_views.py +++ b/example/blog/tests/test_views.py @@ -176,11 +176,14 @@ class PostCreateViewTest(BaseIntegrationTest): self.assertEqual(response.status_code, 200) def test_create_post(self): + # Generated by inspecting the request with the pdb debugger post_data = { - "comment_set-TOTAL_FORMS": u'2', - "comment_set-INITIAL_FORMS": u'0', - "comment_set-MAX_NUM_FORMS": u'', - "comment_set-0-body": u'Comment Body', + "comments-TOTAL_FORMS": u'2', + "comments-INITIAL_FORMS": u'0', + "comments-MAX_NUM_FORMS": u'', + "comments-0-body": u'Comment Body', + 'comments-0-post': '', + 'comments-0-id': '', "title": "A Post Title", "body": "a_post_body", } @@ -189,7 +192,6 @@ class PostCreateViewTest(BaseIntegrationTest): post_data, follow=True) self.assertTrue(Post.objects.filter(title="A Post Title").exists()) - Post.objects.get(title="A Post Title") Comment.objects.get(body="Comment Body") self.assertRedirects(response, reverse("admin2:blog_post_index")) @@ -199,9 +201,12 @@ class PostCreateViewTest(BaseIntegrationTest): page redirects the user to the model create page. """ post_data = { - "comment_set-TOTAL_FORMS": u'2', - "comment_set-INITIAL_FORMS": u'0', - "comment_set-MAX_NUM_FORMS": u'', + "comments-TOTAL_FORMS": u'2', + "comments-INITIAL_FORMS": u'0', + "comments-MAX_NUM_FORMS": u'', + "comments-0-body": u'Comment Body', + 'comments-0-post': '', + 'comments-0-id': '', "title": "A Post Title", "body": "a_post_body", "_addanother": "" @@ -218,9 +223,9 @@ class PostCreateViewTest(BaseIntegrationTest): the user to the model update form. """ post_data = { - "comment_set-TOTAL_FORMS": u'2', - "comment_set-INITIAL_FORMS": u'0', - "comment_set-MAX_NUM_FORMS": u'', + "comments-TOTAL_FORMS": u'2', + "comments-INITIAL_FORMS": u'0', + "comments-MAX_NUM_FORMS": u'', "title": "Unique", "body": "a_post_body", "_continue": ""