| commit 10: | 70991e198807 |
| parent 9: | 397454a46d63 |
| branch: | default |
Support du format Markdown et possibilité d'insérer une image pour illustrer un billet.
17 months ago
Changed (Δ769 bytes):
raw changeset »
blog/admin.py (1 lines added, 1 lines removed)
blog/models.py (13 lines added, 2 lines removed)
templates/base.html (1 lines added, 0 lines removed)
templates/blog/entry_detail.html (1 lines added, 0 lines removed)
views.py (0 lines added, 1 lines removed)
Up to file-list blog/admin.py:
| … | … | @@ -11,7 +11,7 @@ class EntryAdmin(admin.ModelAdmin): |
11 |
11 |
prepopulated_fields = { |
12 |
12 |
'slug': ('title',) |
13 |
13 |
} |
14 |
search_fields = ['title', 'summary', 'body |
|
14 |
search_fields = ['title', 'summary', 'body_markdown', 'body'] |
|
15 |
15 |
filter_horizontal = ['tags'] |
16 |
16 |
|
17 |
17 |
admin.site.register(Tag, TagAdmin) |
Up to file-list blog/models.py:
1 |
1 |
# -*- coding: UTF-8 -*- |
2 |
2 |
from django.db import models |
3 |
3 |
|
4 |
MARKDOWN_SYNTAX = 'Syntaxe <a target="_blank" href="http://daringfireball.net/projects/markdown/syntax/"'\ |
|
5 |
'title="Accès à la syntaxe">markdown</a>' |
|
6 |
||
4 |
7 |
class Tag(models.Model): |
5 |
8 |
name = models.CharField('Nom',max_length=50) |
6 |
9 |
slug = models.SlugField('Référence') |
| … | … | @@ -20,7 +23,9 @@ class Entry(models.Model): |
20 |
23 |
help_text='Automatiquement formé à partir du titre.' |
21 |
24 |
) |
22 |
25 |
summary = models.TextField('Résumé',help_text="Un seul paragraphe. N'ajoutez pas de balise <p>.") |
23 |
|
|
26 |
image = models.ImageField('Image associée', upload_to='images/', blank=True, null=True) |
|
27 |
body_markdown = models.TextField('Contenu Markdown', help_text=MARKDOWN_SYNTAX, blank=True, null=True) |
|
28 |
body = models.TextField('Contenu HTML', help_text='Utilisez la syntaxe HTML.', blank=True, null=True) |
|
24 |
29 |
pub_date = models.DateTimeField('Date de publication') |
25 |
30 |
tags = models.ManyToManyField(Tag) |
26 |
31 |
|
| … | … | @@ -33,4 +38,10 @@ class Entry(models.Model): |
33 |
38 |
|
34 |
39 |
def get_absolute_url(self): |
35 |
40 |
return "/blog/%s/%s/" % (self.pub_date.strftime("%Y/%m/%d").lower(), self.slug) |
36 |
||
41 |
||
42 |
def save(self): |
|
43 |
"""Traduction à l'enregistrement du contenu Markdown en HTML""" |
|
44 |
import markdown |
|
45 |
if self.body_markdown != "": |
|
46 |
self.body = markdown.markdown(self.body_markdown) |
|
47 |
super(Entry, self).save() # Call the "real" save() method. |
Up to file-list templates/base.html:
1 |
1 |
{% load blog_extras %} |
2 |
||
2 |
3 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
3 |
4 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> |
4 |
5 |
<head> |
Up to file-list templates/blog/entry_detail.html:
12 |
12 |
Posté le {{ object.pub_date|date:"j F Y" }} |
13 |
13 |
</div> |
14 |
14 |
|
15 |
<img class="illustration" src="{{ MEDIA_URL }}{{ object.image.url }}"/> |
|
15 |
16 |
{{ object.body|safe }} |
16 |
17 |
|
17 |
18 |
<dl class="informations"> |
2 |
2 |
from django.shortcuts import render_to_response |
3 |
3 |
from django.http import Http404, HttpResponse, HttpResponseRedirect |
4 |
4 |
from django.contrib.auth.decorators import login_required |
5 |
from django.views.generic.list_detail import object_list |
|
6 |
5 |
|
7 |
6 |
def show_gallery(request): |
8 |
7 |
"""Affiche la liste des albums photo apres authentification.""" |
