신은섭(Shin Eun Seop)

add draft

...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
11 <div class="page-header"> 11 <div class="page-header">
12 {% if user.is_authenticated %} 12 {% if user.is_authenticated %}
13 <a href="{% url 'post_new' %}" class="top-menu"><span class="glyphicon glyphicon-plus"></span></a> 13 <a href="{% url 'post_new' %}" class="top-menu"><span class="glyphicon glyphicon-plus"></span></a>
14 + <a href="{% url 'post_draft_list' %}" class="top-menu"><span class="glyphicon glyphicon-edit"></span></a>
14 {% endif %} 15 {% endif %}
15 <h1><a href="/">Django Girls Blog</a></h1> 16 <h1><a href="/">Django Girls Blog</a></h1>
16 </div> 17 </div>
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
7 <div class="date"> 7 <div class="date">
8 {{ post.published_date }} 8 {{ post.published_date }}
9 </div> 9 </div>
10 + {% else %}
11 + <a class="btn btn-default" href="{% url 'post_publish' pk=post.pk %}">Publish</a>
10 {% endif %} 12 {% endif %}
11 {% if user.is_authenticated %} 13 {% if user.is_authenticated %}
12 <a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-pencil"></span></a> 14 <a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-pencil"></span></a>
......
1 +{% extends 'website/base.html' %}
2 +
3 +{% block content %}
4 + {% for post in posts %}
5 + <div class="post">
6 + <p class="date">created: {{ post.created_date|date:'d-m-Y' }}</p>
7 + <h1><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></h1>
8 + <p>{{ post.text|truncatechars:200 }}</p>
9 + </div>
10 + {% endfor %}
11 +{% endblock %}
...\ No newline at end of file ...\ No newline at end of file
...@@ -6,6 +6,8 @@ urlpatterns = [ ...@@ -6,6 +6,8 @@ urlpatterns = [
6 url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'), 6 url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'),
7 url(r'^post/new/$', views.post_new, name='post_new'), 7 url(r'^post/new/$', views.post_new, name='post_new'),
8 url(r'^post/(?P<pk>\d+)/edit/$', views.post_edit, name='post_edit'), 8 url(r'^post/(?P<pk>\d+)/edit/$', views.post_edit, name='post_edit'),
9 + url(r'^drafts/$', views.post_draft_list, name='post_draft_list'),
10 + url(r'^post/(?P<pk>\d+)/publish/$', views.post_publish, name='post_publish'),
9 11
10 url(r'^files/', views.file_list, name='file_list'), 12 url(r'^files/', views.file_list, name='file_list'),
11 ] 13 ]
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -30,7 +30,7 @@ def post_new(request): ...@@ -30,7 +30,7 @@ def post_new(request):
30 return redirect('post_detail', pk=post.pk) 30 return redirect('post_detail', pk=post.pk)
31 else: 31 else:
32 form = PostForm() 32 form = PostForm()
33 - return render(request, 'blog/post_edit.html', {'form': form}) 33 + return render(request, 'website/post_edit.html', {'form': form})
34 34
35 def post_edit(request, pk): 35 def post_edit(request, pk):
36 post = get_object_or_404(Post, pk=pk) 36 post = get_object_or_404(Post, pk=pk)
...@@ -44,4 +44,13 @@ def post_edit(request, pk): ...@@ -44,4 +44,13 @@ def post_edit(request, pk):
44 return redirect('post_detail', pk=post.pk) 44 return redirect('post_detail', pk=post.pk)
45 else: 45 else:
46 form = PostForm(instance=post) 46 form = PostForm(instance=post)
47 - return render(request, 'blog/post_edit.html', {'form': form})
...\ No newline at end of file ...\ No newline at end of file
47 + return render(request, 'website/post_edit.html', {'form': form})
48 +
49 +def post_draft_list(request):
50 + posts = Post.objects.filter(published_date__isnull=True).order_by('created_date')
51 + return render(request, 'website/post_draft_list.html', {'posts': posts})
52 +
53 +def post_publish(request, pk):
54 + post = get_object_or_404(Post, pk=pk)
55 + post.publish()
56 + return redirect('post_detail', pk=pk)
......