Esempio n. 1
0
    def get_urls(self):
        """
        Expose the custom URLs for the subclasses and the URL resolver.
        """
        urls = super(PolymorphicParentModelAdmin, self).get_urls()
        info = self.model._meta.app_label, self.model._meta.module_name

        # Patch the change URL so it's not a big catch-all; allowing all custom URLs to be added to the end.
        # The url needs to be recreated, patching url.regex is not an option Django 1.4's LocaleRegexProvider changed it.
        new_change_url = url(r'^{0}/$'.format(self.pk_regex), self.admin_site.admin_view(self.change_view), name='{0}_{1}_change'.format(*info))
        for i, oldurl in enumerate(urls):
            if oldurl.name == new_change_url.name:
                urls[i] = new_change_url

        # Define the catch-all for custom views
        custom_urls = patterns('',
            url(r'^(?P<path>.+)$', self.admin_site.admin_view(self.subclass_view))
        )

        # At this point. all admin code needs to be known.
        self._lazy_setup()

        # Add reverse names for all polymorphic models, so the delete button and "save and add" just work.
        # These definitions are masked by the definition above, since it needs special handling (and a ct_id parameter).
        dummy_urls = []
        for model, _ in self.get_child_models():
            admin = self._get_real_admin_by_model(model)
            dummy_urls += admin.get_urls()

        return urls + custom_urls + dummy_urls
Esempio n. 2
0
    def get_urls(self):
        """
        Expose the custom URLs for the subclasses and the URL resolver.
        """
        urls = super(PolymorphicParentModelAdmin, self).get_urls()
        info = self.model._meta.app_label, self.model._meta.module_name

        # Patch the change URL so it's not a big catch-all; allowing all custom URLs to be added to the end.
        # The url needs to be recreated, patching url.regex is not an option Django 1.4's LocaleRegexProvider changed it.
        new_change_url = url(r'^(\d+)/$', self.admin_site.admin_view(self.change_view), name='{0}_{1}_change'.format(*info))
        for i, oldurl in enumerate(urls):
            if oldurl.name == new_change_url.name:
                urls[i] = new_change_url

        # Define the catch-all for custom views
        custom_urls = patterns('',
            url(r'^(?P<path>.+)$', self.admin_site.admin_view(self.subclass_view))
        )

        # At this point. all admin code needs to be known.
        self._lazy_setup()

        # Add reverse names for all polymorphic models, so the delete button and "save and add" just work.
        # These definitions are masked by the definition above, since it needs special handling (and a ct_id parameter).
        dummy_urls = []
        for model, _ in self.get_child_models():
            admin = self._get_real_admin_by_model(model)
            dummy_urls += admin.get_urls()

        return urls + custom_urls + dummy_urls
    def get_urls(self):
        urls = super(ParentModelAdmin, self).get_urls()
        info = (self.model._meta.app_label, self.model._meta.model_name)
        if django.VERSION < (1, 9):
            new_change_url = url(
                r'^{0}/$'.format('(\d+|__fk__)'),
                self.admin_site.admin_view(self.change_view),
                name='{0}_{1}_change'.format(*info)
            )
            redirect_urls = []
            for i, oldurl in enumerate(urls):
                if oldurl.name == new_change_url.name:
                    urls[i] = new_change_url
        else:
            redirect_urls = [pat for pat in urls if not pat.name]  # redirect URL has no name.
            urls = [pat for pat in urls if pat.name]

        custom_urls = [
            url(r'^(?P<path>.+)$', self.admin_site.admin_view(self.subclass_view))
        ]

        self._lazy_setup()

        dummy_urls = []
        for type, _ in self.get_child_models():
            admin = self._get_real_admin(type)
            dummy_urls += admin.get_urls()

        return urls + custom_urls + dummy_urls + redirect_urls
Esempio n. 4
0
    def get_urls(self):
        """
        Expose the custom URLs for the subclasses and the URL resolver.
        """
        urls = super(PolymorphicParentModelAdmin, self).get_urls()

        # At this point. all admin code needs to be known.
        self._lazy_setup()

        # Continue only if in compatibility mode
        if not self._compat_mode:
            return urls

        info = _get_opt(self.model)

        # Patch the change view URL so it's not a big catch-all; allowing all
        # custom URLs to be added to the end. This is done by adding '/$' to the
        # end of the regex.  The url needs to be recreated, patching url.regex
        # is not an option Django 1.4's LocaleRegexProvider changed it.
        if django.VERSION < (1, 9):
            # On Django 1.9, the change view URL has been changed from
            # /<app>/<model>/<pk>/ to /<app>/<model>/<pk>/change/, which is
            # why we can skip this workaround for Django >= 1.9.
            new_change_url = url(
                r'^{0}/$'.format(self.pk_regex),
                self.admin_site.admin_view(self.change_view),
                name='{0}_{1}_change'.format(*info)
            )

            redirect_urls = []
            for i, oldurl in enumerate(urls):
                if oldurl.name == new_change_url.name:
                    urls[i] = new_change_url
        else:
            # For Django 1.9, the redirect at the end acts as catch all.
            # The custom urls need to be inserted before that.
            redirect_urls = [pat for pat in urls if not pat.name]  # redirect URL has no name.
            urls = [pat for pat in urls if pat.name]

        # Define the catch-all for custom views
        custom_urls = [
            url(r'^(?P<path>.+)$', self.admin_site.admin_view(self.subclass_view))
        ]

        # Add reverse names for all polymorphic models, so the delete button and "save and add" just work.
        # These definitions are masked by the definition above, since it needs special handling (and a ct_id parameter).
        dummy_urls = []
        for model, _ in self.get_child_models():
            admin = self._get_real_admin_by_model(model)
            dummy_urls += admin.get_urls()

        return urls + custom_urls + dummy_urls + redirect_urls
    def get_urls(self):
        """
        Expose the custom URLs for the subclasses and the URL resolver.
        """
        urls = super(PolymorphicParentModelAdmin, self).get_urls()

        # At this point. all admin code needs to be known.
        self._lazy_setup()

        # Continue only if in compatibility mode
        if not self._compat_mode:
            return urls

        info = _get_opt(self.model)

        # Patch the change view URL so it's not a big catch-all; allowing all
        # custom URLs to be added to the end. This is done by adding '/$' to the
        # end of the regex.  The url needs to be recreated, patching url.regex
        # is not an option Django 1.4's LocaleRegexProvider changed it.
        if django.VERSION < (1, 9):
            # On Django 1.9, the change view URL has been changed from
            # /<app>/<model>/<pk>/ to /<app>/<model>/<pk>/change/, which is
            # why we can skip this workaround for Django >= 1.9.
            new_change_url = url(
                r'^{0}/$'.format(self.pk_regex),
                self.admin_site.admin_view(self.change_view),
                name='{0}_{1}_change'.format(*info)
            )

            redirect_urls = []
            for i, oldurl in enumerate(urls):
                if oldurl.name == new_change_url.name:
                    urls[i] = new_change_url
        else:
            # For Django 1.9, the redirect at the end acts as catch all.
            # The custom urls need to be inserted before that.
            redirect_urls = [pat for pat in urls if not pat.name]  # redirect URL has no name.
            urls = [pat for pat in urls if pat.name]

        # Define the catch-all for custom views
        custom_urls = [
            url(r'^(?P<path>.+)$', self.admin_site.admin_view(self.subclass_view))
        ]

        # Add reverse names for all polymorphic models, so the delete button and "save and add" just work.
        # These definitions are masked by the definition above, since it needs special handling (and a ct_id parameter).
        dummy_urls = []
        for model, _ in self.get_child_models():
            admin = self._get_real_admin_by_model(model)
            dummy_urls += admin.get_urls()

        return urls + custom_urls + dummy_urls + redirect_urls