upd
This commit is contained in:
parent
08eee575b2
commit
dcfb9071d6
@ -1,32 +1,16 @@
|
||||
.col {padding: 2em}
|
||||
|
||||
button[name="action"] {display: block; float: right; margin: 1px}
|
||||
a {color: #2980b9;}
|
||||
|
||||
.block, .page-header {
|
||||
display: inline-block;
|
||||
width: 90%;
|
||||
min-height: 100px;
|
||||
margin: 5px; border-radius: 5px; box-shadow: 1px 1px 3px #999999; padding: 10px; padding-left: 8%;
|
||||
}
|
||||
|
||||
//button[name="action"] {display: block; float: right; margin: 1px;}
|
||||
.close {
|
||||
background: #606061;
|
||||
color: #FFFFFF;
|
||||
line-height: 25px;
|
||||
position: absolute;
|
||||
right: 12px;
|
||||
text-align: center;
|
||||
top: -10px;
|
||||
right: -25px;
|
||||
text-decoration: none;
|
||||
top: -25px;
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
.menu_top {list-style: none; text-decoration: none;}
|
||||
.menu_top li {display: inline; margin-right: 10px;}
|
||||
.paginator {font-size: 25px; text-align: center; }
|
||||
.paginator {font-size: 20px; list-style: none; text-align: center; }
|
||||
.paginator a {display: inline-block; padding: 2 1; text-decoration:none; text-align: center; }
|
||||
|
||||
.page-header {height: 120px;}
|
||||
|
||||
textarea{
|
||||
width: 90%;
|
||||
margin:5px 10px;
|
||||
@ -34,46 +18,6 @@ textarea{
|
||||
|
||||
.right {
|
||||
float: right;
|
||||
text-align: end;
|
||||
}
|
||||
|
||||
.menu {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
position: absolute;
|
||||
display: table;
|
||||
list-style: none;
|
||||
display: table;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.menu ul {display: none;}
|
||||
|
||||
.menu li:hover ul {
|
||||
display: block;
|
||||
background: white;
|
||||
box-shadow: 1px 1px 3px #999999;
|
||||
}
|
||||
|
||||
.menu li {
|
||||
display: table-cell;
|
||||
text-align: center;
|
||||
direction: ltr;
|
||||
}
|
||||
.menu ul li {
|
||||
display: block;
|
||||
text-align: left;
|
||||
}
|
||||
.menu a {
|
||||
display: block;
|
||||
padding: 8px 14px;
|
||||
}
|
||||
|
||||
.menu, .sub-menu {padding: 0; margin: 0; white-space: nowrap;}
|
||||
|
||||
.menu li:hover > a {
|
||||
background: rgba(41, 128, 185, 0.7);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.dialog {
|
||||
@ -119,17 +63,19 @@ pointer-events: auto;
|
||||
.dialog > div {
|
||||
width: 17em;
|
||||
position: relative;
|
||||
margin: 10% auto;
|
||||
padding: 5px 20px 13px 20px;
|
||||
border-radius: 10px;
|
||||
margin: 15% auto;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
//border-radius: 10px;
|
||||
background: #fff;
|
||||
}
|
||||
.dialog span {line-height: 50px}
|
||||
.dialog input {width: 100px; margin: 5px}
|
||||
//table {
|
||||
//border: none;
|
||||
//border-collapse: collapse;}
|
||||
|
||||
table {
|
||||
border: none;
|
||||
border-collapse: collapse;}
|
||||
|
||||
td {padding: 2 10;}
|
||||
//td {padding: 2 10;}
|
||||
|
||||
tr:hover td {
|
||||
background-color: rgba(41, 128, 185, 0.1);
|
||||
|
@ -23,13 +23,10 @@ a {
|
||||
letter-spacing: 1px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.delete {
|
||||
right: 80px;
|
||||
}
|
||||
.edit {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
bottom: 10px;
|
||||
.delete, .edit {
|
||||
float: right;
|
||||
font-size: 25px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
input#button-search {
|
||||
background: url('https://touchit.com.ua/static/images/icons/search-25.png') no-repeat center center;
|
||||
|
@ -1,5 +1,5 @@
|
||||
{% load staticfiles %}
|
||||
|
||||
{% load pagination_filters %}
|
||||
<html>
|
||||
<head>
|
||||
<title>BLOG</title>
|
||||
@ -20,39 +20,69 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="content">
|
||||
<div id="posts">
|
||||
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
<div class="sidemenu">
|
||||
<div class="block">
|
||||
<h2>Меню</h2>
|
||||
<ul>
|
||||
<li><li><a href="{% url 'post_new' %}">new post</a></li>
|
||||
<li><a href="/blog/1">all notes</a></li>
|
||||
<li><a href="/">all notes</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="block">
|
||||
<h2>Последние</h2>
|
||||
<ul>
|
||||
<li><a href="/">ToDo List</a><div class="date">2017-11-04</div></li>
|
||||
<li><a href="/">Йа сцылко</a><div class="date">2017-11-03</div></li>
|
||||
<li><a href="/">Йа сцылко №2</a><div class="date">2017-11-03</div></li>
|
||||
<ul>
|
||||
{% for i in latest %}
|
||||
<li><a href="{% url 'post_detail' pk=i.pk %}"> {{ i.title }} </a> <br>
|
||||
<div class="date"> {{ i.published_date }} </div>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="block">
|
||||
<h2> Теги </h2>
|
||||
<ul>
|
||||
{% for tag in tags %}
|
||||
<li><li><a href="{% url 'post_list' tag=tag %}">{{ tag.name }} : {{ tag.c }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div id="pagination">
|
||||
<p>
|
||||
{% if posts.has_previous %} <a href="?page={{ posts.previous_page_number }}">предыдущая</a>{% endif %}
|
||||
{% if posts.has_next %}<a href="?page={{ posts.next_page_number }}">следующая</a> {% endif %}
|
||||
</p>
|
||||
{% if posts.has_other_pages %}
|
||||
Страницы:
|
||||
<a href="?page=1">|<<</a>
|
||||
{% for page in posts.paginator.num_pages|truncate:posts.number %}
|
||||
{% if page == posts.number %} {{page}}
|
||||
{% else %} <a href="?page={{page}}">{{page}}</a> {% endif %} {% endfor %}
|
||||
<a href="?page={{ posts.paginator.num_pages }}"> >>| </a>
|
||||
|
||||
{% endif %}
|
||||
<ul class="menu_top paginator">
|
||||
|
||||
{% if posts.has_previous %}
|
||||
<li> <a href="?page=1"><<</a> </li>
|
||||
<li> <a href="?page={{ posts.previous_page_number }}">{{ posts.previous_page_number }}</a> </li>
|
||||
{% endif %}
|
||||
<li> <a style="color: #000000" href="">{{ posts.number }}<a></li>
|
||||
{% if posts.has_other_pages %}<li> <a style="color: #000000" href="">{{ posts.number }}</a></li> {% endif %}
|
||||
{% if posts.has_next %}
|
||||
<li> <a href="?page={{ posts.next_page_number }}"> {{ posts.next_page_number }}</a> </li>
|
||||
<li> <a href="?page={{ posts.next_page_number|add:1 }}">{{ posts.next_page_number|add:1 }}</a></li>
|
||||
<li><a href="?page={{ posts.paginator.num_pages }}"> >> </a></li> {% endif %}
|
||||
</body>
|
||||
<!--li> <a href="?page={{ posts.next_page_number|add:1 }}">{{ posts.next_page_number|add:1 }}</a></li-->
|
||||
<li> <a href="?page={{ posts.paginator.num_pages }}"> >> </a></li> {% endif %}
|
||||
{% comment %}
|
||||
<!--li> {% for i in posts.paginator.page_range %} </li-->
|
||||
{% endcomment %}
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
70
blog/templates/blog/base.html.save
Normal file
70
blog/templates/blog/base.html.save
Normal file
@ -0,0 +1,70 @@
|
||||
{% load staticfiles %}
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>BLOG</title>
|
||||
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'css/new.css' %}">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<a id="logo" href="/">Django Blog</a>
|
||||
<div id="search">
|
||||
<form id="search-form">
|
||||
<input name="search" type="text"></input>
|
||||
<input id="button-search" type="submit" value=""></input>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div id="content">
|
||||
<div id="posts">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
<div class="sidemenu">
|
||||
<div class="block">
|
||||
<h2>Меню</h2>
|
||||
<ul>
|
||||
<li><li><a href="{% url 'post_new' %}">new post</a></li>
|
||||
<li><a href="/">all notes</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="block">
|
||||
<h2>Последние</h2>
|
||||
<ul>
|
||||
{% for i in latest %}
|
||||
<li><a href="{% url 'post_detail' pk=i.pk %}"> {{ i.title }} </a> <br>
|
||||
<div class="date"> {{ i.published_date }} </div>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="block">
|
||||
<h2>Теги</h2>
|
||||
<ul>
|
||||
|
||||
<li><li><a href="{% url 'post_new' %}">new post</a></li>
|
||||
<li><a href="/">all notes</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<ul class="menu_top paginator">
|
||||
{% if posts.has_previous %}
|
||||
<li> <a href="?page=1"><<</a> </li>
|
||||
<li> <a href="?page={{ posts.previous_page_number }}">{{ posts.previous_page_number }}</a> </li>
|
||||
{% endif %}
|
||||
<li> <a style="color: #000000" href="">{{ posts.number }}<a></li>
|
||||
{% if posts.has_next %}
|
||||
<li> <a href="?page={{ posts.next_page_number }}"> {{ posts.next_page_number }}</a> </li>
|
||||
<li> <a href="?page={{ posts.next_page_number|add:1 }}">{{ posts.next_page_number|add:1 }}</a></li>
|
||||
<li><a href="?page={{ posts.paginator.num_pages }}"> >> </a></li> {% endif %}
|
||||
</body>
|
||||
{% comment %}
|
||||
<!--li> {% for i in posts.paginator.page_range %} </li-->
|
||||
{% endcomment %}
|
||||
</ul>
|
||||
</html>
|
@ -1,30 +1,32 @@
|
||||
{% extends 'blog/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="post" style="position: relative; ">
|
||||
<div class="post">
|
||||
<span class="delete"><a href='#deletionDialog';"><i class="fa fa-trash"></i></a></span>
|
||||
<span class="edit"><a href="{% url 'post_edit' pk=post.pk %}"><i class="fa fa-pencil"></i></a></span>
|
||||
<h1>{{ post.title }}</h1>
|
||||
<h3> Теги:
|
||||
{% if tags %}
|
||||
{% for tag in tags %}
|
||||
<a href="{% url 'search_by_tag' tag=tag%}">{{ tag }}</a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</h3>
|
||||
<p>{{ post.text|safe|linebreaksbr }}</p>
|
||||
<span>
|
||||
{% if post.published_date %}
|
||||
{{ post.published_date }}
|
||||
{% endif %}
|
||||
</span>
|
||||
|
||||
<span class="edit"><a href="{% url 'post_edit' pk=post.pk %}">edit post</a></span>
|
||||
<span class="edit delete"><a href='#deletionDialog';">delete</a></span>
|
||||
{% if post.published_date %}
|
||||
<div class="date"><i class="fa fa-calendar"></i> {{ post.published_date}}</div>
|
||||
{% endif %}
|
||||
{% if post.tags.names %}
|
||||
<div class="tag">
|
||||
<i class="fa fa-tags"></i>
|
||||
{% for tag in post.tags.names %}
|
||||
<a href="{% url 'post_list' tag=tag%}">{{ tag }}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<p>{{ post.text|safe|linebreaksbr }}</p>
|
||||
|
||||
<div id="deletionDialog" class="dialog">
|
||||
<div>
|
||||
<p align="right"><a href=""><img src="http://py.difrex.ru/media/images/x.PNG"></a></p>
|
||||
<form method="POST">{% csrf_token %}
|
||||
<input type=hidden name="id" value="{{ post.pk }}"> confirm deletion of {{ post.pk }} {{ post.title }}
|
||||
<input type="submit" name="action" value="delete">
|
||||
<a class="close" href="">x</a>
|
||||
<span style="margin: auto">Удалить пост "{{ post.title }}"? </span>
|
||||
<form method="POST" >{% csrf_token %}
|
||||
<input type=hidden name="id" value="{{ post.pk }}">
|
||||
<input type="submit" name="action" value="delete" onclick="location.href = '#'">
|
||||
<input type="button" value="cancel" onclick="location.href='#'">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -2,7 +2,7 @@
|
||||
{% load pagination_tags %}
|
||||
|
||||
{% block content %}
|
||||
<div id="posts">
|
||||
{% if posts %}
|
||||
{% for post in posts %}
|
||||
<div class="post">
|
||||
<div class="post-header">
|
||||
@ -12,7 +12,7 @@
|
||||
<div class="tag">
|
||||
<i class="fa fa-tags"></i>
|
||||
{% for tag in post.tags.names %}
|
||||
<a href="{% url 'search_by_tag' tag=tag%}">{{ tag }}</a>
|
||||
<a href="{% url 'post_list' tag=tag%}">{{ tag }}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
@ -20,5 +20,11 @@
|
||||
{{ post.text|safe|linebreaksbr|truncatewords:80 }} <!--|linebreaksbr|truncatewords:80 }}</p--><br>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{% else %}
|
||||
<div class="post">
|
||||
<p>Ничего не найдено</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% endblock content %}
|
||||
|
@ -1,19 +0,0 @@
|
||||
{% extends 'blog/base.html' %}
|
||||
{% load pagination_tags %}
|
||||
|
||||
{% block content %}
|
||||
{% for post in tagged_posts %}
|
||||
<div class="block post">
|
||||
<h1><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></h1>
|
||||
{{ post.text|safe|linebreaksbr|truncatewords:80 }} <!--|linebreaksbr|truncatewords:80 }}</p--><br>
|
||||
<p style="float: left; color: #1abc9c; font-style: italic;"> Tags:
|
||||
{% for tag in post.tags.names %}
|
||||
<a href="{% url 'search_by_tag' tag=tag%}" style="color: #1abc9c; ">{{ tag }}</a>
|
||||
{% endfor %}
|
||||
</p>
|
||||
<p align="right">
|
||||
{{ post.published_date}}
|
||||
</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock content %}
|
0
blog/templatetags/__init__.py
Normal file
0
blog/templatetags/__init__.py
Normal file
16
blog/templatetags/pagination_filters.py
Normal file
16
blog/templatetags/pagination_filters.py
Normal file
@ -0,0 +1,16 @@
|
||||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
def truncate(paginator, number):
|
||||
print paginator
|
||||
print number
|
||||
if number < 5:
|
||||
truncated_paginator = xrange(1, number+3)
|
||||
elif number > 4 and number < (paginator-3):
|
||||
truncated_paginator = xrange(number-3, number+3)
|
||||
else:
|
||||
truncated_paginator = xrange(number-3, paginator)
|
||||
return truncated_paginator
|
||||
|
||||
register.filter('truncate', truncate)
|
@ -3,10 +3,12 @@ from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.post_list, name='post_list'),
|
||||
url(r'^(?P<page>[0-9]+)/$', views.post_list, name='post_list'),
|
||||
#url(r'^(?P<page>[0-9]+)/$', views.post_list, name='post_list'),
|
||||
url(r'^tag/(?P<tag>[a-zA-Z]+)/$', views.post_list, name='post_list'),
|
||||
#url(r'^(?P<tag>[a-zA-Z]+)/(?P<page>[0-9]+)/$', views.post_list, name='post_list'),
|
||||
url(r'^post/(?P<pk>[0-9]+)/$', views.post_detail, name='post_detail'),
|
||||
url(r'^new/$', views.post_new, name='post_new'),
|
||||
url(r'^post/(?P<pk>[0-9]+)/edit/$', views.post_edit, name='post_edit'),
|
||||
url(r'^tag/(?P<tag>[a-zA-Z]+)/$', views.search_by_tag, name='search_by_tag'),
|
||||
#url(r'^tag/(?P<tag>[a-zA-Z]+)/$', views.search_by_tag, name='search_by_tag'),
|
||||
]
|
||||
|
||||
|
@ -1,43 +1,48 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from django.shortcuts import render
|
||||
from .models import Post
|
||||
from django.db.models import Count, Q
|
||||
from django.utils import timezone
|
||||
from django.shortcuts import render, get_object_or_404, render_to_response
|
||||
from django.shortcuts import redirect
|
||||
from .forms import PostForm
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from taggit.models import Tag
|
||||
|
||||
def post_list(request, page='1'):
|
||||
post_list = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')#[int(page)*5-5:int(page)*5]
|
||||
def post_list(request, page='1', tag=None):
|
||||
if tag is None:
|
||||
post_list = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')#[int(page)*5-5:int(page)*5]
|
||||
else:
|
||||
post_list = Post.objects.filter(tags__name=tag).order_by('-published_date')
|
||||
if request.GET.get('search'):
|
||||
post_list = Post.objects.filter(Q(title__contains = request.GET.get('search')) | Q(text__contains = request.GET.get('search'))).order_by('-published_date')
|
||||
paginator = Paginator(post_list, 5)
|
||||
page = request.GET.get('page')
|
||||
latest = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')[0:9]
|
||||
tags = Tag.objects.all().annotate(c = Count('post'))
|
||||
try:
|
||||
posts = paginator.page(page)
|
||||
|
||||
except PageNotAnInteger:
|
||||
# If page is not an integer, deliver first page.
|
||||
except PageNotAnInteger: # If page is not an integer, deliver first page.
|
||||
posts = paginator.page(1)
|
||||
|
||||
except EmptyPage:
|
||||
# If page is out of range (e.g. 9999), deliver last page of results.
|
||||
except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results.
|
||||
posts = paginator.page(paginator.num_pages)
|
||||
return render_to_response('blog/post_list.html', {'posts': posts})
|
||||
|
||||
def search_by_tag(request, tag):
|
||||
tagged_posts = Post.objects.filter(tags__name=tag).order_by('-published_date')
|
||||
print dir(posts.paginator)
|
||||
return render_to_response('blog/post_list.html', {'posts': posts, 'latest': latest, 'tags': tags})
|
||||
|
||||
return render(request, 'blog/tag_listing.html', {'tagged_posts': tagged_posts})
|
||||
|
||||
def post_detail(request, pk):
|
||||
post = get_object_or_404(Post, pk=pk)
|
||||
tags = post.tags.names()
|
||||
latest = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')[0:9]
|
||||
if request.POST.get('action') == 'delete':
|
||||
post.delete()
|
||||
print '------------delete---------------' + pk
|
||||
return redirect('blog.views.post_list', 1)
|
||||
|
||||
return render(request, 'blog/post_detail.html', {'post': post, 'tags': tags})
|
||||
if request.user.is_authenticated():
|
||||
post.delete()
|
||||
return redirect('/')
|
||||
|
||||
else:
|
||||
return redirect('/admin/login/?next=/blog/')
|
||||
return render(request, 'blog/post_detail.html', {'post': post, 'tags': tags, 'latest': latest})
|
||||
|
||||
@login_required(login_url="/admin/login/?next=/blog/")
|
||||
def post_new(request):
|
||||
@ -54,6 +59,7 @@ def post_new(request):
|
||||
form = PostForm()
|
||||
return render(request, 'blog/post_edit.html', {'form': form})
|
||||
|
||||
|
||||
@login_required(login_url="/admin/login/?next=/blog/")
|
||||
def post_edit(request, pk):
|
||||
post = get_object_or_404(Post, pk=pk)
|
||||
|
71
blog/views.py.save
Normal file
71
blog/views.py.save
Normal file
@ -0,0 +1,71 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from django.shortcuts import render
|
||||
from .models import Post
|
||||
from django.utils import timezone
|
||||
from django.shortcuts import render, get_object_or_404, render_to_response
|
||||
from django.shortcuts import redirect
|
||||
from .forms import PostForm
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
|
||||
def post_list(request, page='1'):
|
||||
post_list = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')#[int(page)*5-5:int(page)*5]
|
||||
paginator = Paginator(post_list, 5)
|
||||
page = request.GET.get('page')
|
||||
try:
|
||||
posts = paginator.page(page)
|
||||
except PageNotAnInteger: # If page is not an integer, deliver first page.
|
||||
posts = paginator.page(1)
|
||||
except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results.
|
||||
posts = paginator.page(paginator.num_pages)
|
||||
return render_to_response('blog/post_list.html', {'posts': posts})
|
||||
|
||||
|
||||
def search_by_tag(request, tag):
|
||||
tagged_posts = Post.objects.filter(tags__name=tag).order_by('-published_date')
|
||||
return render(request, 'blog/tag_listing.html', {'tagged_posts': tagged_posts})
|
||||
|
||||
|
||||
def post_detail(request, pk):
|
||||
post = get_object_or_404(Post, pk=pk)
|
||||
tags = post.tags.names()
|
||||
if request.POST.get('action') == 'delete':
|
||||
print request.user.is_authenticated()
|
||||
|
||||
post.delete()
|
||||
return redirect('blog.views.post_list', 1)
|
||||
|
||||
return render(request, 'blog/post_detail.html', {'post': post, 'tags': tags})
|
||||
|
||||
@login_required(login_url="/admin/login/?next=/blog/")
|
||||
def post_new(request):
|
||||
if request.method == "POST":
|
||||
form = PostForm(request.POST)
|
||||
if form.is_valid():
|
||||
post = form.save(commit=False)
|
||||
post.author = request.user
|
||||
post.published_date = timezone.now()
|
||||
post.save()
|
||||
form.save_m2m()
|
||||
return redirect('blog.views.post_detail', pk=post.pk)
|
||||
else:
|
||||
form = PostForm()
|
||||
return render(request, 'blog/post_edit.html', {'form': form})
|
||||
|
||||
|
||||
@login_required(login_url="/admin/login/?next=/blog/")
|
||||
def post_edit(request, pk):
|
||||
post = get_object_or_404(Post, pk=pk)
|
||||
if request.method == "POST":
|
||||
form = PostForm(request.POST, instance = post)
|
||||
if form.is_valid():
|
||||
post = form.save(commit=False)
|
||||
post.author = request.user
|
||||
#post.published_date = timezone.now()
|
||||
post.save()
|
||||
form.save_m2m()
|
||||
return redirect('blog.views.post_detail', pk=post.pk)
|
||||
else:
|
||||
form = PostForm(instance=post)
|
||||
return render(request, 'blog/post_edit.html', {'form': form})
|
Loading…
Reference in New Issue
Block a user