Tareq Alam

i have promises to keep and miles to go before i sleep – Robert Frost

add contents and publish in plone using python script March 30, 2009

add a external method
in the method’s python file

Newfolder = context.invokeFactory(“Folder”, id=”NEWFOLDERINPLONE”, title=”NEWFOLDERINPLONE”,path=’/’.join(context.getPhysicalPath()))
this will add a new folder in the contexts directory
To publish this folder automatically by code try this magic

Newfolderobj = getattr(context, Newfolder, None)
review_state = Newfolderobj.portal_workflow.getInfoFor(Newfolderobj, ‘review_state’, ”)
if not review_state == ‘published’:
Newfolderobj.portal_workflow.doActionFor(Newfolderobj,”publish”,comment=”publised programmatically”)

it will be published in site on the fly…

to add page template

idict = { ‘id’ : ’step1Page’
, ‘type’: ‘page template’
, ‘body’: page_template_body # variable can be a content of a pt file
, ‘workflow_action’: ‘publish’
, ‘workflow_comment’: ‘This item published programmatically’

}

Newfolderobj.manage_addProduct['PageTemplates'].manage_addPageTemplate(id=idict['id'])
oi = getattr(Newfolderobj,idict['id'])
oi.pt_edit(idict['body'],’text/html’)

this will add a page template in new folder
together


def main(self):

# Example code:

# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
context = self
try:
Newfolder = context.invokeFactory("Folder", id="NewFolderUnusedId", title="NewFolderUnusedId",path='/'.join(context.getPhysicalPath()))
except:
Newfolder = 'NewFolderUnusedId'

Newfolderobj = getattr(context, Newfolder, None)

review_state = Newfolderobj.portal_workflow.getInfoFor(Newfolderobj, 'review_state', '')
if not review_state == 'published':
Newfolderobj.portal_workflow.doActionFor(Newfolderobj,"publish",comment="publised programmatically")
f=open("somefile.pt","r")
page_template_body = f.read()
f.close()
idict = { 'id' : 'step1Page'
, 'type': 'page template'
, 'body': page_template_body
, 'workflow_action': 'publish'
, 'workflow_comment': 'This item published programmatically'

}

Newfolderobj.manage_addProduct['PageTemplates'].manage_addPageTemplate(id=idict['id'])
oi = getattr(Newfolderobj,idict['id'])
oi.pt_edit(idict['body'],'text/html')
return true

 

Add new widget in PloneFormGen March 30, 2009

PloneFormGen is a nice tool to add dynamic forms in plone
There are lot of different form fields in PloneFormGen
but I was in need of a new type of widget in my form
this is how i did that

first to learn how it works..
http://plone.org/products/pfgdatagrid
download this product and install it after installing DataGridWidget and PloneFormGen

now you can add datagrid widget directly in plone form folder

to use a new type of widget as like data grid widget you can do the following steps
1. copy the PFGDataGrid and paste with name as you like for example PFGNoneMultiSelectionWidget
2. inside the folder change in the following files
content
__init__.py will contain import nonemultiselectionff
rename the datagridff.py to nonemultiselectionff.py
in every file in every folder
also in nonemultiselectionff.py you have to define the schema and the function
for this you need to study and this is different for different widgets
you have to define functions so that you can take the widget from the products folder
follow example in datagridfield and in ploneFormGen fields.py for ideas
or call me ;)
change PFGDataGrid to PFGNoneMultiSelectionWidget
and change FormDataGridField to FormNoneMultiSelectionWidget

 

install python 2.4.3 in ubuntu 8.10 March 15, 2009

Filed under: Ubuntu, Zope, ploneCMS, python — tareqalam @ 2:14 pm
Tags: , ,

I have got error at first when i tried to install python 2.4.3 in ubuntu 8.10

error is something like this:

/usr/bin/install -c -m 644 ./LICENSE /usr/local/lib/python2.4/LICENSE.txt
PYTHONPATH=/usr/local/lib/python2.4   \
./python -Wi -tt /usr/local/lib/python2.4/compileall.py \
-d /usr/local/lib/python2.4 -f \
-x ‘badsyntax|site-packages’ /usr/local/lib/python2.4
*** buffer overflow detected ***: ./python terminated
then i searched the net for solution i got this

https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/286334

and the solution isgo inside the python 2.4.3 directory

$ ./configure CC=gcc-4.2 # works
$ ./configure OPT=”-g -O0″ # works

then

$ make

$sudo make install

then the python 2.4.3 will be installed

I need that version of python to run the bootstrap.py of plone svn

now I am happy that the buildout is running ..

Thanks