You are here: Home Plone Python Functions Python Functions (Basic)
Search
Advanced Search…
E-Mail

Webmail: webmail.wyden.com

E-Mail Preferences: postfix.wyden.com/users

E-Mail Administration: postfix.wyden.com

Statistics
Total: 463
Total Pages: 284
Total Folders: 87
Total Files: 18
Total Links: 26
Last modification: 03.02.2012 16:00
 

Python Functions (Basic)

by Wyden Silvan last modified 12.03.2011 11:52

Get the property 'target' from the object 'saction' or returns 'no' if it doesnt' exists:

saction.get('target','no')

Looks if the object has the attribut or not:

hasattr('context', 'title)

Returns the attribute of an object or none

getattr(context, 'exclude_from_nav', None)

Return if an integer is even or odd:

return x%2 and 'Odd' or 'Even'

Gives back the index of a repeat item (in tal):

repeat['item'].index

Function to get variables from url like mypage?variable=test

context.REQUEST.form['mygetvar']

To get the path of the object without fetching it

'/'.join(context.getPhysicalPath() -> /wyden/wyden/plone/python-functions/
object.getPhysicalPath() or context.getPath() or return '/'.join(absolutePath)

to get the URL of the underlying object, usually to provide a link to it:

context.absolute_url()  

to get the URL of the portal:

context.portal_url()

get the selected Language

python:context.portal_languages.getPreferredLanguage()

to localized time

python: toLocalizedTime(here.end_date,long_format=1)

Returns all objects of type ATLink in the folder banner:

return context.banner.objectValues('ATLink')

Cut the description or the text to a lenght of 50 digits and append ... But it doesnt cut words!

python:plone_view.cropText(mylongstring,50, ' …')

Get path of parents:

python:context.aq_parent.absolute_url()

Convert text to string or to integer

python:str(mytext) python:int(mynumber)

Replace all substrings in a string

python:mystring.replace('replace_me', 'replacement')

Get URL of a link object:

python:item.getObject().remote_url()

Get context of an object:

python:context = aq_inner(self.context) -> from Acquisition import aq_inner

 Look if an item is excluded from navigation:

python:node['item'].exclude_from_nav;

Get Object from ULR:

obj = context.restrictedTraverse(url)

 Get the user rights of an object:

context.acl_users.getLocalRolesForDisplay(context)

 Create dictionary in python:

mydict python:{'de':'deutscher Text', 'fr':'text francais'}
devalue python:mydict['de']