Back to index

plone3  3.1.7
checkSelected.py
Go to the documentation of this file.
00001 ## Script (Python) "Check Selected"
00002 ##title=Check if a field should be 'selected' based on value and vocabulary
00003 ##bind container=container
00004 ##bind context=context
00005 ##bind namespace=
00006 ##bind script=script
00007 ##bind subpath=traverse_subpath
00008 ##parameters=item, value, contenttypes=0
00009 
00010 site_charset = context.getCharset()
00011 item = context.unicodeEncode(item, site_charset=site_charset)
00012 value = context.unicodeEncode(value, site_charset=site_charset)
00013 
00014 # map from mimetypes used in allowable_content_types to mimetypes that are stored
00015 # in the base unit
00016 mapping = {
00017     'text/x-python' : 'text/python-source',
00018     'text/restructured': 'text/x-rst',
00019 }
00020 
00021 if contenttypes:
00022     item = mapping.get(item, item)
00023 
00024 uitem = unicode(repr(item))
00025 
00026 if value is not None and \
00027    value == item or \
00028    unicode(repr(value)) == uitem:
00029     return 1
00030 
00031 if isinstance(value, basestring):
00032     value.capitalize()
00033 
00034 # Maybe list?
00035 try:
00036     for v in value:
00037         if uitem == unicode(repr(v)):
00038             return 1
00039 except TypeError:
00040     pass
00041 
00042 return unicode(repr(value)) == uitem