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 108 114 116 117 122 124 127 130 134 136 139 142 144 145 147 148 149 150 154 158 161 163 165 167 168 170 172 173 178 184 186 188 189 191 192 196 197 199 200 201 206 207 209 210 216 218 222 224 225 226 227 228 231 233 235 236 237 238 239 240 241 242 243 245 246 247 248 252 256 257 261 265 267 268 269 270 271 272 273 274 275 277 278 279 280 281 282 283 284 286 288 290 291 292 293 294 295 296 299 301 303 304 305 306 307 308 309 311 312 314 315 316 317 318 319 320 321 322 323 324 325 327 328 329 330 331 334 338 339 340 343 345 347 348 349 350 351 358 360 361 362 363 365 367 368 369 370 371 376 378 379 380 381 382 383 384 385 387 389 391 396 397 398 399 402 403 404 405 407 408 409 410 414 416 418 420 425 427 428 429 431 433 438 440 443 445 446 |
"""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)
"""Make sure the default page ordering is correct."""
"""Instanciate the page object.""" # per instance cache
"""Override the default ``save`` method.""" # Published pages should always have a publication date # Drafts should not, unless they have been set to the future self.publication_date <= datetime.now()): 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 ``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())
|