1 6 9 15 17 19 22 24 29 31 34 37 39 41 42 45 46 47 49 50 51 52 53 54 57 58 59 60 61 62 63 64 65 66 67 68 70 71 72 73 74 75 86 87 89 90 91 92 93 94 95 106 107 109 110 111 112 113 114 120 121 125 128 129 131 134 136 137 138 139 140 141 142 144 148 151 152 153 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 175 177 178 180 181 182 183 184 185 186 187 188 190 191 192 194 195 196 197 198 199 200 201 202 203 204 205 206 207 216 218 219 221 222 224 226 229 231 232 234 235 236 237 238 239 240 241 242 243 250 251 252 253 254 257 258 259 260 262 263 264 265 266 267 268 269 270 279 280 281 282 283 284 285 287 289 291 294 295 296 298 302 307 308 310 311 312 313 314 315 316 317 318 321 323 324 329 330 332 340 341 342 343 344 346 347 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 370 372 373 382 383 385 393 395 396 397 398 399 400 401 402 403 404 405 406 409 410 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 430 431 433 434 435 439 441 442 443 447 449 450 451 452 453 454 455 456 457 460 462 464 466 467 469 472 |
# -*- coding: utf-8 -*- #from django.forms import Widget, Textarea, ImageField, CharField
"""Return a Page object from a slug or an id.""" # if we have a string coming from some templates templates isinstance(page_string, unicode)):
"""Helper function used by ``PlaceholderNode``."""
return ''
"""Filters"""
"""Fitler that return ``True`` if the page has any content in a particular language.
:param page: the current page :param language: the language you want to look at """
'''def has_permission(page, request): """Tell if a user has permissions on the page.
:param page: the current page :param request: the request object where the user is extracted """ return page.has_page_permission(request) register.filter(has_permission)'''
"""Inclusion tags"""
"""Render a nested list of all the descendents of the given page, including this page.
:param page: the page where to start the menu from. :param url: not used anymore. """ takes_context=True)(pages_menu)
"""Get the root page of the given page and render a nested list of all root's children pages. Good for rendering a secondary menu.
:param page: the page where to start the menu from. :param url: not used anymore. """ takes_context=True)(pages_sub_menu)
"""Get the parent page of the given page and render a nested list of its child pages. Good for rendering a secondary menu.
:param page: the page where to start the menu from. :param url: not used anymore. """ root = page.parent else: current_page = context['current_page'] takes_context=True)(pages_siblings_menu)
"""Render the admin table of pages."""
cookie_string = urllib.unquote(request.COOKIES['tree_expanded']) if cookie_string: ids = [int(id) for id in urllib.unquote(request.COOKIES['tree_expanded']).split(',')] if page.id in ids: expanded = True
#has_permission = page.has_page_permission(request)
takes_context=True)(pages_admin_menu)
"""Display a content type from a page.
Example::
{% show_content page_object "title" %}
You can also use the slug of a page::
{% show_content "my-page-slug" "title" %}
Or even the id of a page::
{% show_content 10 "title" %}
:param page: the page object, slug or id :param content_type: content_type used by a placeholder :param lang: the wanted language (default None, use the request object to know) :param fallback: use fallback content from other language """ fallback)} takes_context=True)(show_content)
"""Display slug with level by language.""" if not lang: lang = context.get('lang', pages_settings.PAGE_DEFAULT_LANGUAGE)
page = get_page_from_string_or_id(page, lang) if not page: return ''
return {'content': page.slug_with_level(lang)} takes_context=True)(show_slug_with_level)
"""Show the url of a page in the right language
Example ::
{% show_absolute_url page_object %}
You can also use the slug of a page::
{% show_absolute_url "my-page-slug" %}
Keyword arguments: :param page: the page object, slug or id :param lang: the wanted language (defaults to `settings.PAGE_DEFAULT_LANGUAGE`) """ return {'content':''} takes_context=True)(show_absolute_url)
"""Render the last 10 revisions of a page content with a list using the ``pages/revisions.html`` template""" return {'revisions':None} type=content_type).order_by('-creation_date') return {'revisions':revisions[0:10]} takes_context=True)(show_revisions)
""" Render a "dynamic" tree menu, with all nodes expanded which are either ancestors or the current page itself.
Override ``pages/dynamic_tree_menu.html`` if you want to change the design.
:param page: the current page :param url: not used anymore """ current_page = context['current_page'] # if this node is expanded, we also have to render its children # a node is expanded if it is the current node or one of its ancestors if page.lft <= current_page.lft and page.rght >= current_page.rght: children = page.get_children_for_frontend() 'pages/dynamic_tree_menu.html', takes_context=True )(pages_dynamic_tree_menu)
""" Render a breadcrumb like menu.
Override ``pages/breadcrumb.html`` if you want to change the design.
:param page: the current page :param url: not used anymore """ 'pages/breadcrumb.html', takes_context=True )(pages_breadcrumb)
"""Tags"""
"""Fake CSRF node for django 1.1.1""" return '' return FakeCSRFNode() except ImportError: do_csrf_token = register.tag('csrf_token', do_csrf_token)
"""get_page Node"""
"""Retrieve a page and insert into the template's context.
Example::
{% get_page "news" as news_page %}
:param page: the page object, slug or id :param name: name of the context variable to store the page in """ raise TemplateSyntaxError('%r expects 4 arguments' % bits[0]) raise TemplateSyntaxError( '%r expects "as" as the second argument' % bits[0])
"""Get content node""" context, self.page.resolve(context), self.content_type.resolve(context), self.lang )
"""Retrieve a Content object and insert it into the template's context.
Example::
{% get_content page_object "title" as content %}
You can also use the slug of a page::
{% get_content "my-page-slug" "title" as content %}
Syntax::
{% get_content page type [lang] as name %}
:param page: the page object, slug or id :param type: content_type used by a placeholder :param name: name of the context variable to store the content in :param lang: the wanted language """ raise TemplateSyntaxError('%r expects 4 or 5 arguments' % bits[0]) raise TemplateSyntaxError( '%r expects "as" as the second last argument' % bits[0])
"""Load page node."""
"""Load the navigation pages, lang, and current_page variables into the current context.
Example::
<ul> {% load_pages %} {% for page in pages_navigation %} {% pages_menu page %} {% endfor %} </ul> """
""" Method that parse the placeholder template tag.
Syntax::
{% placeholder <name> [on <page>] [with <widget>] \ [parsed] [as <varname>] %}
Example usage::
{% placeholder about %} {% placeholder body with TextArea as body_text %} {% placeholder welcome with TextArea parsed as welcome_text %} {% placeholder teaser on next_page with TextArea parsed %} """
""" Method that parse the imageplaceholder template tag. """
""" Method that parse the imageplaceholder template tag. """
"""Tell if all the page content has been updated since the last change of the official version (settings.LANGUAGE_CODE)
This is approximated by comparing the last modified date of any content in the page, not comparing each content block to its corresponding official language version. That allows users to easily make "do nothing" changes to any content block when no change is required for a language. """ # official version is always "up to date" # get the last modified date for the official version page=page).order_by('-creation_date') # no official version return True page=page).order_by('-creation_date')[0].creation_date
|