Search code examples
pythondjangodjango-sitetree

How to set up django-siteree with django-postman


I'm trying to set up django-sitetree to work with django-postman, but I'm not having much luck.

Most of the pages work correctly, but I can't seem to figure out how to map the postman_view url to work properly. Here's what I have so far. Maybe someone can help me out a bit?

sitetrees.py

from sitetree.utils import tree, item

sitetrees = (
    tree('postman', items=[
        item('Messages', '/messages/', url_as_pattern=False, access_guest=False, access_loggedin=True, children=[
            item('Compose', 'postman_write', access_guest=False, access_loggedin=True),
            item('Inbox', 'postman_inbox', access_guest=False, access_loggedin=True),
            item('View', 'postman_view message.id', access_guest=False, access_loggedin=True, in_menu=False, in_sitetree=False)
        ])
    ])
)

Postman urls.py excerpt

urlpatterns = patterns('',                                                      
    url(r'^inbox/(?:(?P<option>'+OPTIONS+')/)?$', InboxView.as_view(), name='postman_inbox'),
    url(r'^sent/(?:(?P<option>'+OPTIONS+')/)?$', SentView.as_view(), name='postman_sent'),
    url(r'^archives/(?:(?P<option>'+OPTIONS+')/)?$', ArchivesView.as_view(), name='postman_archives'),
    url(r'^trash/(?:(?P<option>'+OPTIONS+')/)?$', TrashView.as_view(), name='postman_trash'),
    url(r'^write/(?:(?P<recipients>[^/#]+)/)?$', WriteView.as_view(), name='postman_write'),
    url(r'^reply/(?P<message_id>[\d]+)/$', ReplyView.as_view(), name='postman_reply'),
    url(r'^view/(?P<message_id>[\d]+)/$', MessageView.as_view(), name='postman_view'),
    url(r'^view/t/(?P<thread_id>[\d]+)/$', ConversationView.as_view(), name='postman_view_conversation'),
    url(r'^archive/$', ArchiveView.as_view(), name='postman_archive'),          
    url(r'^delete/$', DeleteView.as_view(), name='postman_delete'),             
    url(r'^undelete/$', UndeleteView.as_view(), name='postman_undelete'),          
    (r'^$', RedirectView.as_view(url='inbox/')),                                
)

Both postman_write and postman_inbox work fine, but when I visit postman_view I get this error:

SiteTreeError at /messages/view/2/

Unable to resolve current sitetree item to get a `title_resolved` for current page. Check whether there is an appropriate sitetree item defined for current URL.

Solution

  • Thanks to idle sign for pointing me in the right direction.

    Turns out that the postman/view.html template does not have a variable called message, like I had assumed. There is an array of messages called pm_messages. So the corrected sitetrees.py is:

    sitetrees = (
        tree('postman', items=[
            item('Messages', '/messages/', url_as_pattern=False, access_guest=False, access_loggedin=True, children=[
                item('Compose', 'postman_write', access_guest=False, access_loggedin=True),
                item('Inbox', 'postman_inbox', access_guest=False, access_loggedin=True),
                item('View', 'postman_view pm_messages.0.id', access_guest=False, access_loggedin=True, in_menu=False, in_sitetree=False)
            ])
        ])
    )