<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: plone code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 17 Aug 2008 06:52:55 GMT</pubDate>
    <description>DZone Snippets: plone code</description>
    <item>
      <title>review_state</title>
      <link>http://snippets.dzone.com/posts/show/3331</link>
      <description>// retrieve review state&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from Products.CMFCore.utils import getToolByName&lt;br /&gt;wtool = getToolByName(context, "portal_workflow")&lt;br /&gt;wf_state = wtool.getInfoFor(obj,'review_state',None)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 19 Jan 2007 14:52:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3331</guid>
      <author>morlandi (Mario Orlandi)</author>
    </item>
    <item>
      <title>object_delete</title>
      <link>http://snippets.dzone.com/posts/show/3281</link>
      <description>// object_delete&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from AccessControl import Unauthorized&lt;br /&gt;from Products.CMFPlone.utils import transaction_note&lt;br /&gt;from Products.CMFPlone import PloneMessageFactory as _&lt;br /&gt;&lt;br /&gt;REQUEST = context.REQUEST&lt;br /&gt;if REQUEST.get('REQUEST_METHOD', 'GET').upper() == 'GET':&lt;br /&gt;    raise Unauthorized, 'This method can not be accessed using a GET request'&lt;br /&gt;&lt;br /&gt;parent = context.aq_inner.aq_parent&lt;br /&gt;parent.manage_delObjects(context.getId())&lt;br /&gt;&lt;br /&gt;message = _(u'${title} has been deleted.',&lt;br /&gt;            mapping={u'title' : context.title_or_id()})&lt;br /&gt;transaction_note('Deleted %s' % context.absolute_url())&lt;br /&gt;&lt;br /&gt;context.plone_utils.addPortalMessage(message)&lt;br /&gt;return state.set(status = 'success')&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 14 Jan 2007 12:18:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3281</guid>
      <author>morlandi (Mario Orlandi)</author>
    </item>
    <item>
      <title>Result Object Methods</title>
      <link>http://snippets.dzone.com/posts/show/3011</link>
      <description>// Assuming that we have set result to being a result object we can use the following methods:&lt;br /&gt;&lt;br /&gt;len(result)&lt;br /&gt;&lt;code&gt;&lt;br /&gt;     this will show the number rows returned (which would be 3 in the example above).&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;result.names()&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    a list of all the column headings, returning a list containing emp_id, first, last and salary&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;result.tuples()&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    returns a list of tuples in our example:&lt;br /&gt;&lt;br /&gt;    [(43, 'Bob', 'Roberts', 50000),&lt;br /&gt;     (101, 'Cheeta', 'leCat', 100000),&lt;br /&gt;     (99, 'Jane', 'Junglewoman', 100001)]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;result.dictionaries()&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    will return a list of dictionaries, with one dictionary for each row:&lt;br /&gt;&lt;br /&gt;    [{'emp_id': 42, 'first': 'Bob','last': 'Roberts', 'salary': 50000},&lt;br /&gt;     {'emp_id': 101, 'first: 'Cheeta', 'last': 'leCat', 'salary': 100000},&lt;br /&gt;     {'emp_id': 99, 'first': 'Jane', 'last': 'Junglewoman', 'salary': 100001}]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;result.data_dictionary()&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    returns a dictionary describing the structure of the results table. &lt;br /&gt;&lt;br /&gt;The dictionary has the key name, type, null and width. &lt;br /&gt;Name and type are self explanatory, null is true if that field may contain a null value and width is the width in characters of the field. &lt;br /&gt;Note that null and width may not be set by some Database Adapters.&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;result.asRDB()&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    displays the result in a similar way to a relational database. &lt;br /&gt;&lt;br /&gt;The DTML below displays the result below:&lt;br /&gt;    &lt;pre&gt;&lt;br /&gt;      &lt;dtml-var "list_all_employees().asRDB()"&gt;&lt;br /&gt;    &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    ... displays ...&lt;br /&gt;&lt;br /&gt;    emp_id first last salary&lt;br /&gt;    42 Bob Roberts 50000&lt;br /&gt;    101 Cheeta leCat 100000&lt;br /&gt;    99 Jane Junglewoman 100001&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;result[0][1]&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    return row 0, column 1 of the result, bob in this example. &lt;br /&gt;&lt;br /&gt;Be careful using this method as changes in the schema will cause unexpected results. &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 17 Nov 2006 17:11:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3011</guid>
      <author>morlandi (Mario Orlandi)</author>
    </item>
    <item>
      <title>Dead Content Type Inspector</title>
      <link>http://snippets.dzone.com/posts/show/2932</link>
      <description>&lt;code&gt;&lt;br /&gt;print "Dead Content Type Inspector"&lt;br /&gt;print&lt;br /&gt;&lt;br /&gt;for i in context.portal_catalog.uniqueValuesFor('portal_type'):&lt;br /&gt;   if i in context.portal_types: continue&lt;br /&gt;   print i&lt;br /&gt;   results = context.portal_catalog(portal_type=i)&lt;br /&gt;   for i in results:&lt;br /&gt;       print i.getURL()&lt;br /&gt;   print &lt;br /&gt;   print&lt;br /&gt;&lt;br /&gt;return printed&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 30 Oct 2006 22:26:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2932</guid>
      <author>morlandi (Mario Orlandi)</author>
    </item>
    <item>
      <title>Db Connection</title>
      <link>http://snippets.dzone.com/posts/show/2840</link>
      <description>//  eGenix mxODBC Database Connection: connection string sample&lt;br /&gt;&lt;code&gt;&lt;br /&gt;DSN=LocalServer;&lt;br /&gt;DATABASE=GammaMedidata;&lt;br /&gt;UID=sa;&lt;br /&gt;PWD=******;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;//  eGenix mxODBC Database Connection: connection string sample&lt;br /&gt;&lt;code&gt;&lt;br /&gt;DRIVER=SQL Server;&lt;br /&gt;SERVER=(local);&lt;br /&gt;UID=sa;&lt;br /&gt;PWD=****;&lt;br /&gt;DATABASE=wam&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;//  MySQL connection string sample&lt;br /&gt;&lt;code&gt;&lt;br /&gt;dbcobraf@www2.cobraf.com cobraf 'password'&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 16 Oct 2006 18:23:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2840</guid>
      <author>morlandi (Mario Orlandi)</author>
    </item>
    <item>
      <title>contentItems()</title>
      <link>http://snippets.dzone.com/posts/show/2831</link>
      <description>&lt;code&gt;&lt;br /&gt;p.Members.contentItems(filter={'portal_type':['Folder',]})&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;// Search a specific Purchase, then remove all SalesAttachment from it&lt;br /&gt;&lt;code&gt;&lt;br /&gt;purchaseBrains = context.portal_catalog.searchResults( portal_type='Purchase', getPurchaseId = 1000 )&lt;br /&gt;if len(purchaseBrains)==1:&lt;br /&gt;    purchase = purchaseBrains[0].getObject()&lt;br /&gt;    print purchase &lt;br /&gt;    objs = purchase.contentItems(filter={'portal_type':['SalesAttachment',]})&lt;br /&gt;    ids = []&lt;br /&gt;    for obj in objs:&lt;br /&gt;        id = obj[0]&lt;br /&gt;        print id&lt;br /&gt;        ids.append(id)&lt;br /&gt;    print ids&lt;br /&gt;    purchase.manage_delObjects(ids=ids)&lt;br /&gt;return printed&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 15 Oct 2006 14:00:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2831</guid>
      <author>morlandi (Mario Orlandi)</author>
    </item>
    <item>
      <title>get folder object</title>
      <link>http://snippets.dzone.com/posts/show/2829</link>
      <description>&lt;code&gt;&lt;br /&gt;portal = context.portal_url.getPortalObject()&lt;br /&gt;photosFolder = getattr(portal,'photos')&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;photosFolder = portal.restrictedTraverse('projects/picture-masking-service/incoming-pictures/')&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 15 Oct 2006 13:58:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2829</guid>
      <author>morlandi (Mario Orlandi)</author>
    </item>
    <item>
      <title>getHomeFolder</title>
      <link>http://snippets.dzone.com/posts/show/2828</link>
      <description>// retrieving the home folder of the current user&lt;br /&gt;&lt;code&gt;&lt;br /&gt;m = pm.getAuthenticatedMember()&lt;br /&gt;pm = context.portal_membership&lt;br /&gt;mf = pm.getHomeFolder()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;// retrieving the home folder of the a specific user&lt;br /&gt;&lt;code&gt;&lt;br /&gt;mf = pm.getHomeFolder(userId)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 15 Oct 2006 13:51:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2828</guid>
      <author>morlandi (Mario Orlandi)</author>
    </item>
    <item>
      <title>redirect</title>
      <link>http://snippets.dzone.com/posts/show/2826</link>
      <description>&lt;code&gt;&lt;br /&gt;request = context.REQUEST&lt;br /&gt;...&lt;br /&gt;request.RESPONSE.redirect(request.HTTP_REFERER)&lt;br /&gt;...&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 15 Oct 2006 13:49:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2826</guid>
      <author>morlandi (Mario Orlandi)</author>
    </item>
  </channel>
</rss>
