Discussion:
[Mayan EDMS: 1014] Plugin for post uploading processing
Magan
2015-04-04 19:32:27 UTC
Permalink
Hi, I've read as much as I found within this group, readthedocs and gmane,
but couldn't find a way.

I would like to execute a python script against a new document right after
it is uploaded.

But I'm not willing to modify the project itself since beyond this, I'd
write an app to report the info concerning that post upload processing.


- How to plug my script into Mayan? Or better yet,
- How to add an app with my own views and model to the general project?


If necessary, I'm willing to document that procedures.


Thanks
--
---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mayan-edms+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Roberto Rosario
2015-04-06 07:11:28 UTC
Permalink
Hi Magan,

Indeed there is no documentation on the topic. I've added a ticket to
remedy that (https://github.com/mayan-edms/mayan-edms/issues/175). In the
mean this is the rough idea:

This is for Mayan 1.1, for Mayan 2.0 some the steps have already changed.

1. Create a directory inside mayan/apps for your new app.
2. Create an empty __init__.py and a models.py file with the line:

from django.db import models

this is so Django recognizes this directory as a valid Django app.

3. Tie your code to the post_version_upload signal by adding this to the
models.py file of your app, this signal fires when a document received a
new version or a new document is uploaded:

from django.dispatch import receiver
from documents.signals import post_version_upload
from documents.models import DocumentVersion

@receiver(post_version_upload, dispatch_uid=my_new_doc_handler', sender
=DocumentVersion)
def my_new_doc_handler(sender, instance, **kwargs):
print 'new document version', instance
print 'new document', instance.document

4. To register a view, create a normal views.py, urls.py. Then create a
file named links.py and add a dictionary for every link you want to add:

link_my_app_link = {'text': _('Document summary'), 'view': 'myapp:my_view'}

5. In you __init__.py file add:

from navigation.api import register_top_menu
from .links import link_my_app_link
register_top_menu(name='my_app', link=link_my_app_link)

6. Add you app to INSTALLED_APPS in mayan/settings/base.py and your app's
urls.py file to mayan/urls.py

That should be it.

Let us know how it goes. It would also be great if your could document the
process in the ticket (https://github.com/mayan-edms/mayan-edms/issues/175),
that would make creating the documentation topic file much easier. Thanks!
Post by Magan
Hi, I've read as much as I found within this group, readthedocs and gmane,
but couldn't find a way.
I would like to execute a python script against a new document right after
it is uploaded.
But I'm not willing to modify the project itself since beyond this, I'd
write an app to report the info concerning that post upload processing.
- How to plug my script into Mayan? Or better yet,
- How to add an app with my own views and model to the general project?
If necessary, I'm willing to document that procedures.
Thanks
--
---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mayan-edms+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Magan
2015-04-07 01:56:13 UTC
Permalink
Thank you Roberto, and count on that!

Tonight I'll start adding my app, and recording the steps I give in order
to generate a documentation on the topic.


Regards,
Post by Roberto Rosario
Hi Magan,
Indeed there is no documentation on the topic. I've added a ticket to
remedy that (https://github.com/mayan-edms/mayan-edms/issues/175). In the
This is for Mayan 1.1, for Mayan 2.0 some the steps have already changed.
1. Create a directory inside mayan/apps for your new app.
from django.db import models
this is so Django recognizes this directory as a valid Django app.
3. Tie your code to the post_version_upload signal by adding this to the
models.py file of your app, this signal fires when a document received a
from django.dispatch import receiver
from documents.signals import post_version_upload
from documents.models import DocumentVersion
@receiver(post_version_upload, dispatch_uid=my_new_doc_handler', sender
=DocumentVersion)
print 'new document version', instance
print 'new document', instance.document
4. To register a view, create a normal views.py, urls.py. Then create a
link_my_app_link = {'text': _('Document summary'), 'view': 'myapp:my_view'}
from navigation.api import register_top_menu
from .links import link_my_app_link
register_top_menu(name='my_app', link=link_my_app_link)
6. Add you app to INSTALLED_APPS in mayan/settings/base.py and your app's
urls.py file to mayan/urls.py
That should be it.
Let us know how it goes. It would also be great if your could document the
process in the ticket (https://github.com/mayan-edms/mayan-edms/issues/175),
that would make creating the documentation topic file much easier. Thanks!
Post by Magan
Hi, I've read as much as I found within this group, readthedocs and
gmane, but couldn't find a way.
I would like to execute a python script against a new document right
after it is uploaded.
But I'm not willing to modify the project itself since beyond this, I'd
write an app to report the info concerning that post upload processing.
- How to plug my script into Mayan? Or better yet,
- How to add an app with my own views and model to the general project?
If necessary, I'm willing to document that procedures.
Thanks
--
---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mayan-edms+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Magan
2015-04-21 15:45:42 UTC
Permalink
Hi, I'm a little confused. When a new document is uploaded, it would be useful to have the initial version being uploaded, and the post processed one that results after that.

However, in the stack I see that I am still in the new_version method of the original document. To which event shall I connect the script then?

Regards,
--
---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mayan-edms+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Magan
2015-04-22 13:56:07 UTC
Permalink
Well... It seems that indeed a new version is created and stored in disk, so it would be sufficient to read that file and invoke the new_version method.

However, could the shared upload file be read at this signal? I need to do so since guess_type is not recongnizing the mime type of the stored document but it does with the shared upload separately.
--
---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mayan-edms+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Magan
2015-04-27 22:24:52 UTC
Permalink
When a new file is uploaded and the initial version is created, if we would
want to after-upload-process the new document, the convenient signal would
need to be sent with the new document as a parameter, ready to get a new
version of it.


PS: I deleted my other message, because I was indeed confused and posted
usefulness comments.
Post by Magan
Hi, I'm a little confused. When a new document is uploaded, it would be
useful to have the initial version being uploaded, and the post processed
one that results after that.
However, in the stack I see that I am still in the new_version method of
the original document. To which event shall I connect the script then?
Regards,
--
---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mayan-edms+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Magan
2015-05-05 02:54:56 UTC
Permalink
Between Document.new_version and DocumentVersion.save there are two django
specific creates, and I can't figure how to pass the file_object to the
Document.new_version method.

Any ideas on how to do that?
Post by Magan
When a new file is uploaded and the initial version is created, if we
would want to after-upload-process the new document, the convenient signal
would need to be sent with the new document as a parameter, ready to get a
new version of it.
PS: I deleted my other message, because I was indeed confused and posted
usefulness comments.
Post by Magan
Hi, I'm a little confused. When a new document is uploaded, it would be
useful to have the initial version being uploaded, and the post processed
one that results after that.
However, in the stack I see that I am still in the new_version method of
the original document. To which event shall I connect the script then?
Regards,
--
---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mayan-edms+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...