Is it possible to add a Button to a Wagtail Settings page? - python

I am trying to customize a settings page so it has a button that I will assign to a certain action. (Let's assume for now I just want to log something into the console).
Ideally it would be of something like this:
#register_setting
class ActionTriggeringSetting(BaseSetting):
button = models.ButtonField(
action=myLoggingFunc,
help_text='Click here to log "Hello World" to the console'
)
I tried looking into the site settings but found nothing really helpful there.
Does anybody know if something of the sort exists?
Thank you

Depending on where in the admin UI you want you button to be, there is a way using the register-admin-menu-item or register-settings-menu-item Wagtail hook
See: https://docs.wagtail.io/en/v2.10.1/reference/hooks.html#register-admin-menu-item
and
https://docs.wagtail.io/en/v2.10.1/reference/hooks.html#register-settings-menu-item
The approaches above will add a button to the Wagtail Admin menu or the settings submenu, respectively. Clicking on the button will trigger a custom view that you also need to add - this is also loosely covered in the linked docs.

Related

How to change Log out icon in jazzmin django theme?

I have django project with jazzmin theme library I use, I've change icon for sidebar with:
"icons:{...}"
and I want to change the user menu icons, the logout menu:
what I know is, we can use this line:
"usermenu_links" : {}
But I don't quite understand how to pointing for the log out button, any idea?

How to display a different page when user refreshes the current page in Django

I am a beginner in Django and I want to display page-y when the user refreshes the page-x
this event not related to django if you want to do that you should trigger refresh page event using JavaScript
and when this event happen you can make JavaScript function run and make this function navigate user to new page or open new window
check this article to better understanding what I mean
best of luck
Pure HTML/ Django answer. Reload in a Web browser will do another GET for the page. If the Django server remembers the context of the last GET, it can choose to do a redirect rather than show the same again. So for example, if it's something in the user's profile:
if request.user.profile.whatever:
return redirect( 'myapp:anotherpage' )

Django cms hide menu item when the page is empty

I have created a menu using django cms, there is a menu item named 'News'. There is a page linked to this menu item News, when there is no article in it, this menu item has to hide from the menu otherwise it has to visible. The problem is when all the articles are deleted in the News page the menu item still appears in the menu until or unless the server is not restarted. Can any one help me to figure this out?
Did you read the django cms caching documents? There is a discussion about the caching in the django cms. Have a look at this
There is also an option to use the cache plugin.
Also check this note in the documentation;
If you disable a plugin cache be sure to restart the server and clear the cache afterwards.

How to open dynamic links in new tab with web py framework?

I tried web.seeother("link"), but this does not open it in a new tab. Now I can generate a link with a _blank tag, but then the user has to click on the link separately that is separate button for generating the link and another button to follow that link. I want to perform both with a single click. A server side method to do this would be best.
I am using the web.py framework.
As the document says web.seeother() is used for redirecting a user to another page. So a more clear way for asking your question is: "how to make web.seeother() open a link in a new tab"?
As I have observed the documents, There is no way to do that on server-side.
Not a web.py issue. Cannot be done from server-side by any python or non-python framework, must be done in the Client.
From the client, you can set target="_blank" in the HTML, or use javascript with something like window.open(url). Javascript will allow you to set size and position of second window.

Use django view without redirecting or refreshing a page

I have a button next to some text on a page. I'd like to execute some Python code if that button is pressed. The only way I know how to do this is through a view. The thing is, I need the page not to redirect or refresh or anything, just some code to execute when the button is pressed. Any ideas on how I'd get this done?
Asynchronous Javascript and XML (Ajax).
You can perform an Ajax request to the view you want to execute and this will be done without refreshing nor redirecting the current web page.
This is the W3C Ajax tutorial which might be good for beginners. All you have to do is code some javascript in your templates, add the onclick event listener to your button and you're up :)
You may take a look at this tutorials and documentation, seems very apropiate.
Hope this helps!
When button is clicked you can use javascript to make an async request (AJAX) to your django project
typing in django ajax to google shows a lot of resources, one of which is a beginners tutorial:
http://lethain.com/two-faced-django-part-5-jquery-ajax/

Categories