david / biologeek (http://biologeek.com/)
Source code of biologeek.com weblog under WTFPL.
Clone this repository (size: 252.8 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/david/biologeek/
| commit 87: | a0821d39bfd4 |
| parent 86: | ffbed20c95a1 |
| branch: | default |
| tags: | tip |
Add a custom setting for extending the comments' timestamp (antispam)
| r87:a0821d39bfd4 | 104 loc | 4.3 KB | embed / history / annotate / raw / |
|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | # -*- coding: utf-8 -*-
from datetime import datetime
from django.db import models
from django.conf import settings
from django.contrib.comments.models import Comment
from django.contrib.markup.templatetags.markup import markdown
from tagging.models import Tag
from tagging.fields import TagField
from biologeek.utils import flush_cache_url
MARKDOWN_SYNTAX = 'Syntaxe <a href="http://daringfireball.net/projects/markdown/syntax/"'\
'title="Accès à la syntaxe">markdown</a>'
class PostManager(models.Manager):
def get_query_set(self):
""" Retrieve only published posts. """
qs = super(PostManager, self).get_query_set()
return qs.filter(is_online=True, publication_date__lte=datetime.now())
def get_best_of(self):
""" Retrieve only best of published posts. """
qs = super(PostManager, self).get_query_set()
return qs.filter(is_online=True, is_bestof=True, publication_date__lte=datetime.now())
class Post(models.Model):
title = models.CharField('Titre', max_length=200)
slug = models.SlugField('Adresse', max_length=200, unique=True)
tags = TagField(help_text='Écrivez vos tags, séparés par des espaces ou des virgules.')
summary = models.TextField('Description', help_text=MARKDOWN_SYNTAX, blank=True)
summary_html = models.TextField('Description HTML', blank=True)
content = models.TextField('Contenu', help_text=MARKDOWN_SYNTAX)
content_html = models.TextField('Contenu HTML', blank=True)
related_posts = models.ManyToManyField('self', help_text='Sélectionnez les billets en relation.', blank=True)
related = models.TextField('Contenu additionnel', help_text=MARKDOWN_SYNTAX, blank=True)
related_html = models.TextField('Contenu additionnel HTML', blank=True)
creation_date = models.DateTimeField('Date de création', null=True, blank=True)
modification_date = models.DateTimeField('Date de modification', null=True, blank=True)
publication_date = models.DateTimeField('Date de publication', null=True, blank=True)
image = models.ImageField('Image associée', upload_to='images/logos/', blank=True)
is_online = models.BooleanField('En ligne', default=False)
is_bestof = models.BooleanField('Best of', default=False)
nb_comments = models.IntegerField(null=True, blank=True, default=0, editable=False)
class Admin:
list_display = ('title', 'thumbnail', 'summary', 'is_online', 'creation_date', 'nb_comments')
list_filter = ('modification_date', 'is_online')
search_fields = ('title', 'content', 'summary')
date_hierarchy = 'publication_date'
class Meta:
ordering = ['-publication_date']
def __unicode__(self):
return self.is_bestof and u'★ %s' % self.title or self.title
def get_absolute_url(self):
tags = self.tags.split()
tags.sort()
return "/%s/%s/" % (','.join([tag for tag in tags]), self.slug)
# Django do not handle nested parenthesis in urls yet, see #2977 and #6934
# return ('post', [tags, self.slug])
#get_absolute_url = permalink(get_absolute_url)
def get_complete_url(self):
return 'http://www.biologeek.com%s' % self.get_absolute_url()
def get_data_url(self):
return 'http://www.biologeek.com/data%s' % self.get_absolute_url()
def save(self):
if not self.id:
self.creation_date = datetime.now()
self.modification_date = datetime.now()
if not self.publication_date:
self.publication_date = self.modification_date
self.summary_html = markdown(self.summary)
self.content_html = markdown(self.content)
self.related_html = markdown(self.related)
super(Post, self).save()
if self.is_online:
flush_cache_url(self.get_absolute_url())
flush_cache_url('/journal/')
def compute_nb_comments(self):
"""Useful method to sync the number of comment."""
self.nb_comments = Comment.objects.for_model(self)\
.filter(object_pk=self.id,
is_public=True,
is_removed=False)\
.count()
self.save()
objects = models.Manager()
published = PostManager()
|
