Chris,
I think this is something that you should probably do on the database
side. Nonetheless, I did get the following code to work.
import datetime
global_contract_date = datetime.datetime.now().date()
def is_valid_contract_date(value):
from dateutil import parser
from django.core.exceptions import ValidationError
try:
dt = parser.parse(value)
except ValueError:
raise ValidationError('Invalid date')
global global_contract_date
global_contract_date = dt.date()
return dt.date().isoformat()
def is_valid_expiry_date(value):
import datetime
global global_contract_date
if global_contract_date:
expiry_date = global_contract_date+datetime.timedelta(days=365)
else:
expiry_date = datetime.datetime.not().date()
return expiry_date.isoformat()
*I would highly recommend that you do not do this! *There are just too many
things that can go wrong with this code. For example, because there is an
"Update" checkbox when editing metadata, I can bring up the metadata,
change the "contract_date", uncheck the "Update" box behind
"contract_date", and click "Save". The "expiry_date" will be updated with
the new value of "contract_date", but "contract_date" will not actually
change. The end result is that the dates no longer correspond. Also,
there are not constraints to make the "expiry_date" dependent on the
"contract_date". As a result, I could add the "expiry_date" metadata type
to a document that does not even possess the "contract_date" metadata type,
making it completely meaningless. There would have to be a major
"overhaul" of the metadata subsystem to make these kinds of things work
correctly.
I think the use of validators (as I have implemented them) should be
limited to validating and, perhaps, normalizing the data (as there is
little harm that can be done by the latter).
Gary
On Wed, Oct 8, 2014 at 4:07 AM, Christoph H. Larsen <
[email protected]> wrote:
> Dear All,
>
> I am afraid I need a wee bit more help here, which is entirely related to
> my limited experience with Django. Apologies.
> Here is what I would like to do:
> Imagine you have documents uploaded into Mayan EDMS that expire after a
> given period of time, such as warranty documents.
> So, I should be able to create a metadata set, that contains both the date
> the documents gets uploaded into an "valid" folder, and and automatically
> completed expiry metatdata field which, in Python speak, would do something
> like as a minimum:
>
> from datetime import timedelta
> VALIDITY_PERIOD = 365
> expiry_date = date_of_purchase + timedelta(days=VALIDITY_PERIOD)
> In the stanza above, expiry_date should be calculated from another metadata
> field called, for instance date_of_purchase. How can this be achieved (for
> dummies!) in Mayan EDMS?
> I guess once I have a worknig example on how to include Python functions in
> detail, I can easily do other things.
> 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
>>>>>
>>>>> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Mayan EDMS" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/mayan-edms/p-d9PvY3mc4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
Gary D. Walborn
[email protected]
--
---
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.