Chris,

  You need to put your functions into a module (e.g., my_settings.py). 
 That module must be on your Python path.  I think I placed the file in the 
"mayan" sub-directory, but any directory in the path should work.  In 
addition, you must have the "import my_settings" statement in your 
"local_settings.py" local settings file. (Note: you must specify that 
Mayan-EDMS should read your local settings upon startup.)  Finally, you 
must make a dictionary entry for your function in the 
METADATA_AVAILABLE_VALIDATORS.  Your function should raise an exception if 
the data is not correct and your function MAY return a value if you want to 
normalize data.  Having your function use other metadata in the validation 
is somewhat tricky.  Your function will have to access the data that is 
returned by the form. It took me a lot of poking around to find how this 
can be done and I am not sure to this day whether the method will work 
reliably in all cases.

Gary


On Wednesday, October 8, 2014 7:32:05 AM UTC-4, Christoph H. Larsen wrote:
>
> Dear Mathias,
>
> Thanks a lot for your quick reply and the link, which is clearly an more 
> elaborate version of the rather terse earlier discussion here.
> However (did I say Django dummy before? ;-)!), allow me to ask some stupid 
> questions:
> While I am clear about the additional settings in the local_settings.py 
> file, I am note sure where to stick the function itself. Gary mentioned 
> that the "validator function [...]
> is placed in a module read by the settings routine". Here comes the dummy 
> question: How do I do that?
> Placing a my_settings.py with the contents of Gary's function into the 
> mayan/settings folder does not work... Seems I got stuck with the module 
> creation issue.
> Sorry for pestering you. Any assistance is hugely appreciated.
> Chris
>
>
> On Wednesday, 8 October 2014 14:06:40 UTC+3, Mathias Behrle wrote:
>>
>> * Christoph H. Larsen: " [Mayan EDMS: 882] Re: Using python functions 
>> within 
>>   Mayan EDMS" (Wed, 8 Oct 2014 03:36:12 -0700 (PDT)): 
>>
>> Hi Chris, 
>>
>> did you have a look at: 
>>
>> https://github.com/mayan-edms/mayan-edms/pull/58 
>>
>> Cheers, 
>> Mathias 
>>
>> > Dear Roberto, dear Gary, 
>> > 
>> > I thought I posted a reply earlier today but it seems it did not get 
>> > through. If it did, my apologies for double-posting. 
>> > Due to my lack of in-depth experience with Django, I beg for some more 
>> > detailed information how to get Python functions working with automatic 
>> > metadata. 
>> > Here is a use case: 
>> > I plan to have time-constrained documentation sitting inside Mayan 
>> EDMS, 
>> > such as warranty certificates, or performance verification 
>> certificates, 
>> > which are valid for only N days. 
>> > Ideally, the "Valid through" metadata should automagically calculate a 
>> > default expiry date from different metadata, e.g. purchase date, or 
>> > revision date. 
>> > Also, it would of course be great to then automatically change flags 
>> from 
>> > green to yellow, or whatever. 
>> > This needs a wee bit of Python magic (which I am OK with on the Python 
>> > side) with the default metadata as a function. But how can I, as Django 
>> > dummy, implement this (step by step) inside Mayan EDMS. 
>> > Thanks a million! 
>> > 
>> > Chris 
>> > 
>> > 
>> > On Wednesday, 10 September 2014 16:26:09 UTC+3, Gary D Walborn wrote: 
>> > > 
>> > > Roberto, 
>> > > 
>> > >   Thanks.  I should have mentioned that I figured that out the other 
>> day 
>> > > by looking at the source code.   Be aware that the current code does 
>> not 
>> > > override "__builtins__", so it is possible to enter code in the 
>> LOOKUP area 
>> > > to do anything that you want.  For example, 
>> > > 
>> > > __import__('my_custom_module').my_function() 
>> > > 
>> > > I think that is probably not intended, but it works. 
>> > > 
>> > > Gary W. 
>> > > 
>> > > On Tuesday, September 9, 2014 2:22:12 PM UTC-4, Roberto Rosario 
>> wrote: 
>> > >> 
>> > >> Create you own custom settings.py file in mayan/settings directory: 
>> > >> 
>> > >> # my_settings.py file 
>> > >> from my_custom_module import my_function 
>> > >> 
>> > >> METADATA_AVAILABLE_MODELS = {'my_function': my_function} 
>> > >> 
>> > >> and launch Mayan with --settings=mayan.settings.my_settings.py 
>> > >> 
>> > >> now my_function should be available in the namespace of your 
>> metadata 
>> > >> lookup snippets. 
>> > >> 
>> > >> 
>> > >> On Tuesday, September 9, 2014 8:59:02 AM UTC-4, Gary D Walborn 
>> wrote: 
>> > >>> 
>> > >>> I found a work-around for this, but I think it is also a huge 
>> security 
>> > >>> hole in Mayan-EDMS.  I think I'll use it, but it will probably go 
>> away 
>> > >>> when (if) the security hole is fixed. :-(   
>> > >>> 
>> > >>> On Thursday, September 4, 2014 3:48:38 PM UTC-4, Gary D Walborn 
>> wrote: 
>> > >>>> 
>> > >>>> I have written a python function (lets call it 'options') that 
>> returns 
>> > >>>> a list of strings.  I would like to use this function to populate 
>> the 
>> > >>>> drop-down lists in a metadata type.  I have tried all sorts of 
>> ways to 
>> > >>>> do this, and none of them seem to work.  The documentation is very 
>> scant 
>> > >>>> on this subject.  Can anyone provide any information on how this 
>> is 
>> > >>>> supposed to work? 
>> > >>>> 
>> > >>>> Thanks, 
>> > >>>> 
>> > >>>> Gary Walborn 
>> > >>>> 
>> > >>>> 
>> > 
>>
>>
>>
>> -- 
>>
>>     Mathias Behrle 
>>     PGP/GnuPG key availabable from any keyserver, ID: 0x8405BBF6 
>>
>

-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to