views:

145

answers:

3

I'm writing a custom app for Django CMS, but get the following error when trying to view a published entry in the admin:

TemplateSyntaxError at /admin/cmsplugin_publisher/entry/

Caught NoReverseMatch while rendering: Reverse for 'cmsplugin_publisher_entry_detail' with arguments '()' and keyword arguments '{'slug': u'test-german'}' not found.

I can get the app working if I give the app a URL in my main application urls.py, but that fixes the app to a required URL, I just want extend Django CMS so the app will come from whichever page it's added to.

models.py Absolute URL Pattern

    @models.permalink
    def get_absolute_url(self):
        return ('cmsplugin_publisher_entry_detail', (), {
            'slug': self.slug})

urls/entries.py

from django.conf.urls.defaults import *
from cmsplugin_publisher.models import Entry
from cmsplugin_publisher.settings import PAGINATION, ALLOW_EMPTY, ALLOW_FUTURE

entry_conf_list = {'queryset': Entry.published.all(), 'paginate_by': PAGINATION,}

entry_conf = {'queryset': Entry.published.all(),
    'date_field': 'creation_date',
    'allow_empty': ALLOW_EMPTY,
    'allow_future': ALLOW_FUTURE,
}

entry_conf_detail = entry_conf.copy()
del entry_conf_detail['allow_empty']
del entry_conf_detail['allow_future']
del entry_conf_detail['date_field']
entry_conf_detail['queryset'] = Entry.objects.all()

urlpatterns = patterns('cmsplugin_publisher.views.entries',
    url(r'^$', 'entry_index', entry_conf_list,
        name='cmsplugin_publisher_entry_archive_index'),
    url(r'^(?P<page>[0-9]+)/$', 'entry_index', entry_conf_list,
        name='cmsplugin_publisher_entry_archive_index_paginated'),
)

urlpatterns += patterns('django.views.generic.list_detail',
    url(r'^(?P<slug>[-\w]+)/$', 'object_detail', entry_conf_detail,
        name='cmsplugin_publisher_entry_detail'),
)

views/entries.py

from django.views.generic.list_detail import object_list
from cmsplugin_publisher.models import Entry
from cmsplugin_publisher.views.decorators import update_queryset

entry_index = update_queryset(object_list, Entry.published.all)

views/decorators.py

def update_queryset(view, queryset, queryset_parameter='queryset'):
    '''Decorator around views based on a queryset passed in parameter which will force the update despite cache
    Related to issue http://code.djangoproject.com/ticket/8378'''

    def wrap(*args, **kwargs):
        '''Regenerate the queryset before passing it to the view.'''
        kwargs[queryset_parameter] = queryset()
        return view(*args, **kwargs)
    return wrap

The app integration with Django CMS is explained here: http://github.com/divio/django-cms/blob/master/cms/docs/app_integration.txt

It looks like the issue might be that I'm not correctly returning the RequestContext as I'm using a mis of generic views and custom in the application.

The CMS App extension py file:

cms_app.py

from django.utils.translation import ugettext_lazy as _

from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from cmsplugin_publisher.settings import APP_MENUS

class PublisherApp(CMSApp):
    name = _('Publisher App Hook')
    urls = ['cmsplugin_publisher.urls']

apphook_pool.register(PublisherApp)

Any pointers appreciated, it's proving to be a tough nut to crack!

A: 

UPDATE:

OK, I think your error originates from get_absolute_url:

@models.permalink
def get_absolute_url(self):
    return ('cmsplugin_publisher_entry_detail', (), {'slug': self.slug})

I suspect it's because this ultimately calls object_detail which expects a positional parameter queryset (see django/views/generic/list_detail.py). You could try changing this to something like:

    return ('cmsplugin_publisher_entry_detail', [Entry.objects.all(),], {'slug': self.slug})
ars
That's not making a difference: the slug_field defaults to use 'slug' - which is part of the model.
Chris
You're right, didn't notice the default for slug_field .. I've updated my answer. Hope this gets somewhere.
ars
I think you're right about the poisitional element, but your edit raises:Caught ValueError while rendering: Don't mix *args and **kwargs in call to reverse()!So it must be elsewhere that this issue is ocurring
Chris
Maybe just create a wrapper function for object_detail that accepts two positional parameters (Entry.objects.all and self.slug) which then calls object_detail. Specify that wrapper function in get_absolute_url. If that works, at least you'll know you're on the right track.
ars
A: 

I would double-check that urls/entries.py is actually being imported somewhere otherwise it won't be able to get the reverse match.

Jason Davies
Doesn't seem to be that, it's in a folder /urls/ importing entries.py via __init__.py in the folder. Works OK when an absolute URL is given for the application int he main website urls.py - though of course I only want to extend off django-cms URLs, so that's not a solution I can use.
Chris
A: 

Looks like it's a bug in the URLconf parser in Django-CMS 2.1.0beta3, which is fixed in dev. The bug only occurs when including other URLconfs from within an app.

Jason Davies
That's fixed it perfectly. Thanks Jason!
Chris