Include an existing django app in a wagtail page menu - what's the idiomatic 'wagtail-y' approach ?

454 views
Skip to first unread message

Chris Adams

unread,
Jun 7, 2016, 6:09:39 PM6/7/16
to Wagtail support
Hi all,

I'm converting an existing Django site to move from Django CMS, to using Wagtail, and I was hoping someone here might have some pointers on how best to deal with external apps that would typically exist in a global navigation menu on, without hardcoding their names into html templates, and making them harder to change in future.

With Django CMS, you have the notion of 'mounting' an app on a specific page, so you might have a page called 'special blog', that you can then mount a django app at.

In my case I have an existing app, that I'd like to be able include in a menu generated by listing Wagtail pages (a teensy bit like the 'mounting' example above), but it's not clear to me how I ought to do this.

Using serve() and get_context()

One way could be to have a page with the same name as the app, and then dropping some of the app's view code into that specific page subclass, by overriding the serve()[1] and get_context()[2] methods, or maybe using the route()[3].


The eventPage example[4] looks quite a lot like this, and I extracting the view code there isn't a huge pain in this case, but before I do, I wanted to check - is this the recommended way to do this, if you want to make a page appear in wagtail admin menus, so it can be re-ordered like the rest?


Thanks again for such a lovely project

Chris

Andrew Barton

unread,
Jun 7, 2016, 7:01:16 PM6/7/16
to Wagtail support
Hi Chris;

This blog post might help - http://www.tivix.com/blog/working-with-wagtail-menus/

Chris Adams

unread,
Jun 8, 2016, 4:31:57 AM6/8/16
to Wagtail support
Thanks Andrew,

I'm currently using some of that code to generate menus at present :)

For those examples the lists of pages that appear in a menu are already Wagtail Pages, and I'd like to be able add include a link to an external app (let's assume a app with a fair amount of logic, that I might typically define a route for in a urls.py) file in my project otherwise.

I know I can hardcode a link in there with a template tag function, but I'm interested in seeing there's a way to make a link to this appear in Wagtail, so that editors can re-order how the links appear in the nav for example.

I've tried putting a diagram together here to help explain what I'm going for.



It may be that this happens so rarely that it's not worth spending too much time trying to work out how to do this, but before I had a look, it seemed worth asking in the group here.

Thanks again!

Chris

Brett Grace

unread,
Jun 8, 2016, 11:44:27 AM6/8/16
to Wagtail support
If you want to be able to re-order pages in the in the Explorer admin, you're going to have to make a Node that acts like a Page, and the easiest way to do that is probably making a dummy RoutablePage that effectively consumes your app's urls.py to generate its routes.

On several projects I found it to be desirable/necessary to have global navigation menus that weren't strictly derived from the page hierarchy, and the approach I used was to create a navigation menu object that you can edit through the snippets interface. I wound up with the code in this gist. (It's for an older version of Wagtails so it may not work without modification; also, the LinkFields mixin is taken from the wagtaildemo project, but it contains fields for things like Page, Document, URL).

For example take a look at https://www.wsiassn.org — the navigation on the top is built from the sitemap, but the footer navigation is built from three different NavigationMenu snippets. The items are independent of the site map (which may or may not work for your use case), and the site adminstrators have the ability to link URLs that aren't pages managed by Wagtail, such as would be the case with your app.

Not included is the template tag and template code to make this work, if this approach solves your problem and you want some more context/pointers, let me know.

Chris Adams

unread,
Jun 8, 2016, 11:53:44 AM6/8/16
to wag...@googlegroups.com
Hi Brett,

That approach (having a separate menu object for global menus) sounds like a very good solution to my problem - and actually better than what is on the original site.

I'd be very grateful if you were able to share a couple of gists, and I'd be happy to write a blog post about the process, as I'm pretty sure others would find it useful too.


Chris

--
You received this message because you are subscribed to a topic in the Google Groups "Wagtail support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wagtail/srsWmMCpn6Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wagtail+u...@googlegroups.com.
To post to this group, send email to wag...@googlegroups.com.
Visit this group at https://groups.google.com/group/wagtail.
To view this discussion on the web, visit https://groups.google.com/d/msgid/wagtail/d5f69074-281e-4320-935d-cc0889b1aef4%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
See when I'm available for a call: https://calendly.com/mrchrisadams

Chris Adams
skype: chris.d.adams
twitter: mrchrisadams
mob (UK) : +44 7974 368 229
mob (DE) : +49 160 9595 2951

Brett Grace

unread,
Jun 8, 2016, 5:42:03 PM6/8/16
to Wagtail support
I updated the gist, let me know of any problems.
Reply all
Reply to author
Forward
0 new messages