root/trunk/pylucid_project/PyLucid/plugins_internal/back_links/back_links.py

Revision 1634, 2.7 kB (checked in by JensDiemer, 6 months ago)

Update Meta Informations:

  • file encoding
  • shebang
  • copyleft and license line
  • svn:keywords
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Rev LastChangedDate
Line 
1# -*- coding: utf-8 -*-
2
3"""
4    PyLucid back links Plugin
5    ~~~~~~~~~~~~~~~~~~~~~~~~~
6
7    Generates a horizontal backlink bar.
8    Adjastuble with the following Parameters
9
10    - print_last_page = False (default)
11        if print_last_page has the value True, then the actual page will be the
12        last page in the bar. Otherwise the parentpage.
13
14    - print_index = False (default)
15        display a link to the index ("/") if = True
16
17
18    - index = "Index" (default)
19        the name that is printed for the indexpage
20
21
22    Last commit info:
23    ~~~~~~~~~
24    $LastChangedDate$
25    $Rev$
26    $Author$
27
28    :created: 29.11.2005 10:14:02 by Jens Diemer
29    :copyleft: 2005-2008 by the PyLucid team, see AUTHORS for more details.
30    :license: GNU GPL v2 or above, see LICENSE for more details
31"""
32
33__version__= "$Rev$"
34
35
36from django.utils.safestring import mark_safe
37
38from PyLucid.system.BasePlugin import PyLucidBasePlugin
39from PyLucid.models import Page, Plugin
40
41class back_links(PyLucidBasePlugin):
42
43    def lucidTag(self, **kwargs):
44        """
45        generate the backlinks
46        TODO: **kwargs only for Backwards-incompatible changes info
47        """
48        if self.request.debug == True and kwargs != {}:
49            self.page_msg(
50                "DeprecationWarning:"
51                " kwargs in back_links plugin are obsolete. Please remove them."
52            )
53            return
54
55        # Get the preferences from the database:
56        preferences = self.get_preferences()
57        if preferences == None:
58            # preferences not in database -> reinit required
59            if self.request.debug == True:
60                msg = (
61                    '<a href="http://www.pylucid.org/_goto/121/changes/#23-05-2008-back_links">'
62                    'reinit "back_links" plugin required!</a>'
63                )
64                self.page_msg.red(mark_safe(msg))
65                return
66
67        current_page = self.context["PAGE"]
68        if preferences["print_last_page"] == True:
69            print_page = current_page
70        else:
71            print_page = current_page.parent
72            if not print_page:
73                # There exist no higher-ranking page
74                return ""
75
76        data = self._backlink_data(print_page)
77        data.reverse()
78
79        context = {
80            "pages": data,
81            "preferences": preferences,
82        }
83        self._render_template("back_links", context)#, debug=True)
84
85    def _backlink_data(self, parent_page):
86        """
87        make a list of all pages in the current way back to the index page.
88        """
89        data = []
90        while parent_page:
91            page_id = parent_page.id
92            page = Page.objects.get(id=page_id)
93            parent_page = page.parent
94
95            data.append(page)
96
97        return data
Note: See TracBrowser for help on using the browser.