Quickstart¶
Setup¶
Actually it would be more interesting to show how pagetools works with existing apps. But for simplicity let’s start with a pure pagetools installation.
Add the pagetools apps you want to use and their requirements to INSTALLED_APPS:
INSTALLED_APPS = [
'grappelli.dashboard',# optional (pagetools provides two dashboard modules), needs further configuration
'grappelli',
'django.contrib.admin',
...
'django.contrib.sites',
'crispy_forms', # required for pages
'sekizai', # required for sections. Needs further configuration
'captcha' # required for `pages.forms.CaptchaContactForm`
'pagetools.core', # needed for all pagetools modules
'pagetools.widgets', # Widgets (e.g. for sidebars)
'pagetools.menus', #
'pagetools.pages', # Simple Pages, requires `menus` and `widgets`
'pagetools.sections',# Nested Content (e.g. for a singlepage site)
'pagetools.search', # Simple Search on database fields
'pagetools.subscriptions', # Subscriptions to whatever
...
]
SITE_ID = 1 # required by contrib.sites
Add the urls to your project:
from pagetools.pages.views import IndexView
from pagetools.sections.views import admin_pagenodesview
urlpatterns = [
path("admin/filebrowser/", site.urls),
path("grappelli/", include("grappelli.urls")),
path("admin/", admin.site.urls),
# path("captcha/", include("captcha.urls")),
path("", IndexView.as_view(), name="index"),
path("", include("pagetools.urls")),
path("pages/", include("pagetools.pages.urls", namespace="pages")),
path("node/", include("pagetools.sections.urls", namespace="sections")),
path(
"adminnodes/<slug:slug>/",
admin_pagenodesview,
name="admin_pagenodesview",
),
path("search/", include("pagetools.search.urls")),
path(
"subscribe/",
include("pagetools.subscriptions.urls", namespace="subscriptions"),
),
]
Note: Most pagetools models have a language field. If you don’t need different languages just ignore them.
Configuring the Dashboard¶
Migrate if you have not already..
Create the dashboard:
./manage.py customdashboard
and add it in settings:
GRAPPELLI_INDEX_DASHBOARD = 'dashboard.CustomIndexDashboard'
Edit dashboard.py to include the menu module:
from pagetools.menus.dashboard_modules import MenuModule
...
class CustomIndexDashboard(Dashboard):
...
def init_with_context(self, context):
...
self.children.append(MenuModule(column=1)) # default menu title is MainMenu
# or
# self.children.append(MenuModule(column=1, menu_title="mymenu"))
Search¶
The search is just a simple database query. Define somwhere:
from pagetools import search
search.search_mods = (
(Page, ('title', 'content'),),
# or
# (Page, ('title', 'content'),{'replacements': 'content'}),
...
)
If replacement is defined as a json file, it will be used as source for replacements. (e.g. “ä” to “ä”). You can also set search.extra_filter to a callable that receives the resulting queryset (and should return one)
The SearchView is also an example for adding a view to the Menu.
All is required is a call to pagetools.menus.utils.entrieable_reverse_name with one or two arguments (viewname, appname).
This is done in pagetools.search.urls:
urlpatterns = [path("", SearchResultsView.as_view(), name=entrieable_reverse_name("search"))]