[Python-modules-commits] [django-polymorphic] 01/01: Import django-polymorphic_1.1.orig.tar.gz

Michael Fladischer fladi at moszumanska.debian.org
Mon Mar 6 12:51:38 UTC 2017


This is an automated email from the git hooks/post-receive script.

fladi pushed a commit to branch upstream
in repository django-polymorphic.

commit c8a26004aa28670af6a8e8e4d4fbfb4b94fef30b
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Wed Mar 1 14:37:27 2017 +0100

    Import django-polymorphic_1.1.orig.tar.gz
---
 .../_ext/djangodummy}/__init__.py                  |   0
 docs/_ext/djangodummy/requirements.txt             |   3 +
 docs/_ext/djangodummy/settings.py                  |  11 +
 .../_ext/djangoext}/__init__.py                    |   0
 docs/_ext/djangoext/docstrings.py                  |  47 ++
 docs/_ext/djangoext/roles.py                       |   8 +
 docs/advanced.rst                                  |   3 +-
 docs/api/index.rst                                 |  13 +
 docs/api/polymorphic.admin.rst                     |  93 ++++
 docs/api/polymorphic.contrib.extra_views.rst       |   7 +
 docs/api/polymorphic.contrib.guardian.rst          |   7 +
 docs/api/polymorphic.formsets.rst                  |  41 ++
 docs/api/polymorphic.managers.rst                  |  21 +
 docs/api/polymorphic.models.rst                    |   8 +
 docs/api/polymorphic.templatetags.rst              |   4 +
 docs/api/polymorphic.utils.rst                     |   5 +
 docs/changelog.rst                                 |  10 +
 docs/conf.py                                       |  21 +-
 docs/index.rst                                     |  10 +-
 docs/migrating.rst                                 |  19 +-
 docs/third-party.rst                               |  52 +-
 polymorphic/__init__.py                            |   5 +-
 polymorphic/admin/__init__.py                      |   1 +
 polymorphic/admin/childadmin.py                    |   3 -
 polymorphic/admin/generic.py                       |   8 +-
 polymorphic/admin/inlines.py                       |   9 +-
 polymorphic/admin/parentadmin.py                   |   2 -
 polymorphic/contrib/extra_views.py                 | 126 +++++
 polymorphic/formsets/__init__.py                   |  17 -
 polymorphic/formsets/generic.py                    |  19 +-
 polymorphic/formsets/models.py                     |  14 +-
 polymorphic/formsets/utils.py                      |   1 +
 polymorphic/manager.py                             |   2 +-
 polymorphic/managers.py                            |  10 +-
 polymorphic/models.py                              |  62 +--
 polymorphic/query.py                               |  36 +-
 polymorphic/query_translate.py                     |   8 +-
 polymorphic/showfields.py                          |   2 +-
 polymorphic/templatetags/__init__.py               |  77 +++
 .../templatetags/polymorphic_formset_tags.py       |  79 +++
 polymorphic/tests/__init__.py                      | 418 ++++++++++++++++
 polymorphic/tests/test_admin.py                    |  31 ++
 polymorphic/tests/test_multidb.py                  | 106 ++++
 polymorphic/{tests.py => tests/test_orm.py}        | 554 +--------------------
 polymorphic/tests/test_regression.py               |  24 +
 polymorphic/utils.py                               |  29 ++
 setup.cfg                                          |   4 +
 47 files changed, 1360 insertions(+), 670 deletions(-)

diff --git a/polymorphic/templatetags/__init__.py b/docs/_ext/djangodummy/__init__.py
similarity index 100%
copy from polymorphic/templatetags/__init__.py
copy to docs/_ext/djangodummy/__init__.py
diff --git a/docs/_ext/djangodummy/requirements.txt b/docs/_ext/djangodummy/requirements.txt
new file mode 100644
index 0000000..b5041fb
--- /dev/null
+++ b/docs/_ext/djangodummy/requirements.txt
@@ -0,0 +1,3 @@
+# for readthedocs
+# Remaining requirements are picked up from setup.py
+Django==1.5.10
diff --git a/docs/_ext/djangodummy/settings.py b/docs/_ext/djangodummy/settings.py
new file mode 100644
index 0000000..414e9fa
--- /dev/null
+++ b/docs/_ext/djangodummy/settings.py
@@ -0,0 +1,11 @@
+# Settings file to allow parsing API documentation of Django modules,
+# and provide defaults to use in the documentation.
+#
+# This file is placed in a subdirectory,
+# so the docs root won't be detected by find_packages()
+
+# Display sane URLs in the docs:
+STATIC_URL = '/static/'
+
+# Avoid error for missing the secret key
+SECRET_KEY = 'docs'
diff --git a/polymorphic/templatetags/__init__.py b/docs/_ext/djangoext/__init__.py
similarity index 100%
copy from polymorphic/templatetags/__init__.py
copy to docs/_ext/djangoext/__init__.py
diff --git a/docs/_ext/djangoext/docstrings.py b/docs/_ext/djangoext/docstrings.py
new file mode 100644
index 0000000..5ae5bf1
--- /dev/null
+++ b/docs/_ext/djangoext/docstrings.py
@@ -0,0 +1,47 @@
+"""
+Automatically mention all model fields as parameters in the model construction.
+Based on http://djangosnippets.org/snippets/2533/
+"""
+import django
+from django.utils.html import strip_tags
+from django.utils.encoding import force_unicode
+import inspect
+
+
+def improve_model_docstring(app, what, name, obj, options, lines):
+    from django.db import models  # must be inside the function, to allow settings initialization first.
+
+    if inspect.isclass(obj) and issubclass(obj, models.Model):
+        if django.VERSION >= (1,8):
+            model_fields = obj._meta.get_fields()
+        elif django.VERSION >= (1,6):
+            model_fields = obj._meta.fields
+        else:
+            model_fields = obj._meta._fields()
+
+        for field in model_fields:
+            help_text = strip_tags(force_unicode(field.help_text))
+            verbose_name = force_unicode(field.verbose_name).capitalize()
+
+            # Add parameter
+            if help_text:
+                lines.append(u':param %s: %s' % (field.attname, help_text))
+            else:
+                lines.append(u':param %s: %s' % (field.attname, verbose_name))
+
+            # Add type
+            if isinstance(field, models.ForeignKey):
+                to = field.rel.to
+                lines.append(u':type %s: %s to :class:`~%s.%s`' % (field.attname, type(field).__name__, to.__module__, to.__name__))
+            else:
+                lines.append(u':type %s: %s' % (field.attname, type(field).__name__))
+
+    # Return the extended docstring
+    return lines
+
+# Allow this module to be used as sphinx extension:
+def setup(app):
+    # Generate docstrings for Django model fields
+    # Register the docstring processor with sphinx
+    app.connect('autodoc-process-docstring', improve_model_docstring)
+
diff --git a/docs/_ext/djangoext/roles.py b/docs/_ext/djangoext/roles.py
new file mode 100644
index 0000000..b5ed3e1
--- /dev/null
+++ b/docs/_ext/djangoext/roles.py
@@ -0,0 +1,8 @@
+# Allow :django:setting:`SITE_ID` to work.
+
+def setup(app):
+    app.add_crossref_type(
+        directivename = "setting",
+        rolename = "setting",
+        indextemplate = "pair: %s; setting",
+    )
diff --git a/docs/advanced.rst b/docs/advanced.rst
index c9fcac4..bcffe50 100644
--- a/docs/advanced.rst
+++ b/docs/advanced.rst
@@ -203,7 +203,8 @@ Nicely Displaying Polymorphic Querysets
 In order to get the output as seen in all examples here, you need to use the
 :class:`~polymorphic.showfields.ShowFieldType` class mixin::
 
-    from polymorphic.showfields import PolymorphicModel, ShowFieldType
+    from polymorphic.models import PolymorphicModel
+    from polymorphic.showfields import ShowFieldType
 
     class ModelA(ShowFieldType, PolymorphicModel):
         field1 = models.CharField(max_length=10)
diff --git a/docs/api/index.rst b/docs/api/index.rst
new file mode 100644
index 0000000..935762d
--- /dev/null
+++ b/docs/api/index.rst
@@ -0,0 +1,13 @@
+API Documentation
+=================
+
+.. toctree::
+
+   polymorphic.admin
+   polymorphic.contrib.extra_views
+   polymorphic.contrib.guardian
+   polymorphic.formsets
+   polymorphic.managers
+   polymorphic.models
+   polymorphic.templatetags
+   polymorphic.utils
diff --git a/docs/api/polymorphic.admin.rst b/docs/api/polymorphic.admin.rst
new file mode 100644
index 0000000..aadabee
--- /dev/null
+++ b/docs/api/polymorphic.admin.rst
@@ -0,0 +1,93 @@
+polymorphic.admin
+=================
+
+ModelAdmin classes
+------------------
+
+The ``PolymorphicParentModelAdmin`` class
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. autoclass:: polymorphic.admin.PolymorphicParentModelAdmin
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+
+The ``PolymorphicChildModelAdmin`` class
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. autoclass:: polymorphic.admin.PolymorphicChildModelAdmin
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+
+List filtering
+--------------
+
+The ``PolymorphicChildModelFilter`` class
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. autoclass:: polymorphic.admin.PolymorphicChildModelFilter
+    :show-inheritance:
+
+
+Inlines support
+---------------
+
+The ``StackedPolymorphicInline`` class
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. autoclass:: polymorphic.admin.StackedPolymorphicInline
+    :show-inheritance:
+
+
+The ``GenericStackedPolymorphicInline`` class
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. autoclass:: polymorphic.admin.GenericStackedPolymorphicInline
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+
+The ``PolymorphicInlineSupportMixin`` class
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. autoclass:: polymorphic.admin.PolymorphicInlineSupportMixin
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+
+Low-level classes
+-----------------
+
+These classes are useful when existing parts of the admin classes.
+
+
+.. autoclass:: polymorphic.admin.PolymorphicModelChoiceForm
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+
+.. autoclass:: polymorphic.admin.PolymorphicInlineModelAdmin
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+
+.. autoclass:: polymorphic.admin.GenericPolymorphicInlineModelAdmin
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+
+.. autoclass:: polymorphic.admin.PolymorphicInlineAdminForm
+    :show-inheritance:
+
+
+.. autoclass:: polymorphic.admin.PolymorphicInlineAdminFormSet
+    :show-inheritance:
+
diff --git a/docs/api/polymorphic.contrib.extra_views.rst b/docs/api/polymorphic.contrib.extra_views.rst
new file mode 100644
index 0000000..b30133f
--- /dev/null
+++ b/docs/api/polymorphic.contrib.extra_views.rst
@@ -0,0 +1,7 @@
+polymorphic.contrib.extra_views
+===============================
+
+.. automodule:: polymorphic.contrib.extra_views
+    :members:
+    :undoc-members:
+    :show-inheritance:
diff --git a/docs/api/polymorphic.contrib.guardian.rst b/docs/api/polymorphic.contrib.guardian.rst
new file mode 100644
index 0000000..87a171b
--- /dev/null
+++ b/docs/api/polymorphic.contrib.guardian.rst
@@ -0,0 +1,7 @@
+polymorphic.contrib.guardian
+============================
+
+.. automodule:: polymorphic.contrib.guardian
+    :members:
+    :undoc-members:
+    :show-inheritance:
diff --git a/docs/api/polymorphic.formsets.rst b/docs/api/polymorphic.formsets.rst
new file mode 100644
index 0000000..abc48d2
--- /dev/null
+++ b/docs/api/polymorphic.formsets.rst
@@ -0,0 +1,41 @@
+polymorphic.formsets
+====================
+
+.. automodule:: polymorphic.formsets
+
+
+Model formsets
+--------------
+
+.. autofunction:: polymorphic.formsets.polymorphic_modelformset_factory
+
+.. autoclass:: polymorphic.formsets.PolymorphicFormSetChild
+
+
+Inline formsets
+---------------
+
+.. autofunction:: polymorphic.formsets.polymorphic_inlineformset_factory
+
+
+Generic formsets
+----------------
+
+.. autofunction:: polymorphic.formsets.generic_polymorphic_inlineformset_factory
+
+
+Low-level features
+------------------
+
+The internal machinery can be used to extend the formset classes. This includes:
+
+.. autofunction:: polymorphic.formsets.polymorphic_child_forms_factory
+
+.. autoclass:: polymorphic.formsets.BasePolymorphicModelFormSet
+    :show-inheritance:
+
+.. autoclass:: polymorphic.formsets.BasePolymorphicInlineFormSet
+    :show-inheritance:
+
+.. autoclass:: polymorphic.formsets.BaseGenericPolymorphicInlineFormSet
+    :show-inheritance:
diff --git a/docs/api/polymorphic.managers.rst b/docs/api/polymorphic.managers.rst
new file mode 100644
index 0000000..d7cc448
--- /dev/null
+++ b/docs/api/polymorphic.managers.rst
@@ -0,0 +1,21 @@
+polymorphic.managers
+====================
+
+.. automodule:: polymorphic.managers
+
+
+The ``PolymorphicManager`` class
+--------------------------------
+
+
+.. autoclass:: polymorphic.managers.PolymorphicManager
+    :members:
+    :show-inheritance:
+
+
+The ``PolymorphicQuerySet`` class
+---------------------------------
+
+.. autoclass:: polymorphic.managers.PolymorphicQuerySet
+    :members:
+    :show-inheritance:
diff --git a/docs/api/polymorphic.models.rst b/docs/api/polymorphic.models.rst
new file mode 100644
index 0000000..8bf3949
--- /dev/null
+++ b/docs/api/polymorphic.models.rst
@@ -0,0 +1,8 @@
+polymorphic.models
+==================
+
+.. automodule:: polymorphic.models
+
+.. autoclass:: polymorphic.models.PolymorphicModel
+    :members:
+    :show-inheritance:
diff --git a/docs/api/polymorphic.templatetags.rst b/docs/api/polymorphic.templatetags.rst
new file mode 100644
index 0000000..dde9cc7
--- /dev/null
+++ b/docs/api/polymorphic.templatetags.rst
@@ -0,0 +1,4 @@
+polymorphic.templatetags.polymorphic_admin_tags
+===============================================
+
+.. automodule:: polymorphic.templatetags
diff --git a/docs/api/polymorphic.utils.rst b/docs/api/polymorphic.utils.rst
new file mode 100644
index 0000000..97fcfc6
--- /dev/null
+++ b/docs/api/polymorphic.utils.rst
@@ -0,0 +1,5 @@
+polymorphic.utils
+=================
+
+.. automodule:: polymorphic.utils
+    :members:
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 3092a46..1593c2c 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -1,6 +1,16 @@
 Changelog
 =========
 
+Version 1.1 (2017-01-27)
+------------------------
+
+* Added class based formset views in ``polymorphic/contrib/extra_views``.
+* Added helper function ``polymorphic.utils.reset_polymorphic_ctype()``.
+  This eases the migration old existing models to polymorphic.
+* Fixed Python 2.6 issue.
+* Fixed Django 1.6 support.
+
+
 Version 1.0.2 (2016-10-14)
 --------------------------
 
diff --git a/docs/conf.py b/docs/conf.py
index f14fa5f..8ae26d3 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -13,6 +13,8 @@
 
 import sys
 import os
+import django
+import sphinx_rtd_theme
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
@@ -21,6 +23,9 @@ sys.path.insert(0, os.path.abspath('_ext'))
 sys.path.insert(0, os.path.abspath('..'))
 os.environ['DJANGO_SETTINGS_MODULE'] = 'djangodummy.settings'
 
+if django.VERSION >= (1, 8):
+    django.setup()
+
 # -- General configuration -----------------------------------------------------
 
 # If your documentation needs a minimal Sphinx version, state it here.
@@ -31,7 +36,9 @@ os.environ['DJANGO_SETTINGS_MODULE'] = 'djangodummy.settings'
 extensions = [
     'sphinx.ext.autodoc',
     'sphinx.ext.graphviz',
-    'sphinx.ext.intersphinx'
+    'sphinx.ext.intersphinx',
+    'djangoext.docstrings',
+    'djangoext.roles',
 ]
 
 # Add any paths that contain templates here, relative to this directory.
@@ -55,9 +62,9 @@ copyright = u'2013, Bert Constantin, Chris Glass, Diederik van der Boor'
 # built documents.
 #
 # The short X.Y version.
-version = '1.0.2'
+version = '1.1'
 # The full version, including alpha/beta/rc tags.
-release = '1.0.2'
+release = '1.1'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
@@ -98,7 +105,8 @@ pygments_style = 'sphinx'
 
 # The theme to use for HTML and HTML Help pages.  See the documentation for
 # a list of builtin themes.
-#html_theme = 'alabaster'
+html_theme = 'sphinx_rtd_theme'
+html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
 
 # Theme options are theme-specific and customize the look and feel of a theme
 # further.  For a list of options available for each theme, see the
@@ -252,5 +260,8 @@ texinfo_documents = [
 # Example configuration for intersphinx: refer to the Python standard library.
 intersphinx_mapping = {
     #'http://docs.python.org/': None,
-    'https://docs.djangoproject.com/en/dev': 'https://docs.djangoproject.com/en/dev/_objects',
+    'https://docs.djangoproject.com/en/stable': 'https://docs.djangoproject.com/en/stable/_objects',
 }
+
+# autodoc settings
+autodoc_member_order = 'groupwise'
diff --git a/docs/index.rst b/docs/index.rst
index f648091..e2c1769 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -1,8 +1,9 @@
 Welcome to django-polymorphic's documentation!
 ==============================================
 
-Django-polymorphic simplifies using inherited models in Django projects.
-When a query is made at the base model, the inherited model classes are returned.
+Django-polymorphic builds on top of the standard Django model inheritance.
+It makes using inherited models easier. When a query is made at the base model,
+the inherited model classes are returned.
 
 When we store models that inherit from a ``Project`` model...
 
@@ -43,6 +44,7 @@ Features
  * Combining querysets of different models (``qs3 = qs1 | qs2``)
  * Support for custom user-defined managers.
 
+* Formset support.
 * Uses the minimum amount of queries needed to fetch the inherited models.
 * Disabling polymorphic behavior when needed.
 
@@ -56,6 +58,7 @@ Getting started
    quickstart
    admin
    performance
+   third-party
 
 Advanced topics
 ---------------
@@ -67,9 +70,10 @@ Advanced topics
    migrating
    managers
    advanced
-   third-party
    changelog
    contributing
+   api/index
+
 
 Indices and tables
 ==================
diff --git a/docs/migrating.rst b/docs/migrating.rst
index 7848234..b6f7d5c 100644
--- a/docs/migrating.rst
+++ b/docs/migrating.rst
@@ -41,10 +41,6 @@ can be included in a single Django migration. For example:
         MyModel.objects.filter(polymorphic_ctype__isnull=True).update(polymorphic_ctype=new_ct)
 
 
-    def backwards_func(apps, schema_editor):
-        pass
-
-
     class Migration(migrations.Migration):
 
         dependencies = [
@@ -58,8 +54,21 @@ can be included in a single Django migration. For example:
                 name='polymorphic_ctype',
                 field=models.ForeignKey(related_name='polymorphic_myapp.mymodel_set+', editable=False, to='contenttypes.ContentType', null=True),
             ),
-            migrations.RunPython(forwards_func, backwards_func),
+            migrations.RunPython(forwards_func, migrations.RunPython.noop),
         ]
 
 It's recommended to let ``makemigrations`` create the migration file,
 and include the ``RunPython`` manually before running the migration.
+
+.. versionadded:: 1.1
+When the model is created elsewhere, you can also use
+the :func:`polymorphic.utils.reset_polymorphic_ctype` function:
+
+.. code-block:: python
+
+    from polymorphic.utils import reset_polymorphic_ctype
+    from myapp.models import Base, Sub1, Sub2
+
+    reset_polymorphic_ctype(Base, Sub1, Sub2)
+
+    reset_polymorphic_ctype(Base, Sub1, Sub2, ignore_existing=True)
diff --git a/docs/third-party.rst b/docs/third-party.rst
index 837f21f..f1d412a 100644
--- a/docs/third-party.rst
+++ b/docs/third-party.rst
@@ -2,6 +2,35 @@ Third-party applications support
 ================================
 
 
+django-guardian support
+-----------------------
+
+.. versionadded:: 1.0.2
+
+You can configure django-guardian_ to use the base model for object level permissions.
+Add this option to your settings:
+
+.. code-block:: python
+
+    GUARDIAN_GET_CONTENT_TYPE = 'polymorphic.contrib.guardian.get_polymorphic_base_content_type'
+
+This option requires django-guardian_ >= 1.4.6. Details about how this option works are available in the
+`django-guardian documentation <https://django-guardian.readthedocs.io/en/latest/configuration.html#guardian-get-content-type>`_.
+
+
+django-extra-views
+------------------
+
+.. versionadded:: 1.1
+
+The :mod:`polymorphic.contrib.extra_views` package provides classes to display polymorphic formsets
+using the classes from django-extra-views_. See the documentation of:
+
+* :class:`~polymorphic.contrib.extra_views.PolymorphicFormSetView`
+* :class:`~polymorphic.contrib.extra_views.PolymorphicInlineFormSetView`
+* :class:`~polymorphic.contrib.extra_views.PolymorphicInlineFormSet`
+
+
 django-mptt support
 -------------------
 
@@ -97,24 +126,9 @@ This doesn't work, since it needs to look for revisions of the child model. Usin
 the view of the actual child model is used, similar to the way the regular change and delete views are redirected.
 
 
-django-guardian support
------------------------
-
-.. versionadded:: 1.0.2
-
-You can configure django-guardian_ to use the base model for object level permissions.
-Add this option to your settings:
-
-.. code-block:: python
-
-    GUARDIAN_GET_CONTENT_TYPE = 'polymorphic.contrib.guardian.get_polymorphic_base_content_type'
-
-This option requires django-guardian_ >= 1.4.6. Details about how this option works are available in the
-`django-guardian documentation <https://django-guardian.readthedocs.io/en/latest/configuration.html#guardian-get-content-type>`_.
-
-
-.. _django-reversion: https://github.com/etianen/django-reversion
-.. _django-reversion-compare: https://github.com/jedie/django-reversion-compare
+.. _django-extra-views: https://github.com/AndrewIngram/django-extra-views
+.. _django-guardian: https://github.com/django-guardian/django-guardian
 .. _django-mptt: https://github.com/django-mptt/django-mptt
 .. _django-polymorphic-tree: https://github.com/django-polymorphic/django-polymorphic-tree
-.. _django-guardian: https://github.com/django-guardian/django-guardian
+.. _django-reversion-compare: https://github.com/jedie/django-reversion-compare
+.. _django-reversion: https://github.com/etianen/django-reversion
diff --git a/polymorphic/__init__.py b/polymorphic/__init__.py
index 4b8c380..1a2fdc0 100644
--- a/polymorphic/__init__.py
+++ b/polymorphic/__init__.py
@@ -6,12 +6,13 @@ Copyright:
 This code and affiliated files are (C) by Bert Constantin and individual contributors.
 Please see LICENSE and AUTHORS for more information.
 """
+import django
+
 # See PEP 440 (https://www.python.org/dev/peps/pep-0440/)
-__version__ = "1.0.2"
+__version__ = "1.1"
 
 
 # Monkey-patch Django < 1.5 to allow ContentTypes for proxy models.
-import django
 if django.VERSION[:2] < (1, 5):
     from django.contrib.contenttypes.models import ContentTypeManager
     from django.utils.encoding import smart_text
diff --git a/polymorphic/admin/__init__.py b/polymorphic/admin/__init__.py
index e067b62..5a6efa8 100644
--- a/polymorphic/admin/__init__.py
+++ b/polymorphic/admin/__init__.py
@@ -41,6 +41,7 @@ __all__ = (
     'PolymorphicInlineAdminFormSet',
     'PolymorphicInlineSupportMixin',
     'PolymorphicInlineModelAdmin',
+    'StackedPolymorphicInline',
     'GenericPolymorphicInlineModelAdmin',
     'GenericStackedPolymorphicInline',
 )
diff --git a/polymorphic/admin/childadmin.py b/polymorphic/admin/childadmin.py
index 0d45f88..e492fed 100644
--- a/polymorphic/admin/childadmin.py
+++ b/polymorphic/admin/childadmin.py
@@ -8,13 +8,11 @@ from django.core.urlresolvers import resolve
 from django.utils import six
 from django.utils.translation import ugettext_lazy as _
 
-from .helpers import PolymorphicInlineSupportMixin
 from ..admin import PolymorphicParentModelAdmin
 
 
 class ParentAdminNotRegistered(RuntimeError):
     "The admin site for the model is not registered."
-    pass
 
 
 class PolymorphicChildModelAdmin(admin.ModelAdmin):
@@ -167,7 +165,6 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin):
             context.update(extra_context)
         return super(PolymorphicChildModelAdmin, self).history_view(request, object_id, extra_context=context)
 
-
     # ---- Extra: improving the form/fieldset default display ----
 
     def get_fieldsets(self, request, obj=None):
diff --git a/polymorphic/admin/generic.py b/polymorphic/admin/generic.py
index 747be67..4a121af 100644
--- a/polymorphic/admin/generic.py
+++ b/polymorphic/admin/generic.py
@@ -1,15 +1,20 @@
-from django.contrib.contenttypes.admin import GenericInlineModelAdmin
 from django.contrib.contenttypes.models import ContentType
 from django.utils.functional import cached_property
 
 from polymorphic.formsets import polymorphic_child_forms_factory, BaseGenericPolymorphicInlineFormSet, GenericPolymorphicFormSetChild
 from .inlines import PolymorphicInlineModelAdmin
 
+try:
+    from django.contrib.contenttypes.admin import GenericInlineModelAdmin  # Django 1.7+
+except ImportError:
+    from django.contrib.contenttypes.generic import GenericInlineModelAdmin
+
 
 class GenericPolymorphicInlineModelAdmin(PolymorphicInlineModelAdmin, GenericInlineModelAdmin):
     """
     Base class for variation of inlines based on generic foreign keys.
     """
+    #: The formset class
     formset = BaseGenericPolymorphicInlineFormSet
 
     def get_formset(self, request, obj=None, **kwargs):
@@ -58,4 +63,5 @@ class GenericStackedPolymorphicInline(GenericPolymorphicInlineModelAdmin):
     """
     The stacked layout for generic inlines.
     """
+    #: The default template to use.
     template = 'admin/polymorphic/edit_inline/stacked.html'
diff --git a/polymorphic/admin/inlines.py b/polymorphic/admin/inlines.py
index 9fd6218..1a1d434 100644
--- a/polymorphic/admin/inlines.py
+++ b/polymorphic/admin/inlines.py
@@ -6,7 +6,6 @@ Each row in the inline can correspond with a different subclass.
 from functools import partial
 
 from django.contrib.admin.options import InlineModelAdmin
-from django.contrib.admin.utils import flatten_fieldsets
 from django.core.exceptions import ImproperlyConfigured
 from django.forms import Media
 
@@ -14,6 +13,11 @@ from polymorphic.formsets import polymorphic_child_forms_factory, BasePolymorphi
 from polymorphic.formsets.utils import add_media
 from .helpers import PolymorphicInlineSupportMixin
 
+try:
+    from django.contrib.admin.utils import flatten_fieldsets  # Django 1.7+
+except ImportError:
+    from django.contrib.admin.util import flatten_fieldsets
+
 
 class PolymorphicInlineModelAdmin(InlineModelAdmin):
     """
@@ -225,7 +229,7 @@ class PolymorphicInlineModelAdmin(InlineModelAdmin):
                 # InlineModelAdmin doesn't define its own.
                 exclude.extend(self.form._meta.exclude)
 
-            #can_delete = self.can_delete and self.has_delete_permission(request, obj)
+            # can_delete = self.can_delete and self.has_delete_permission(request, obj)
             defaults = {
                 "form": self.form,
                 "fields": fields,
@@ -245,4 +249,5 @@ class StackedPolymorphicInline(PolymorphicInlineModelAdmin):
     Stacked inline for django-polymorphic models.
     Since tabular doesn't make much sense with changed fields, just offer this one.
     """
+    #: The default template to use.
     template = 'admin/polymorphic/edit_inline/stacked.html'
diff --git a/polymorphic/admin/parentadmin.py b/polymorphic/admin/parentadmin.py
index e08cf21..744ac28 100644
--- a/polymorphic/admin/parentadmin.py
+++ b/polymorphic/admin/parentadmin.py
@@ -34,12 +34,10 @@ if sys.version_info[0] >= 3:
 
 class RegistrationClosed(RuntimeError):
     "The admin model can't be registered anymore at this point."
-    pass
 
 
 class ChildAdminNotRegistered(RuntimeError):
     "The admin site for the model is not registered."
-    pass
 
 
 class PolymorphicParentModelAdmin(admin.ModelAdmin):
diff --git a/polymorphic/contrib/extra_views.py b/polymorphic/contrib/extra_views.py
new file mode 100644
index 0000000..c84ea6a
--- /dev/null
+++ b/polymorphic/contrib/extra_views.py
@@ -0,0 +1,126 @@
+"""
+The ``extra_views.formsets`` provides a simple way to handle formsets.
+The ``extra_views.advanced`` provides a method to combine that with a create/update form.
+
+This package provides classes that support both options for polymorphic formsets.
+"""
+from __future__ import absolute_import
+from django.core.exceptions import ImproperlyConfigured
+import extra_views
+from polymorphic.formsets import polymorphic_child_forms_factory, BasePolymorphicModelFormSet, BasePolymorphicInlineFormSet
+
+
+__all__ = (
+    'PolymorphicFormSetView',
+    'PolymorphicInlineFormSetView',
+    'PolymorphicInlineFormSet',
+)
+
+
+class PolymorphicFormSetMixin(object):
+    """
+    Internal Mixin, that provides polymorphic integration with the ``extra_views`` package.
+    """
+
+    formset_class = BasePolymorphicModelFormSet
+
+    #: Default 0 extra forms
+    extra = 0
+
+    #: Define the children
+    # :type: list[PolymorphicFormSetChild]
+    formset_children = None
+
+    def get_formset_children(self):
+        """
+        :rtype: list[PolymorphicFormSetChild]
+        """
+        if not self.formset_children:
+            raise ImproperlyConfigured("Define 'formset_children' as list of `PolymorphicFormSetChild`")
+        return self.formset_children
+
+    def get_formset_child_kwargs(self):
+        return {}
+
+    def get_formset(self):
+        """
+        Returns the formset class from the inline formset factory
+        """
+        # Implementation detail:
+        # Since `polymorphic_modelformset_factory` and `polymorphic_inlineformset_factory` mainly
+        # reuse the standard factories, and then add `child_forms`, the same can be done here.
+        # This makes sure the base class construction is completely honored.
+        FormSet = super(PolymorphicFormSetMixin, self).get_formset()
+        FormSet.child_forms = polymorphic_child_forms_factory(self.get_formset_children(), **self.get_formset_child_kwargs())
+        return FormSet
+
+
+class PolymorphicFormSetView(PolymorphicFormSetMixin, extra_views.ModelFormSetView):
+    """
+    A view that displays a single polymorphic formset.
+
+    .. code-block:: python
+
+        from polymorphic.formsets import PolymorphicFormSetChild
+
+
+        class ItemsView(PolymorphicFormSetView):
+            model = Item
+            formset_children = [
+                PolymorphicFormSetChild(ItemSubclass1),
+                PolymorphicFormSetChild(ItemSubclass2),
+            ]
+
+    """
+    formset_class = BasePolymorphicModelFormSet
+
+
+class PolymorphicInlineFormSetView(PolymorphicFormSetMixin, extra_views.InlineFormSetView):
+    """
+    A view that displays a single polymorphic formset - with one parent object.
+    This is a variation of the :mod:`extra_views` package classes for django-polymorphic.
+
+    .. code-block:: python
+
+        from polymorphic.formsets import PolymorphicFormSetChild
+
+
+        class OrderItemsView(PolymorphicInlineFormSetView):
+            model = Order
+            inline_model = Item
+            formset_children = [
+                PolymorphicFormSetChild(ItemSubclass1),
+                PolymorphicFormSetChild(ItemSubclass2),
+            ]
+    """
+    formset_class = BasePolymorphicInlineFormSet
+
+
+class PolymorphicInlineFormSet(PolymorphicFormSetMixin, extra_views.InlineFormSet):
+    """
+    An inline to add to the ``inlines`` of
+    the :class:`~extra_views.advanced.CreateWithInlinesView`
+    and :class:`~extra_views.advanced.UpdateWithInlinesView` class.
+
+    .. code-block:: python
+
+        from polymorphic.formsets import PolymorphicFormSetChild
+
+
+        class ItemsInline(PolymorphicInlineFormSet):
+            model = Item
+            formset_children = [
+                PolymorphicFormSetChild(ItemSubclass1),
+                PolymorphicFormSetChild(ItemSubclass2),
+            ]
+
+
+        class OrderCreateView(CreateWithInlinesView):
+            model = Order
+            inlines = [ItemsInline]
+
+            def get_success_url(self):
+                return self.object.get_absolute_url()
+
+    """
+    formset_class = BasePolymorphicInlineFormSet
diff --git a/polymorphic/formsets/__init__.py b/polymorphic/formsets/__init__.py
index 5605d75..02c47ae 100644
--- a/polymorphic/formsets/__init__.py
+++ b/polymorphic/formsets/__init__.py
@@ -1,6 +1,4 @@
 """
-Polymorphic formsets support.
-
 This allows creating formsets where each row can be a different form type.
 The logic of the formsets work similar to the standard Django formsets;
 there are factory methods to construct the classes with the proper form settings.
@@ -9,21 +7,6 @@ The "parent" formset hosts the entire model and their child model.
 For every child type, there is an :class:`PolymorphicFormSetChild` instance
 that describes how to display and construct the child.
 It's parameters are very similar to the parent's factory method.
-
-See:
-* :func:`polymorphic_inlineformset_factory`
-* :class:`PolymorphicFormSetChild`
-
-The internal machinery can be used to extend the formset classes. This includes:
-* :class:`BasePolymorphicModelFormSet`
-* :class:`BasePolymorphicInlineFormSet`
-* :func:`polymorphic_child_forms_factory`
-
-For generic relations, a similar set is available:
-* :class:`BasePolymorphicGenericInlineFormSet`
-* :class:`PolymorphicGenericFormSetChild`
-* :func:`polymorphic_generic_inlineformset_factory`
-
 """
 from .models import (
     BasePolymorphicModelFormSet,
diff --git a/polymorphic/formsets/generic.py b/polymorphic/formsets/generic.py
index 2109d82..90c0ec1 100644
--- a/polymorphic/formsets/generic.py
+++ b/polymorphic/formsets/generic.py
@@ -1,16 +1,21 @@
 import django
-from django.contrib.contenttypes.forms import BaseGenericInlineFormSet, generic_inlineformset_factory
 from django.contrib.contenttypes.models import ContentType
 from django.db import models
 from django.forms.models import ModelForm
 
 from .models import BasePolymorphicModelFormSet, polymorphic_child_forms_factory, PolymorphicFormSetChild
 
+try:
+    from django.contrib.contenttypes.forms import BaseGenericInlineFormSet, generic_inlineformset_factory  # Django 1.7+
+except ImportError:
+    from django.contrib.contenttypes.generic import BaseGenericInlineFormSet, generic_inlineformset_factory
+
 
 class GenericPolymorphicFormSetChild(PolymorphicFormSetChild):
     """
     Formset child for generic inlines
     """
+
     def __init__(self, *args, **kwargs):
         self.ct_field = kwargs.pop('ct_field', 'content_type')
         self.fk_field = kwargs.pop('fk_field', 'object_id')
@@ -90,17 +95,17 @@ def generic_polymorphic_inlineformset_factory(model, formset_children, form=Mode
... 1867 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/django-polymorphic.git



More information about the Python-modules-commits mailing list