1 2 7 16 18 20 21 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 55 56 57 58 59 63 65 67 69 71 72 74 75 76 78 81 82 84 85 87 88 89 92 93 94 96 98 99 100 102 104 105 106 107 111 113 119 121 124 127 130 131 132 133 136 139 141 142 144 145 146 147 151 155 158 160 162 164 165 167 169 170 175 181 183 185 186 188 189 193 194 196 197 198 203 204 206 207 213 215 219 221 222 223 224 225 228 230 232 233 234 235 236 237 238 239 240 242 243 244 245 249 253 254 258 262 264 265 266 267 268 269 270 271 272 274 275 276 277 278 279 280 281 283 285 287 288 289 290 291 292 293 296 298 300 301 302 303 304 305 306 308 309 311 312 313 314 315 316 317 318 319 320 321 322 324 325 326 327 328 331 335 336 337 340 342 344 345 346 347 348 353 355 357 358 359 360 362 364 365 366 367 368 373 375 376 377 378 379 380 381 382 384 386 388 393 394 395 396 399 400 401 402 404 405 406 407 411 413 415 417 422 424 425 426 428 430 435 437 440 442 443 |
"""Django page CMS ``models``."""
""" This model contain the status, dates, author, template. The real content of the page can be found in the :class:`Content <pages.models.Content>` model.
.. attribute:: creation_date When the page has been created.
.. attribute:: publication_date When the page should be visible.
.. attribute:: publication_end_date When the publication of this page end.
.. attribute:: last_modification_date Last time this page has been modified.
.. attribute:: status The current status of the page. Could be DRAFT, PUBLISHED, EXPIRED or HIDDEN. You should the property :attr:`calculated_status` if you want that the dates are taken in account.
.. attribute:: template A string containing the name of the template file for this page. """
# some class constants to refer to, e.g. Page.DRAFT (PUBLISHED, _('Published')), (HIDDEN, _('Hidden')), (DRAFT, _('Draft')), )
related_name='children', verbose_name=_('parent')) default=datetime.now) null=True, blank=True, help_text=_('''When the page should go live. Status must be "Published" for page to go live.''')) null=True, blank=True, help_text=_('''When to expire the page. Leave empty to never expire.'''))
blank=True)
blank=True)
null=True, blank=True, help_text=_('''Don't publish any content after this date.'''))
help_text=_('The site(s) the page is accessible at.'), verbose_name=_('sites'))
related_name='redirected_pages')
# Managers
from tagging import fields tags = fields.TagField(null=True)
# per instance cache
"""Make sure the default page ordering is correct."""
"""Override the default ``save`` method.""" # Published pages should always have a publication date # Drafts should not, unless they have been set to the future if (self.publication_date and self.publication_date <= datetime.now()): self.publication_date = None else: # let's assume there is no more broken links after a save # fix sites many-to-many link when the're hidden from the form self.sites.add(Site.objects.get(pk=settings.SITE_ID))
"""Get the calculated status of the page based on :attr:`Page.publication_date`, :attr:`Page.publication_end_date`, and :attr:`Page.status`."""
"""Return a :class:`QuerySet` of published children page"""
"""Return a :class:`QuerySet` of published children page ordered by publication date."""
"""Invalidate cached data for this page."""
# delete content cache, frozen or not # frozen (self.id, name, 1)) # not frozen (self.id, name, 0))
""" Return a list of all used languages for this page. """ return self._languages
c in Content.objects.filter(page=self, type="slug").values('language')]
"""Return ``True`` if the page is the first root page."""
"""Return the URL's path component. Add the language prefix if ``PAGE_USE_LANGUAGE_PREFIX`` setting is set to ``True``.
:param language: the wanted url language. """ url += str(language) + '/'
"""Alias for `get_url_path`.
This method is only there for backward compatibility and will be removed in a near futur.
:param language: the wanted url language. """ return self.get_url_path(language=language)
"""Return the complete slug of this page by concatenating all parent's slugs.
:param language: the wanted slug language.""" (self.id, language)) url = '' else:
"""Alias for `get_complete_slug`.
This method is only there for backward compatibility and will be removed in a near futur.
:param language: the wanted url language. """ return self.get_complete_slug(language=language)
""" Return the slug of the page depending on the given language.
:param language: wanted language, if not defined default is used. :param fallback: if ``True``, the slug will also be searched in other \ languages. """
""" Return the title of the page depending on the given language.
:param language: wanted language, if not defined default is used. :param fallback: if ``True``, the slug will also be searched in \ other languages. """
"""Shortcut method for retrieving a piece of page content
:param language: wanted language, if not defined default is used. :param ctype: the type of content. :param fallback: if ``True``, the content will also be searched in \ other languages. """ language_fallback)
"""Return all the current content of this page into a `string`.
This is used by the haystack framework to build the search index.""" placeholders = get_placeholders(self.get_template()) exposed_content = [] for lang in self.get_languages(): for p_name in [p.name for p in placeholders]: content = self.get_content(lang, p_name, False) if content: exposed_content.append(content) return u"\r\n".join(exposed_content)
""" Get the :attr:`template <Page.template>` of this page if defined or the closer parent's one if defined or :attr:`pages.settings.PAGE_DEFAULT_TEMPLATE` otherwise. """
template = p.template break
""" Get the template name of this page if defined or if a closer parent has a defined template or :data:`pages.settings.PAGE_DEFAULT_TEMPLATE otherwise. """ return t[1]
""" Return ``True`` if the page have broken links to other pages into the content. """
"""Return a :class:`QuerySet` of valid targets for moving a page into the tree.
:param perms: the level of permission of the concerned user. """
"""Display the slug of the page prepended with insecable spaces equal to the level of page in the hierarchy.""" level = '' if self.level: for n in range(0, self.level): level += ' ' return mark_safe(level + self.slug(language))
"""Used in the admin menu to create the left margin."""
"""Representation of the page, saved or not.""" return "Page %d" % self.id return "Page without id"
# Don't register the Page model twice. except mptt.AlreadyRegistered: pass
"""A block of content, tied to a :class:`Page <pages.models.Page>`, for a particular language"""
# languages could have five characters : Brazilian Portuguese is pt-br db_index=True)
default=datetime.now)
return "%s :: %s" % (self.page.slug(), self.body[0:15])
"""URL alias for a :class:`Page <pages.models.Page>`""" verbose_name=_('page'))
# normalize url
return "%s => %s" % (self.url, self.page.get_complete_slug())
|