Back to index

plone3  3.1.7
isExpired.py
Go to the documentation of this file.
00001 ## Script (Python) "isExpired"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=content=None
00008 ##title=Find out if the object is expired
00009 ##
00010 
00011 from DateTime import DateTime
00012 from Products.CMFPlone.utils import base_hasattr
00013 from Products.CMFPlone.utils import safe_callable
00014 
00015 if not content:
00016     content = context
00017 expiry = None
00018 
00019 # NOTE: We also accept catalog brains as 'content' so that the catalog-based
00020 # folder_contents will work. It's a little magic, but it works.
00021 
00022 # ExpirationDate should have an ISO date string, which we need to
00023 # convert to a DateTime
00024 
00025 # Try DC accessor first
00026 if base_hasattr(content, 'ExpirationDate'):
00027     expiry=content.ExpirationDate
00028 
00029 # Try the direct way
00030 if not expiry and base_hasattr(content, 'expires'):
00031     expiry=content.expires
00032 
00033 # See if we have a callable
00034 if safe_callable(expiry):
00035     expiry = expiry()
00036 
00037 # Convert to DateTime if necessary, ExpirationDate may return 'None'
00038 if expiry and expiry != 'None' and same_type(expiry, ''):
00039     expiry = DateTime(expiry)
00040 
00041 if same_type(expiry, DateTime()) and expiry.isPast():
00042         return 1
00043 return 0