Did a quick test and with Jinja2 it is possible:

from jinja2 import Template
from document_renaming.models import Sequence

document=Document.objects.first()

Template('{% set user = document.target_actions.first().actor %}{{user}}-{{ 
Sequence.objects.get(slug=user).next_value() }}').render(document=document, 
Sequence=Sequence)


outputs:

admin-1

it is even possible to create the user sequences from the template (using 
get_or_create):

Template('{% set user = document.target_actions.first().actor %}{{user}}-{{ 
Sequence.objects.get_or_create(slug=user)[0].next_value() 
}}').render(document=document, Sequence=Sequence)

On Tuesday, January 12, 2016 at 5:30:02 AM UTC-4, Roberto Rosario wrote:
>
> The UI, document upload and document renamer execute in different 
> contexts, it is not possible for them to share the web session. The 
> alternative would be to access the event log of the document and extract 
> the first entry which would indicate the user who created the document and 
> expose this to the context of the renaming template here: 
> https://gitlab.com/mayan-edms/document_renaming/blob/master/document_renaming/models.py#L80
>
> The even log app uses Django activity stream (
> https://github.com/justquick/django-activity-stream/blob/master/actstream/models.py)
>  
> and they provide a reverse reference. Something like 
>
> document.target_actions.first().actor 
>
> should give your the user instance.
>
> The second problem would be to get the user's sequence dynamically. 
> Sequences are passed to the rename template's context as 'sequence_XXX' 
> variables because Django's template engine doesn't allow parameter method 
> calling.
>
> In my mind the easiest path would be to ditch Django's template engine and 
> use something like Jinja2 (http://jinja.pocoo.org/) which allows method 
> calls with parameters and the renaming template itself can contain all the 
> required logic:
>
> {% set username = document.target_actions.first.actor.username %}  {{ 
> username }}-{{ Sequence.objects.get(slug=%username%).next_value() }}
>
> Provided you have already the sequences created for each use. This is all 
> from the top of my head without any actual test of course :)
>
>
> On Friday, January 8, 2016 at 4:52:07 PM UTC-4, Rachael Sewell wrote:
>>
>> Roberto,
>>
>> I'm working with this app currently. I have two document types:
>>
>>    1. Specs 
>>    2. Memos
>>    
>> Memos will be renamed according to the logged in user. I would like to 
>> create a number like this <username>-<incremental number>. For example: 
>> "rachael.sewell-00"
>>
>> I've tried a few things, but it seems the user is not accessible in the 
>> view. Any pointers to where I should be updating code would be helpful to 
>> add this. Thanks for the continued help.
>>
>> Rachael
>>
>> On Friday, December 18, 2015 at 10:34:13 AM UTC-8, Rachael Sewell wrote:
>>>
>>> Hello,
>>>
>>> I'd like to know if there is already a way to add an automatically 
>>> created document number to a document. For example I would like to start 
>>> with a initial document number of AN00001 and increment (AN00002, AN00003) 
>>> for each additional doc. Does this functionality already exist? If not 
>>> could it be added to the core or would it need to be a custom application? 
>>> Any pointers on how to get started on this would be helpful as well. 
>>>
>>> Thanks,
>>> Rachael
>>>
>>

-- 

--- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to