Wagtail page promote tab - "Show in Menu" - How does it work? - django

The default Wagtail page model includes the "Show in Menu" option on the promote tab. I've been searching through the documentation for awhile now trying to find more information about how this works and I don't see anything.
What is this option used for, and how do I hook into that field so that I can build a simple list of links to be used is some arbitrary template like a footer?
Am I supposed to just build my own queryset of page models and then filter on that value, or is there a simpler utility include with Wagtail that I can use directly?

This is a generic field that is available on Page models that does not do anything by default.
https://docs.wagtail.org/en/stable/reference/pages/model_reference.html?highlight=show_in_menua#wagtail.core.models.Page.show_in_menus
While the documentation is not the clearest, the only thing this impacts is whether the page is returned in in_menu() querysets.
https://docs.wagtail.org/en/stable/reference/pages/queryset_reference.html#wagtail.core.query.PageQuerySet.in_menu
As Wagtail does not make assumptions about what your frontend (front facing pages) will look like it is up to you to determine what this field means for your application.
Additional links
https://wagtailmenus.readthedocs.io/en/stable/ - a package for building complex menus within Wagtail
https://www.accordbox.com/blog/how-to-create-and-manage-menus-in-wagtail/ - good tutorial on building custom Wagtail menus

The Wagtail Getting Started section could use some information about how to use 'show in menu' to create menus. Until that gets added, try this tutorial for how to use this 'from scratch': https://www.accordbox.com/blog/how-to-create-and-manage-menus-in-wagtail/
Or install wagtailmenus per instructions in this tutorial: https://engineertodeveloper.com/wagtail-site-navigation/
(At work we built ours by hand but if we were doing it over, I would definitely look into wagtailmenus)

Related

Wagtail menu: add or move items

I'm creating website with Wagtail and i'd like to understand menu wagtail-way. I found solutions with templatetags or with menu-items. This is simple and working. But Wagtail solves if i need to add some item (link to external site, link to webpage with filters aso...) and how menu can be rearanged? I'm tried to search Wagtail "doc", but it keeps talking just about admin menu and for simple menu there nothing more than few simple hints about parent and children of the Page.
Thanks for any advice or link to doc.
You are correct that Wagtail itself does not include menu management features. If modifying templates to manipulate menus is not an adequate solution (e.g. site editors will need to modify the menu in the future), you will have to either create your own custom logic or use an external library like https://github.com/rkhleics/wagtailmenus.

How to create sub-pages for apphook model instances with django-cms?

Question Context
I am responsible to design the cms architecture for a project.
The requirements state that a group of editors should be able to create "Projects".
Each project..
saves meta data about itself
is queryable from other places (e.g. top 5 projects).
has a page that displays information about it. (does not need to be a cms page instance)
can be connected to countries (meaning that an implementation of that project exists in the selected counties).
can have sub-pages which in turn can also be nested.
Imagined Example
Using the django-cms documentation as a bases I would image the resulting structure to look like this:
Projects (apphook)
"Project 1" (Page for project 1 model instance)
"Project 2" (Page for project 2 model instance)
"Project 2 Subpage 1" (Subpage for project 2 model instance)
"Project 2 Subpage 2" (Subpage for project 2 model instance)
"Project 2 Sub-Subpage" (Subpage of "Project 2 Subpage 2")
However that does not seem to exist or at least I did not see any references on how to get such a structure.
In a video I heard that as soon as there is an apphook.. subpages do not make sense anymore.
Somewhere else I read that in theory if the hook is permissive enough.. it could be combined. However even if that works.. the subpages would not be liked to actual instances of the custom apphook model.
PS: I am currently using: django-cms==3.3.0
Question
How can I feature such a structure using django-cms?
I figured it could be done by having an apphooked page for each project. In that case.. the server would have to be restarted for every newly created project. That does not seem to be very elegant.
Alternatives
I have been working with wagtail on a previous project. Thus I do know how to implement such a structure with wagtail easily using ProjectPage and ProjectSubpage models.
I refuse to give up on django-cms being capable of replicating such functionality. I am open for alternative paradigms and approaches. Maybe there are some I have not thought of. If so please let me know. :)
Request
Guidance and ideas are very welcome!
Please tell me if you know of any way how to get that or have some idea that could point me in the right direction.
Thank you!
A couple of points here for you.
django CMS can happily serve pages "beneath" and apphook, but the apphook gets priority during URL resolution. So, just make sure that your apphook's URL patterns don't gobble up everything and sub-pages should be OK.
An alternative approach would be to make a one-to-many table that holds "page-like" attributes (title, meta-attributes, etc.) and at least one PlaceholderField. This can then be used to present what appears to be normal CMS pages that the apphook-itself can control with its views. So, you could have apphook-model-specific context and url-patterns and still have almost all of the front-end editing features of the CMS.
I hope this helps!

Opencart module development - Inject javascript/html code in some pages

I'm a beginner on Opencart and just started developing a module for Opencart which it must inject some lines of javascript and html code in these pages:
- Cart Page
- Product Page
- Confirmation Order Page
- Register form page
The official documentation doesn't have informations about how can i do that, I've tried to find a good documentation about OpenCart but I didn't find anything.
I need help. How can I do that?
Diggin necro topics;) :
The easiest way i think:
upload/catalog/view/theme/[themename]/template/product/product.tpl - here you can add your custom html for product page
[your theme name, you shouldnt overwrite default theme because it can cause damage after update]
It depends on where you're trying to insert the HTML/JavaScript.
Doing things the proper way in OpenCart, you're limited to the column-left, column-right, content-top, and content-bottom positions.
The files you'll need to create are:
admin/controller/module/mymodule.php
admin/language/english/module/mymodule.php
admin/view/template/module/mymodule.tpl
catalog/controller/module/mymodule.php
catalog/language/module/mymodule.php
catalog/view/theme/default/module/mymodule.php
To learn how to do this the first time, it's easiest to replicate an existing stock OpenCart module (preferably a simple one, such as information). Once you've replicated it you'll need to go through each of those files and replace any references to "information" with "mymodule".
After that, if you've done it properly, you should be able to navigate to Admin > Extensions > Modules and see your module in there. Then install it, use the "Add module" button to position the module on all the relevant layouts, hit save and hey presto you have a working module on the front-end.
To modify the front-end output, just edit catalog/view/theme/default/module/mymodule.php
If you want to insert your HTML somewhere other than the 4 available positions OpenCart gives you, position your module in the content-bottom position and use JavaScript/jQuery to inject some HTML where you want.
If this is for your own personal website then as Pawel S suggested it would be easiest to simply modify the relevant view files (ie. catalog/view/theme/[themename]/template/product/product.tpl), however if you're making a module which you plan to distribute then this should be a last resort.
Hope that helps!
I realize this is probably long dead by now, but if you're creating a module that needs to modify existing controllers, languages, models or views the correct tool to use is vQMod.
vQMod allows you to modify existing code on the fly using XML.
https://code.google.com/p/vqmod/

Django strategy for automatically suggesting matching content

I'm looking at porting a custom-written PHP CMS into Django. One of the features the CMS currently has is an image upload function. I write an article, tag it with information, then choose a photo for it. If the system has any photos which have been added to articles with tags in common with the new one, it will suggest the photo for that article too. If there are no matches then a new image can be added.
In case this doesn't make sense, let's say I tag an article as Bruce Springsteen, The Beatles and Led Zeppelin. Next time I add an article with the tag The Beatles, it should suggest I use the image added for the first article.
What would be the best Django-applicable way to implement this? I've looked at the Photologue app and have integrated it, and I know it has tagging support (the problem here is that I'm using django-taggit, whereas Photologue supports django-tagging). One approach could be simply building it myself -- when a user uploads an article, I run a hook after they save it to associate the tags with the image. I'm just not sure how to then autosuggest an image in the admin tools based on that info.
Any ideas/approaches greatly appreciated.
This is almost certainly something you're going to have to build yourself. Django has a moderate number of libraries out there (that you've clearly already found). Unlike other solutions, it doesn't have a lot of things that get you 100% to your desired solution (whereas something like Drupal might get you 100% of the way there).
What you will probably need to do (at a high level) is something like this:
Create an AJAX view that takes the current tags as an argument and does a query on the existing posts to see what tags match and returns images from those posts.
Use jQuery/javascript on your view to call your AJAX view on the page as tags are added
Use jQuery to update a <div> on your page and show all the images that your view returned
Here is a similar example that might help get you started.
You might look into django-ajax as a helper library for your requests, but it definitely isn't necessary.
The hook between the your image module and any other django module can be implemented using django's contenttypes framework which also provides some useful instance methods for returning related/hooked objects.

Use Django admin modules inside own forms

In the Django admin i have a customized changelist with added search and filters. I have been looking alot but cannot seem to find a way to use the whole "changelist module" outside of admin. So i can embed it in one of my own pages.
I do not need any of the authentication or anything like that. I just want to show a table (for a content management backend) that has the nice search, sort and filter capabilities.
Is there perhaps any documentation about doing this?
Of course you can use the ChangeList class for your own projects. I cannot give you a full documentation on doing so here, but some points to start with.
Have a look here to see how the
ChangeList has to be initialized in
your view. (The ChangeList class
lives at
django.contrib.admin.views.main, so
import it from there!)
Look at the admin templates to see how the
corresponding template tags are used.
(also this template)
Maybe you will also find the django.contrib.databrowse-application helpful!