Rename Documents

Questions, comments, discussions. Over time certain topics might be moved to their own category.
fern
Posts: 4
Joined: Sat Mar 21, 2020 12:27 pm

Re: Rename Documents

Post by fern »

I managed to have the workflow rename after uploads and get the name like <yyyy-dd-mm>_<documenttype>.<file_extension> where the date is a custom datefield documentdate that I fill.

How do I get rid of the dashes in the date format ? Currently I get a file named something like 2020-03-24_invoice.pdf but would prefer 20200324_invoice.pdf.

User avatar
rosarior
Developer
Developer
Posts: 505
Joined: Tue Aug 21, 2018 3:28 am
Location: Puerto Rico
Contact:

Re: Rename Documents

Post by rosarior »

This is a limitation of Django's template engine, which we use for Mayan. Like the "split" tag, they have determined that a "replace" tag will not be added: https://code.djangoproject.com/ticket/21367

We are considering adding those (and others) ourselves for Mayan use only. As such we have been customizing Django's template system incrementally, adding new features in each iteration. There is no timeline for adding a replace tag, but is something we are looking into.

gtrot
Posts: 10
Joined: Tue Oct 01, 2019 9:03 pm

Re: Rename Documents

Post by gtrot »

fern,

You could try, for the workflow :

Code: Select all

{{ document.metadata_value_of.yourcustommetadatadatefield|cut:"-" }}
It will remove the dashes.
Source : https://docs.djangoproject.com/en/1.11/ ... /builtins/

G

User avatar
rosarior
Developer
Developer
Posts: 505
Joined: Tue Aug 21, 2018 3:28 am
Location: Puerto Rico
Contact:

Re: Rename Documents

Post by rosarior »

Forgot about the "cut" filter. Thanks Guillaume!

fern
Posts: 4
Joined: Sat Mar 21, 2020 12:27 pm

Re: Rename Documents

Post by fern »

Thanks for your information all - the cut statement works for me!

I really like Mayan and will expore django a little more.

fern
Posts: 4
Joined: Sat Mar 21, 2020 12:27 pm

Re: Rename Documents

Post by fern »

Is it possible to retain the filetype extension while renaming? The extension is dropped in my workflow.

Here's my current code:

{% if document.metadata_value_of.factuur_nummer %} {{ document.metadata_value_of.document_datum|cut:"-" }}_{{ document.metadata_value_of.bedrijf }}_{{ document.document_type.label }}_{{ document.metadata_value_of.factuur_nummer }} {% else %} {{ document.label }} {% endif %}

Post Reply