Custom Documents menu option (3.5.1/pip install)

Technical aspects, customization, code samples.
Post Reply
lsmoker
Posts: 12
Joined: Wed Sep 05, 2018 3:52 pm

Custom Documents menu option (3.5.1/pip install)

Post by lsmoker »

I am adding a custom menu link to the Documents menu called "Top documents". I have most if it figured out but would like to put the link in order after "All documents". By default, my link is added as the last one, but I'd like to control where it goes. I tried removing the links that would be after it, then re-adding them back with my link as the first in the tuple, but that didn't work - I was able to remove them but not add them back, ie my link showed up but the others I tried to re-add were not there.

Is it possible to control the order of custom menu links?

Also, I would like to have a metadata updated on each document when it is viewed (metadata type = the number of times the document is viewed). In v.2.7.3, I used a nightly script to do this, but I'm wondering if it might be better to have it done in real-time. I'm thinking I might be able to override the 'event_document_view' event for this.

How should one accomplish this?
---
LeVon Smoker
User avatar
rosarior
Developer
Developer
Posts: 596
Joined: Tue Aug 21, 2018 3:28 am
Location: Puerto Rico
Contact:

Re: Custom Documents menu option (3.5.1/pip install)

Post by rosarior »

The bind_links method offers a position argument for this purpose (https://gitlab.com/mayan-edms/mayan-edm ... es.py#L286). However the actual position is not absolute but relative to any existing links in the same menu. Therefore this will also depend on the order your app loads in relation to other app that use the same menu.

Using the view event would be the best choice, this is how the workflow app uses events as transition triggers itself. Create a handler to act as a receiver for the post_save signal of the Action model. The handler will get the Action instance, and from it you will get the verb field which correspond to Mayan's event object, and the target field which will be the document.

https://gitlab.com/mayan-edms/mayan-edm ... ers.py#L36
https://gitlab.com/mayan-edms/mayan-edm ... ps.py#L602
lsmoker
Posts: 12
Joined: Wed Sep 05, 2018 3:52 pm

Re: Custom Documents menu option (3.5.1/pip install)

Post by lsmoker »

Thanks for the reply!
On menu option ordering, I decided to let my options be at the bottom.
On my other question, I did figure out how to set up a signal handler for exactly what you described. Good to know that I did the "right" thing...
---
LeVon Smoker
Post Reply