1 10 12 15 17 19 20 21 22 25 26 27 30 31 36 38 39 40 42 44 45 48 49 52 53 55 59 65 68 71 72 75 79 80 83 85 86 87 88 90 91 96 97 98 99 100 101 102 103 104 105 106 107 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 131 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# -*- coding: utf-8 -*-
"""return a mockup dictionnary to use in get_placeholders.""" context.update(settings.PAGE_EXTRA_CONTEXT())
"""Return a list of PlaceholderNode found in the given template.
:param template_name: the name of the template file """ except TemplateDoesNotExist: return []
# I need to render the template in order to extract # placeholder tags
"""Recursively search into a template node list for PlaceholderNode node.""" # I needed to import make this lazy import to make the doc compile
# extends node plist, blist) # include node
# It's a placeholder hasattr(node, 'as_varname') and hasattr(node, 'name'): already_in_plist = True
# delete placeholders found in a block of the same name pl.found_in_block.name == node.name \ and pl.found_in_block != node:
except: pass
"""Return true if the current user has permission to add a new page.
:param page: not used """ return True else: # the user has the right to add a page under a page he control target = request.GET.get('target', None) if target is not None: try: target = int(target) if target in permission: return True except: pass return False
"""Return a normalized url with trailing and without leading slash.
>>> normalize_url(None) '/' >>> normalize_url('/') '/' >>> normalize_url('/foo/bar') '/foo/bar' >>> normalize_url('foo/bar') '/foo/bar' >>> normalize_url('/foo/bar/') '/foo/bar' """ if not url or len(url)==0: return '/' if not url.startswith('/'): url = '/' + url if len(url)>1 and url.endswith('/'): url = url[0:len(url)-1] return url
"""Transform the HTML link href to point to the targeted page absolute URL.
>>> filter_link('<a class="page_1">hello</a>', page, 'en-us', body) '<a href="/pages/page-1" class="page_1">hello</a>' """ if not settings.PAGE_LINK_FILTER: return content if content_type in ('title', 'slug'): return content from BeautifulSoup import BeautifulSoup tree = BeautifulSoup(content) tags = tree.findAll('a') if len(tags) == 0: return content for tag in tags: tag_class = tag.get('class', False) if tag_class: # find page link with class 'page_ID' result = PAGE_CLASS_ID_REGEX.search(content) if result and result.group: try: # TODO: try the cache before fetching the Page object from pages.models import Page target_page = Page.objects.get(pk=int(result.group(1))) tag['href'] = target_page.get_url_path(language) except Page.DoesNotExist: cache.set(Page.PAGE_BROKEN_LINK_KEY % page.id, True) tag['class'] = 'pagelink_broken' return unicode(tree) |