class Page( AbstractPage, AppsMixin, # For adding the articles app to pages through the CMS. TemplateMixin, # Two page templates, one with only a main # region and another with a sidebar as well. MenuMixin, # We have a main and a footer navigation (meta). LanguageMixin, # We're building a multilingual CMS. (Also, # feincms3.apps depends on LanguageMixin # currently.) RedirectMixin, # Allow redirecting pages to other pages and/or arbitrary # URLs. ): # TemplateMixin TEMPLATES = [ Template( key="standard", title=_("standard"), template_name="pages/standard.html", regions=(Region(key="main", title=_("Main")), ), ), Template( key="with-sidebar", title=_("with sidebar"), template_name="pages/with-sidebar.html", regions=( Region(key="main", title=_("Main")), Region(key="sidebar", title=_("Sidebar")), ), ), ] # MenuMixin MENUS = [("main", _("main")), ("footer", _("footer"))] # AppsMixin. We have two apps, one is for company PR, the other # for a more informal blog. # # NOTE! The app names (first element in the tuple) have to match the # article categories exactly for URL reversing and filtering articles by # app to work! (See app.articles.models.Article.CATEGORIES) APPLICATIONS = [ ("publications", _("publications"), { "urlconf": "testapp.articles_urls" }), ("blog", _("blog"), { "urlconf": "testapp.articles_urls" }), ( "stuff-with-required", "stuff-with-required", { "urlconf": "stuff-with-required", "required_fields": ("optional", "not_editable"), }, ), ] optional = models.IntegerField(blank=True, null=True) not_editable = models.IntegerField(blank=True, null=True, editable=False)
class Page( AbstractPage, AppsMixin, # For adding the articles app to pages through the CMS. TemplateMixin, # Two page templates, one with only a main # region and another with a sidebar as well. MenuMixin, # We have a main and a footer navigation (meta). LanguageMixin, # We're building a multilingual CMS. (Also, # feincms3.apps depends on LanguageMixin # currently.) RedirectMixin, # Allow redirecting pages to other pages and/or arbitrary # URLs. ): # TemplateMixin TEMPLATES = [ Template( key='standard', title=_('standard'), template_name='pages/standard.html', regions=( Region(key='main', title=_('Main')), ), ), Template( key='with-sidebar', title=_('with sidebar'), template_name='pages/with-sidebar.html', regions=( Region(key='main', title=_('Main')), Region(key='sidebar', title=_('Sidebar')), ), ), ] # MenuMixin MENUS = [ ('main', _('main')), ('footer', _('footer')), ] # AppsMixin. We have two apps, one is for company PR, the other # for a more informal blog. # # NOTE! The app names (first element in the tuple) have to match the # article categories exactly for URL reversing and filtering articles by # app to work! (See app.articles.models.Article.CATEGORIES) APPLICATIONS = [ ('publications', _('publications'), { 'urlconf': 'testapp.articles_urls', }), ('blog', _('blog'), { 'urlconf': 'testapp.articles_urls', }), ] objects = PageManager()
class Page(models.Model): title = models.CharField(max_length=200) parent = models.ForeignKey("self", related_name="children", blank=True, null=True, on_delete=models.CASCADE) template = Template( key="test", regions=[ Region(key="main", title="main region"), Region(key="sidebar", title="sidebar region", inherited=True), ], ) class Meta: verbose_name = "page" verbose_name_plural = "pages" def get_absolute_url(self): return reverse("page_detail", kwargs={"pk": self.pk}) @property def regions(self): return self.template.regions
class Page(MPTTModel): title = models.CharField(max_length=200) parent = models.ForeignKey('self', related_name='children', blank=True, null=True, on_delete=models.CASCADE) template = Template( key='test', regions=[ Region(key='main', title='main region'), Region(key='sidebar', title='sidebar region', inherited=True), ], ) class Meta: verbose_name = 'page' verbose_name_plural = 'pages' def get_absolute_url(self): return reverse('page_detail', kwargs={'pk': self.pk}) @property def regions(self): return self.template.regions
def get_template_list(app_name, templates): return [ Template( key=template[0], title=_(template[0]).title(), template_name=f"{app_name}/{template[0]}.html", regions=[ Region(key=region, title=region.title(), inherited=True) for region in template[1] ] ) for template in templates ]
class Page( AbstractPage, AppsMixin, # For adding the articles app to pages through the CMS. TemplateMixin, # Two page templates, one with only a main # region and another with a sidebar as well. MenuMixin, # We have a main and a footer navigation (meta). LanguageMixin, # We're building a multilingual CMS. (Also, # feincms3.apps depends on LanguageMixin # currently.) ): # TemplateMixin TEMPLATES = [ Template( key='standard', title=_('standard'), template_name='pages/standard.html', regions=( Region(key='main', title=_('Main'), content='contents.main'), Region(key='footer', title=_('Footer'), inherited=True, content='contents.footer'), ), ), Template( key='with-sidebar', title=_('with sidebar'), template_name='pages/with-sidebar.html', regions=( Region(key='main', title=_('Main'), content='contents.main'), Region(key='sidebar', title=_('Sidebar'), content='contents.sidebar'), Region(key='footer', title=_('Footer'), inherited=True, content='contents.footer'), ), ), ] # MenuMixin MENUS = [ ('main', _('main')), ('footer', _('footer')), ] def get_plugins(self): renderers = get_available_renderers() page = get_object_or_404(Page, pk=self.id) contents = contents_for_item(page, PagePlugins) data = [] for region in self.regions: new_data = { region.key: [ dict(renderers[plugin.__class__](plugin), type=plugin.__class__.__name__, lang=page.language_code, parent=page.slug) ] for plugin in eval(region.content) } data.append(new_data) return data # AppsMixin. We have two apps, one is for company PR, the other # for a more informal blog. # # NOTE! The app names (first element in the tuple) have to match the # article categories exactly for URL reversing and filtering articles by # app to work! (See app.articles.models.Article.CATEGORIES) APPLICATIONS = [ ('publications', _('publications'), { 'urlconf': 'app.articles.urls', }), ('blog', _('blog'), { 'urlconf': 'app.articles.urls', }), ]