Don't remove Drafts in blog view
Add a check for robots directly using search form
This commit is contained in:
parent
7cb4f1d3d7
commit
10347ec588
|
@ -255,7 +255,15 @@ class Tag(models.Model):
|
||||||
if os.path.exists(output):
|
if os.path.exists(output):
|
||||||
shutil.rmtree(output)
|
shutil.rmtree(output)
|
||||||
|
|
||||||
|
class PostOnlyManager(models.Manager):
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return super(PostOnlyManager, self).get_queryset().filter(post_type='P')
|
||||||
|
|
||||||
class Post(models.Model):
|
class Post(models.Model):
|
||||||
|
|
||||||
|
objects = PostOnlyManager()
|
||||||
|
|
||||||
title = models.CharField(max_length=255)
|
title = models.CharField(max_length=255)
|
||||||
title_slug = models.CharField(max_length=255)
|
title_slug = models.CharField(max_length=255)
|
||||||
category = models.ForeignKey(Category, blank=True, null=True, on_delete=models.SET_NULL)
|
category = models.ForeignKey(Category, blank=True, null=True, on_delete=models.SET_NULL)
|
||||||
|
@ -274,6 +282,7 @@ class Post(models.Model):
|
||||||
(CONTENT_HTML, 'HTML'),
|
(CONTENT_HTML, 'HTML'),
|
||||||
(CONTENT_TEXT, 'Text'))
|
(CONTENT_TEXT, 'Text'))
|
||||||
content_format = models.IntegerField(choices=CONTENT_FORMAT, default=CONTENT_HTML, blank=False, null=False)
|
content_format = models.IntegerField(choices=CONTENT_FORMAT, default=CONTENT_HTML, blank=False, null=False)
|
||||||
|
post_type = models.CharField(max_length=1, default='P')
|
||||||
|
|
||||||
def getPath(self):
|
def getPath(self):
|
||||||
filename = '/post/'
|
filename = '/post/'
|
||||||
|
@ -386,6 +395,9 @@ class Post(models.Model):
|
||||||
return 'text'
|
return 'text'
|
||||||
|
|
||||||
class Draft(Post):
|
class Draft(Post):
|
||||||
|
|
||||||
|
objects = models.Manager()
|
||||||
|
|
||||||
def createDraft(self, content, tags):
|
def createDraft(self, content, tags):
|
||||||
b = self.blog
|
b = self.blog
|
||||||
output = b.src_path
|
output = b.src_path
|
||||||
|
@ -483,3 +495,7 @@ def pre_delete_post_signal(sender, **kwargs):
|
||||||
@receiver(pre_save, sender=Comment)
|
@receiver(pre_save, sender=Comment)
|
||||||
def pre_save_comment_signal(sender, **kwargs):
|
def pre_save_comment_signal(sender, **kwargs):
|
||||||
kwargs['instance']._update_line_returns()
|
kwargs['instance']._update_line_returns()
|
||||||
|
|
||||||
|
@receiver(pre_save, sender=Draft)
|
||||||
|
def pre_save_draft_signal(sender, **kwargs):
|
||||||
|
kwargs['instance'].post_type = 'D'
|
||||||
|
|
|
@ -22,7 +22,7 @@ import re
|
||||||
from datetime import datetime, date, time
|
from datetime import datetime, date, time
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.contrib.auth import authenticate, login, logout
|
from django.contrib.auth import authenticate, login, logout
|
||||||
from django.http import HttpResponseRedirect, HttpResponse, Http404
|
from django.http import HttpResponseRedirect, HttpResponse, Http404, HttpResponseForbidden
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.forms.models import inlineformset_factory
|
from django.forms.models import inlineformset_factory
|
||||||
|
@ -344,7 +344,7 @@ def add_blog(request):
|
||||||
def view_blog(request, blog_id):
|
def view_blog(request, blog_id):
|
||||||
b,_ = have_I_right(request, blog_id)
|
b,_ = have_I_right(request, blog_id)
|
||||||
|
|
||||||
orig_posts = Post.objects.filter(blog=b)
|
posts = Post.objects.filter(blog=b)
|
||||||
|
|
||||||
if 'page' in request.GET:
|
if 'page' in request.GET:
|
||||||
cur_page = int(request.GET['page'])
|
cur_page = int(request.GET['page'])
|
||||||
|
@ -356,7 +356,7 @@ def view_blog(request, blog_id):
|
||||||
else:
|
else:
|
||||||
drafts = []
|
drafts = []
|
||||||
|
|
||||||
count = len(orig_posts) - len(drafts)
|
count = len(posts) - len(drafts)
|
||||||
nb_pages = int(count/50)
|
nb_pages = int(count/50)
|
||||||
|
|
||||||
# Prevent error injection
|
# Prevent error injection
|
||||||
|
@ -368,14 +368,7 @@ def view_blog(request, blog_id):
|
||||||
start = cur_page * 50
|
start = cur_page * 50
|
||||||
end = start + 50 + len(drafts)
|
end = start + 50 + len(drafts)
|
||||||
|
|
||||||
orig_posts = orig_posts.order_by('-creation_date')[start:end]
|
posts = posts.order_by('-creation_date')[start:end]
|
||||||
|
|
||||||
# Select post without drafts
|
|
||||||
if drafts:
|
|
||||||
drafts_id = [draft.id for draft in drafts]
|
|
||||||
posts = [p for p in orig_posts if not p.id in drafts_id]
|
|
||||||
else:
|
|
||||||
posts = orig_posts
|
|
||||||
|
|
||||||
form = BlogForm(instance=b)
|
form = BlogForm(instance=b)
|
||||||
|
|
||||||
|
@ -677,6 +670,9 @@ def generate_search(request, blog_id):
|
||||||
def search(request, blog_id):
|
def search(request, blog_id):
|
||||||
from dynastie.generators import search
|
from dynastie.generators import search
|
||||||
|
|
||||||
|
if not 'HTTP_REFERER' in request.META:
|
||||||
|
return HttpResponseForbidden()
|
||||||
|
|
||||||
ref = request.META['HTTP_REFERER']
|
ref = request.META['HTTP_REFERER']
|
||||||
|
|
||||||
b = Blog.objects.filter(pk=blog_id)
|
b = Blog.objects.filter(pk=blog_id)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user