Dynastie

Dynastie Commit Details

Date:2020-03-20 16:56:02 (4 months 14 days ago)
Author:Grégory Soutadé
Branch:master
Commit:10347ec588d857e4a3f2f267822bf29ce26b7280
Parents: 7cb4f1d3d7504b6e45a2f3179f40c8b38cbcbf55
Message:Don't remove Drafts in blog view Add a check for robots directly using search form

Changes:
Mdynastie/models.py (4 diffs)
Mdynastie/views.py (5 diffs)

File differences

dynastie/models.py
255255
256256
257257
258
259
260
261
262
258263
264
265
266
259267
260268
261269
......
274282
275283
276284
285
277286
278287
279288
......
386395
387396
388397
398
399
400
389401
390402
391403
......
483495
484496
485497
498
499
500
501
if os.path.exists(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):
objects = PostOnlyManager()
title = 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)
(CONTENT_HTML, 'HTML'),
(CONTENT_TEXT, 'Text'))
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):
filename = '/post/'
return 'text'
class Draft(Post):
objects = models.Manager()
def createDraft(self, content, tags):
b = self.blog
output = b.src_path
@receiver(pre_save, sender=Comment)
def pre_save_comment_signal(sender, **kwargs):
kwargs['instance']._update_line_returns()
@receiver(pre_save, sender=Draft)
def pre_save_draft_signal(sender, **kwargs):
kwargs['instance'].post_type = 'D'
dynastie/views.py
2222
2323
2424
25
25
2626
2727
2828
......
344344
345345
346346
347
347
348348
349349
350350
......
356356
357357
358358
359
359
360360
361361
362362
......
368368
369369
370370
371
371
372372
373
374
375
376
377
378
379
380373
381374
382375
......
677670
678671
679672
673
674
675
680676
681677
682678
from datetime import datetime, date, time
from django.shortcuts import render
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.views.decorators.csrf import csrf_exempt
from django.forms.models import inlineformset_factory
def view_blog(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:
cur_page = int(request.GET['page'])
else:
drafts = []
count = len(orig_posts) - len(drafts)
count = len(posts) - len(drafts)
nb_pages = int(count/50)
# Prevent error injection
start = cur_page * 50
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)
comments = Comment.objects.all()
def search(request, blog_id):
from dynastie.generators import search
if not 'HTTP_REFERER' in request.META:
return HttpResponseForbidden()
ref = request.META['HTTP_REFERER']
b = Blog.objects.filter(pk=blog_id)

Archive Download the corresponding diff file

Branches

Tags