Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: added recipe for translating external apps #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Table of contents
getting_started
migrating
settings
recipes
reference/index
releases/index
contributing
54 changes: 54 additions & 0 deletions docs/source/recipes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.. _recipes:


===============
Recipes
===============

Code recipes that you may find useful.

-------------------------
Translate an external app
-------------------------

1. Create an abstract class from "TranslatablePage":

.. code-block:: python

from wagtailtrans.models import TranslatablePage

class TranslatablePageAbstract(TranslatablePage):
class Meta:
abstract = True

This code can reside in a separate app (let's call it "common"). It will be imported when needed by other apps.


2. Subclass from "TranslatablePageAbstract" and the external app pages.

Example for `puput <https://github.com/APSL/puput>`_:

.. code-block:: python

from wagtail.core.models import Page
from common.models import TranslatablePageAbstract
from puput.models import BlogPage, EntryPage

class BlogHomePage(TranslatablePageAbstract, BlogPage):
subpage_types = ['blog.BlogEntryPage']

search_fields = BlogPage.search_fields + TranslatablePageAbstract.search_fields[len(Page.search_fields):]
settings_panels = BlogPage.settings_panels + TranslatablePageAbstract.settings_panels[len(Page.settings_panels):]

class BlogEntryPage(TranslatablePageAbstract, EntryPage):
parent_page_types = ['blog.BlogHomePage']

search_fields = EntryPage.search_fields + TranslatablePageAbstract.search_fields[len(Page.search_fields):]
settings_panels = EntryPage.settings_panels + TranslatablePageAbstract.settings_panels[len(Page.settings_panels):]


.. note::

**settings_panels** and **search_fields** are the only attributes that might be defined in **both** wagtailtrans page model and the external app page models.
To avoid overriding their external app definitions we redefine them here by adding the fields coming from the external app and the fields from wagtailtrans.
You notice also that we avoided duplication of the common fields (Ex: Go live date, Expiry date) coming from the parent class "Page".