Code Monkey home page Code Monkey logo

Comments (35)

aacimov avatar aacimov commented on June 11, 2024

Any other soul having the issue? I need to decide whether to use Django CMS 4 for more complex solutions or not. It really is a deal-breaker for me at the moment since I have incoming projects with the same principle of hooking up pages.

I couldn't find anything related in the docs, or I missed it.

Thanks a lot!

from django-cms.

fsbraun avatar fsbraun commented on June 11, 2024

I have not encountered this issue when using multiple instances of namespaced apphooks.

I wonder what Placeholder you are adding the custom plugins to. While django CMS 3 allowed access to page placeholders on apphook root pages, this was never a documented feature and is not immediately possible for v4 without making them explicitly available and set them for the toolbar (see #7712).

I am suspecting you are somehow accessing the wrong placeholder and the permission denied is coming from the fact that the placeholder belongs to a published (and therefore write-protected) page. But that's just a stab in the dark.

Can you check which placeholders you are trying to add plugins to. Are they different for the instances (they should)? Do they belong to a publsihed object?

from django-cms.

aacimov avatar aacimov commented on June 11, 2024

Hmmm. I am actually using my default "Content" template with "Content" placeholder. AppHook role is actually just to be able to hook the URL root to the CMS page (to be able to get e.g. /serial-production/1/test-product/ or /handmade-production/2/another-test-product/

The point is controlling the list through my CMS plugin added to "Content" placeholder (e.g. items shown on 1 page) and/or adding a Disclaimer at the bottom of the list.

Indeed v3 allowed this and it was an awesome feature since clients often ask for display control through plugins.

I am not sure I understand why this is not possible in v4 since the Toolbar is not involved at all. It is not the detail page with PlaceholderMixin "deep down the url structure".

And the weird thing is that it works as expected on my Page 1. When same Apphook with different namespace is added to Page 2 the error appears.

Thanks in advance.

from django-cms.

fsbraun avatar fsbraun commented on June 11, 2024

The reason this changed in v4 are the edit and preview endpoints. The toolbar is the thing allowing you to edit a page in the first place. So it is involved. ;-) The edit endpoints for your apphook will get the apphook view which then must advertise which model instance is to be edited or previewed. This happened implicitly in v3 through the URL of the page (which also was a URL for a valid page).

So you must be doing something in your view to show the placeholder. I assume this code causes the issue. The issue in linked contains a snipped which will advertise the page content object for the apphook's root URL. Maybe it solves your problem? Maybe you can share your apphook root view's code?

from django-cms.

aacimov avatar aacimov commented on June 11, 2024

@fsbraun my bad for not understanding. It may sound a little hostile in my previous reply but it really wasn't (when I read it again it really could have been misinterpreted).

My urls.py has only the detail URL:

urlpatterns = [
    re_path(r'^(?P<product_id>[\d]+)/(?P<product_slug>[\w-]+)/', ProductDetail.as_view(), name='product_detail'),
]

AppHook root is not defined since I am using a custom Plugin with list queryset which is added to my "Content" placeholder.

My cms_app_config.py

class CMSConfigApp(CMSApp):

    def get_configs(self):
        return self.app_config.objects.all()

    def get_config(self, namespace):
        try:
            return self.app_config.objects.get(namespace=namespace)
        except ObjectDoesNotExist:
            return None

    def get_config_add_url(self):
        try:
            return reverse('admin:%s_%s_add' % (self.app_config._meta.app_label,
                                                self.app_config._meta.model_name))
        except:  # pragma: no cover
            return reverse('admin:%s_%s_add' % (self.app_config._meta.app_label,
                                                self.app_config._meta.module_name))

My cms_apps.py

@apphook_pool.register
class ProductsApp(CMSConfigApp):
    app_config = Category
    app_name = 'products'
    name = _('Products')

    def get_urls(self, page=None, language=None, **kwargs):
        return ['myappname.app.products.urls']

My cms_plugins.py

@plugin_pool.register_plugin
class ProductsListPlugin(CMSPluginBase):
    model = ProductListCMSPlugin
    module = _("Products")
    name = _('Products list')
    render_template = "products/plugins/products_list_plugin.html"
    cache = False

    def render(self, context, instance, placeholder):
        context = super(ProductsListPlugin, self).render(context, instance, placeholder)
        category = instance.category
        paginated_items = instance.paginated_items

        try:
            products = Product.objects.filter(category=category, published=True).order_by('order')
        except category.DoesNotExist or category is None:
            products = Product.objects.filter(published=True).order_by('order')

        context.update({
            'products': products,
            'paginated_items': paginated_items
        })

        return context

DB screenshot for these AppHooked pages.

Screenshot 2024-02-23 at 18 00 55

I hope it clarifies my setup.

from django-cms.

fsbraun avatar fsbraun commented on June 11, 2024

Everything's all right - no worries!! OK, I now understand that you do not have a root URL defined for your apphook. I will need some time to take a look and try to reproduce.

from django-cms.

aacimov avatar aacimov commented on June 11, 2024

I thought it is better to write-out my code. It is a bit unusual but it gives a lot of flexibility, especially as some of my clients want to be able to change "almost" everything. Maybe someone will also find it helpful :D

Thanks a lot for your help.

from django-cms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.