Revision 373164666138 () - Diff

Link to this snippet: https://friendpaste.com/7QtUTWQIPK1wOip3EAIyqc
Embed:
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
home.html

{% extends "layout/base2.html" %}
{% load generic_content %}
{% load blog_extras %}




{% block cont_actu %}
{% get_latest_objects blog.entry 5 as latest_entry %}
{% display_last_entry %}



{% endblock cont_actu %}

blog_extras.py

# -*- coding: utf-8 -*-
from django import template
from django.template import Library, Node, TemplateSyntaxError
from django.conf import settings
from monsite.blog.models import Tag,Entry




register = template.Library()


@register.inclusion_tag('blog/tag_list.html')
def show_alltags():
allmytags = Tag.objects.order_by('name')
return {'alltags': allmytags}

@register.inclusion_tag('blog/archive_by_year.html')
def archive_by_year():
year_list = Entry.objects.dates('pub_date','year', order='ASC')
return {'year_list': year_list}

@register.inclusion_tag('blog/archive_by_month.html')
def archive_by_month():
month_list = Entry.objects.dates('pub_date','month', order='ASC')
return {'month_list': month_list}


def display_last_entry(context):
"""
Display latest posts, ``latest_posts`` var should be in the context.

Usage::

{% get_latest_objects journal.Post 5 as latest_posts %}
{% display_footer_posts %}

This will use ``display_footer_posts.html`` template.
"""
return { 'latest_entry': context['latest_entry'] }



register.inclusion_tag('blog/display_last_entry.html', takes_context=True)(display_last_entry)

display_last_entry.html

<h3>Derniers billets publiés</h3>
<ul>
{% for entry in latest_posts %}
<li><a href="{{ entry.get_absolute_url }}" title="Lire le billet intitulé {{ entry.title }}">{{ entry|safe }}</a></li>
{% endfor %}
</ul>