Navigation Menu

Skip to content

Commit

Permalink
Backwards incompatible: remove collecting import from fluent_pages.in…
Browse files Browse the repository at this point in the history
…tegration.fluent_contents

This turned out to be a really bad idea, forcing projects into debugging
various circular import errors. By making sure the admin is NOT
importing during a models import, many cross-importing cases are solved.
This issue is amplified when projects use
FLUENT_PAGES_PARENT_ADMIN_MIXIN/FLUENT_PAGES_CHILD_ADMIN_MIXIN to insert
their own admin mixin classes, which could easily issue a module scan.
The prominent example is django-guardian's admin calling get_user_model()
  • Loading branch information
vdboor committed Mar 25, 2015
1 parent 2b02791 commit 199c1f6
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -10,6 +10,9 @@ Changes in version 0.9 (dev)
* Fix behavior of ``Page.objects.language(..).get_for_path()`` and ``best_match_for_path()``, use the currently selected language.
This is similar to django-parler_'s ``TranslatableModel.objects.language(..).create(..)`` support.
* Fix skipping mount-points in ``app_reverse()`` when the root is not translated.
* *Backwards incompatible* with previous beta releases: split the ``fluent_pages.integration.fluent_contents`` package.
You'll need to import from the ``.models.``, ``.admin`` and ``.page_type_plugins`` explicitly.
This removes many cases where projects suffered from circular import errors.


Released in 0.9c1:
Expand Down
8 changes: 4 additions & 4 deletions docs/api/integration/fluent_contents.rst
Expand Up @@ -6,19 +6,19 @@ fluent_pages.integration.fluent_contents
.. automodule:: fluent_pages.integration.fluent_contents

The ``FluentContentsPageAdmin`` class
--------------------------------------
-------------------------------------

.. autoclass:: fluent_pages.integration.fluent_contents.FluentContentsPageAdmin
.. autoclass:: fluent_pages.integration.fluent_contents.admin.FluentContentsPageAdmin
:members:

The ``FluentContentsPage`` class
--------------------------------

.. autoclass:: fluent_pages.integration.fluent_contents.FluentContentsPage
.. autoclass:: fluent_pages.integration.fluent_contents.models.FluentContentsPage
:members:

The ``FluentContentsPagePlugin`` class
--------------------------------------

.. autoclass:: fluent_pages.integration.fluent_contents.FluentContentsPagePlugin
.. autoclass:: fluent_pages.integration.fluent_contents.page_type_plugins.FluentContentsPagePlugin
:members:
8 changes: 4 additions & 4 deletions docs/newpagetypes/fluent_contents.rst
Expand Up @@ -6,7 +6,7 @@ Integration with fluent-contents
The bundled :ref:`fluent page type <fluentpage>` provides a page type
where parts of the page can be filled with flexible content blocks.
This feature can be used in your custom page types as well.
The :mod:`fluent_pages.integration.fluent_contents` package contains
The :mod:`fluent_pages.integration.fluent_contents` package provides
all classes to make this integration painless.

.. note::
Expand All @@ -32,7 +32,7 @@ This allowed editing the opening view, and "thank you view" as 2 separate area's

.. code-block:: python
from fluent_pages.integration.fluent_contents import FluentContentsPage
from fluent_pages.integration.fluent_contents.models import FluentContentsPage
class DonationPage(FluentContentsPage):
"""
Expand All @@ -48,7 +48,7 @@ This allowed editing the opening view, and "thank you view" as 2 separate area's

.. code-block:: python
from fluent_pages.integration.fluent_contents import FluentContentsPageAdmin
from fluent_pages.integration.fluent_contents.admin import FluentContentsPageAdmin
class DonationPageAdmin(FluentContentsPageAdmin):
"""
Expand All @@ -65,7 +65,7 @@ This allowed editing the opening view, and "thank you view" as 2 separate area's
from django.conf.urls import url
from fluent_pages.extensions import page_type_pool
from fluent_pages.integration.fluent_contents import FluentContentsPagePlugin
from fluent_pages.integration.fluent_contents.page_type_plugins import FluentContentsPagePlugin
from .admin import DonationPageAdmin
from .models import DonationPage
from .views import DonationSuccessView
Expand Down
10 changes: 10 additions & 0 deletions fluent_pages/integration/__init__.py
@@ -0,0 +1,10 @@
# import apipkg
#
# realmodule = "fluent_pages.integration._fluent_contents"
# apipkg.initpkg(__name__, {
# 'fluent_contents': {
# 'FluentContentsPage': realmodule + ".models.FluentContentsPage",
# 'FluentContentsPageAdmin': realmodule + ".admin.FluentContentsPageAdmin",
# 'FluentContentsPagePlugin': realmodule + ".admin.FluentContentsPagePlugin",
# }
# })
24 changes: 13 additions & 11 deletions fluent_pages/integration/fluent_contents/__init__.py
Expand Up @@ -7,16 +7,18 @@
The following parts are provided:
* The admin class; :class:`FluentContentsPageAdmin`
* The page type model: :class:`FluentContentsPage`
* The plugin class: :class:`FluentContentsPagePlugin`
* The admin class; :class:`.admin.FluentContentsPageAdmin`
* The page type model: :class:`.models.FluentContentsPage`
* The plugin class: :class:`.page_type_plugins.FluentContentsPagePlugin`
These classes can be imported from their respective subpackages::
from fluent_pages.integration.fluent_contents.admin import FluentContentsPageAdmin
from fluent_pages.integration.fluent_contents.models import FluentContentsPage
from fluent_pages.integration.fluent_contents.page_type_plugins import FluentContentsPagePlugin
"""
from .models import FluentContentsPage
from .admin import FluentContentsPageAdmin
from .page_type_plugins import FluentContentsPagePlugin

__all__ = (
'FluentContentsPageAdmin',
'FluentContentsPage',
'FluentContentsPagePlugin',
)
# There used to be more imports here, but that turned out to be a really bad idea.
# Exposing the model, plugin and admin in one __init__ package means importing the admin,
# and potentially triggering circular imports because of that (e.g. get_user_model(), load all apps)
from .models import FluentContentsPage
2 changes: 1 addition & 1 deletion fluent_pages/pagetypes/fluentpage/admin.py
@@ -1,6 +1,6 @@
from django.conf.urls import url, patterns
from fluent_pages.admin import HtmlPageAdmin, PageAdminForm
from fluent_pages.integration.fluent_contents import FluentContentsPageAdmin
from fluent_pages.integration.fluent_contents.admin import FluentContentsPageAdmin
from fluent_pages.models import PageLayout
from fluent_contents.analyzer import get_template_placeholder_data
from fluent_utils.ajax import JsonResponse
Expand Down
2 changes: 1 addition & 1 deletion fluent_pages/pagetypes/fluentpage/models.py
@@ -1,7 +1,7 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from fluent_pages.models import PageLayout
from fluent_pages.integration.fluent_contents import FluentContentsPage
from fluent_pages.integration.fluent_contents.models import FluentContentsPage


# This all exists for backwards compatibility
Expand Down
2 changes: 1 addition & 1 deletion fluent_pages/pagetypes/fluentpage/page_type_plugins.py
@@ -1,5 +1,5 @@
from fluent_pages.extensions import page_type_pool
from fluent_pages.integration.fluent_contents import FluentContentsPagePlugin
from fluent_pages.integration.fluent_contents.page_type_plugins import FluentContentsPagePlugin
from .models import FluentPage
from .admin import FluentPageAdmin

Expand Down

0 comments on commit 199c1f6

Please sign in to comment.