Comments (11)
Hi @dwasyl. Thanks for the input. I take it this idea has come out of frustration in using wagtailmenus on a multisite project? If so, it'd be great to hear more about that setup (how the page tree is broken up... what is similar across sites, what is different etc). I suppose I always assumed multisite projects would rarely share any pages across sites, and so duplicating a menu for use on a different site wouldn't be that useful, as you'd have to change every item to link to a different page anyway. That's just based on my experience, though, yours may well be different?
from wagtailmenus.
My pleasure @ababic! Wagtailmenus has been great, super easy to implement so far, although I've been trying to use it to develop sidebar menus/navs as well. That's definitely where my request came from.
In my case, the multisite project is basically taking consistent look & feel web project onto separate properties. The web trees don't really share any pages, although, they do generally share the same header/footer menus (and definitely not sharing the same Main Menu). I would hardcode the header/footer menus in, but there are some limited circumstances where change/customization could be required. Due to this, keeping the menus separate (rather than shared) is good, but being able to duplicate one entirely would be very useful.
The required look and feel means that certain things, like header and footer or even some other menus would be the same/similar between sites, although no other content would be the same. Does the use case make sense? Let me know if I wasn't clear enough.
from wagtailmenus.
Hi @dwasyl. Thanks. It's great to have your insight! Can I just ask why you aren't using the section_menu tag for side menus? Is it because the sites use a lot of apps that are routed via URLs, and so you aren't serving actual wagtail Page objects a lot of the time (section_menu currently only works when serving a 'Page', so it can figure out what to render)? Or are you adding a lot of links to things that aren't pages?
from wagtailmenus.
Sorry for all the questions :) I'm thinking that with some small adjustments elsewhere to make things easier to use in different situations, it may well solve the problem for most people.
from wagtailmenus.
Hi @dwasyl I've raised #23 in order to better explain what I was getting at earlier. I still think the idea of having a 'Duplicate' feature for flat menus has merit. The admin side of things is using the wagtail.contrib.modeladmin
app to hook into wagtail, which I know supports the addition of urls/views and a new button.
Is this something you'd feel comfortable tackling yourself and adding via a pull request?
from wagtailmenus.
Well, I am using section_menu where possible, but I have a number of side menus that have outside links. As well, I'm trying to build a menu that generates links based on the document using JavaScript (sort of a Table of Contents menu).
Let me take a look at the code to see if I can figure out how to add the feature/button myself. I'm happy to try sending a PR.
from wagtailmenus.
Thanks @dwasyl, I wrote the modeladmin app, so allow me to point you in the right direction:
Adding the button:
- You need to create a new ButtonHelper class (sub-classing
wagtail.contrib.modeladmin.helpers.ButtonHelper
), and add abutton_helper_class
attribute onwagtailmenus.wagtail_hooks.FlatMenuAdmin
to point at it. - The button helper class will need a new
duplicate_button
method to define the button (you can probably copyedit_button
as a starting point) - You'll then need to override the
get_buttons_for_obj
method to add that button into a list with the others. - I think it would be sensible to add some logic inside
get_buttons_for_obj
to only add the duplicate button if there areSite
objects that don't yet have a flat menu with the same handle.
Creating a view:
This will be where most of the work is needed. It's probably best to sub-class wagtail.contrib.modeladmin.InstanceSpecificView
as your starting point and work from there. For an example of getting a simple form into a view, you should use the ChooseParentView
as a guide.
Linking the new view into FlatMenuAdmin
:
- You need to add a new
duplicate_view
method toFlatMenuAdmin
, that will grab your new class-based view, initialise and return it (copying theedit_view
method from ModelAdmin should get you most of the way there: https://github.com/torchbox/wagtail/blob/master/wagtail/contrib/modeladmin/options.py#L364) - The
get_admin_urls_for_registration
method from ModelAdmin needs extending forFlatMenuAdmin
to hook an additional 'duplicate' url into Wagtail. This should just be a case of adding a newurl
definition to the list it already creates, and returning it (copying theedit
url definition from ModelAdmin should get you most of the way there: https://github.com/torchbox/wagtail/blob/master/wagtail/contrib/modeladmin/options.py#L485)
from wagtailmenus.
Alright - thanks for the directions :) I was away for a few days, but I'm going to try and tackle this this week or next.
I will also update the display code, as right now if two menus have the same name on different sites it is difficult to differentiate them (since nothing about the site name appears in the display).
from wagtailmenus.
Sounds great! Let me know if you run into any blockers :)
from wagtailmenus.
Had a few days delay with another project so this got delayed slightly, but still on the list for soon :)
from wagtailmenus.
Not a problem, @dwasyl. In the meantime, I might tweak the listing to include the site name, as that's a small change, and something that should really be there already.
from wagtailmenus.
Related Issues (20)
- Potential UI compatibility issues with Wagtail 4.0 HOT 17
- `help_text` with `mark_safe_lazy` breaks the admin panel: `TypeError at /admin/wagtailmenus/flatmenu/create/: __str__ returned non-string (type __proxy__)` HOT 3
- Wagtail 4 field labels are unecessarily right-aligned, looks strange HOT 1
- missing template file in wagtailadmin 4.0.x is breaking wagtailmenus HOT 3
- DEFAULT_AUTO_FIELD introduced in Django 3.2 behaviour HOT 2
- Setting a limit to the creation of FlatMenu instances HOT 1
- Multiple Sites?
- Remove obsolete hard-coded publishing panel fields HOT 2
- Discrepancy between compatibility on website and readme. HOT 3
- ImportError during development
- No migration file ! So makemigrations break HOT 8
- Support for wagtail >= 2.15 HOT 1
- Migrate to wagtail.snippets or wagtail-modeladmin HOT 13
- Does not work with Wagtail 5.1 HOT 6
- Wagtail 5.2 throws wagtailadmin.W002 warnings HOT 4
- wagtailadmin.W002 warnings HOT 1
- Wagtail 5.2.x Warnings HOT 2
- Update documentation for new release HOT 2
- Pypi Project links are broken, Read the Docs not updated HOT 4
- In Wagtail 6.1 not working menus!!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wagtailmenus.