<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: zope code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 05:43:12 GMT</pubDate>
    <description>DZone Snippets: zope code</description>
    <item>
      <title>Packing ZODB from command line</title>
      <link>http://snippets.dzone.com/posts/show/5477</link>
      <description>Packing ZODB from command line&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$wget.exe --delete-after --user=admin --password=***** "http://localhost:8090/Control_Panel/manage_pack?days:float=0"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;"D:\services\support\curl-7.17.0\curl" -d -v -f -u admin:password http://localhost:8090/Control_Panel/manage_pack?days:float=0&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 08 May 2008 14:13:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5477</guid>
      <author>morlandi (Mario Orlandi)</author>
    </item>
    <item>
      <title>Send a message with zope</title>
      <link>http://snippets.dzone.com/posts/show/3551</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;      # get a correct mail&lt;br /&gt;&lt;br /&gt;      searching_obj = context&lt;br /&gt;      interesatuen_epostak = []&lt;br /&gt;&lt;br /&gt;      while interesatuen_epostak == []:&lt;br /&gt;            if searching_obj.interesatuen_epostak != []:&lt;br /&gt;               for m in searching_obj.interesatuen_epostak:&lt;br /&gt;                   if '@' in m:&lt;br /&gt;                      interesatuen_epostak.append(m)&lt;br /&gt;            searching_obj = searching_obj.aq_parent&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;      # send a mail&lt;br /&gt;&lt;br /&gt;      try:&lt;br /&gt;        mailhost=getattr(context, context.superValues('Mail Host')[0].id)&lt;br /&gt;      except:&lt;br /&gt;        raise AttributeError, "cant find a Mail Host object"&lt;br /&gt;&lt;br /&gt;      for i in interesatuen_epostak: &lt;br /&gt;       mMsg = "To: " + i + "\n"&lt;br /&gt;       mMsg = mMsg + "From: intranet@zenbaki.es\n"&lt;br /&gt;       mMsg = mMsg + "Mime-Version: 1.0\n"&lt;br /&gt;       mMsg = mMsg + "Content-Type: text/html; charset=ISO-8859-1\n\n"&lt;br /&gt;&lt;br /&gt;       mMsg = mMsg + "&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body bgcolor='#dddddd'&gt;"&lt;br /&gt;       mMsg = mMsg + "&lt;h1&gt;Aldaketak:&lt;/h1&gt;"&lt;br /&gt;       mMsg = mMsg + "&lt;p&gt;"+user.getUserName()&lt;br /&gt;&lt;br /&gt;       if user.getUserName()[-1] in ['a','e','i','o','u']:&lt;br /&gt;          mMsg = mMsg + "k,"&lt;br /&gt;       else:&lt;br /&gt;          mMsg = mMsg + "ek,"&lt;br /&gt;&lt;br /&gt;       mMsg = mMsg + " '&lt;a href='"+obj.absolute_url()+"'&gt;"+obj.title+"&lt;/a&gt;' HTML fitxategia gehitu zuen "&lt;br /&gt;       mMsg = mMsg + "'&lt;a href='"+container_folder.absolute_url()+"'&gt;"+container_folder.id+"&lt;/a&gt;' izendako karpetan.&lt;/p&gt;"&lt;br /&gt;       mMsg = mMsg + "&lt;/body&gt;&lt;/html&gt;"&lt;br /&gt;&lt;br /&gt;       mSubj = "[intranet] '"+obj.title+"' HTML fitxategia gehituta izan zen"&lt;br /&gt;       mailhost.send(mMsg, subject=mSubj, encode='base64')&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 20 Feb 2007 10:27:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3551</guid>
      <author>nando.quintana (Nando Quintana)</author>
    </item>
    <item>
      <title>IPython shell</title>
      <link>http://snippets.dzone.com/posts/show/3415</link>
      <description>// "%PYTHON%" -i -c ..."&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from Zope2 import configure; &lt;br /&gt;import os; &lt;br /&gt;configure(os.environ['ZOPE_CONFIG_FILE']); &lt;br /&gt;&lt;br /&gt;import Zope2; &lt;br /&gt;app=Zope2.app(); &lt;br /&gt;&lt;br /&gt;ns={'__name__':'blah','app':app};&lt;br /&gt;&lt;br /&gt;import IPython; &lt;br /&gt;IPython.Shell.IPShell(user_ns=ns).mainloop(sys_exit=1);&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 05 Feb 2007 20:57:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3415</guid>
      <author>morlandi (Mario Orlandi)</author>
    </item>
    <item>
      <title>SQL export in zope</title>
      <link>http://snippets.dzone.com/posts/show/1653</link>
      <description>Takes the result of a Zope SQL query, and an ordered list of field names, and outputs a CSV file as the resultant web page.  Should be called like this:&lt;br /&gt;&lt;br /&gt;return context.sql.ordered-sql2csv(context.sql.exportOrders().dictionaries(), ["fullname","email","phone","address","town","postcode","children","adults","comments"])&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;## Script (Python) "ordered-sql2csv"&lt;br /&gt;##bind container=container&lt;br /&gt;##bind context=context&lt;br /&gt;##bind namespace=&lt;br /&gt;##bind script=script&lt;br /&gt;##bind subpath=traverse_subpath&lt;br /&gt;##parameters=sql, fo&lt;br /&gt;##title=&lt;br /&gt;##&lt;br /&gt;container.REQUEST.RESPONSE.setHeader("Content-Type", "text/csv", 0)&lt;br /&gt;sep = ""&lt;br /&gt;for dk in fo:&lt;br /&gt;  container.REQUEST.RESPONSE.write(sep + dk)&lt;br /&gt;  sep = ","&lt;br /&gt;sep = "\n"&lt;br /&gt;&lt;br /&gt;for rec in sql:&lt;br /&gt;  for i in range(0,len(fo)):&lt;br /&gt;    data=rec[fo[i]]&lt;br /&gt;    dl = str(data).split(',')&lt;br /&gt;    data1 = " ".join(dl)&lt;br /&gt;    container.REQUEST.RESPONSE.write(sep + str(data1))&lt;br /&gt;    sep = ","&lt;br /&gt;  sep="\n"&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 08 Mar 2006 08:24:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1653</guid>
      <author>MatthewWilkes (Matthew Wilkes)</author>
    </item>
    <item>
      <title>Check that a user has permission on all parents in Zope</title>
      <link>http://snippets.dzone.com/posts/show/484</link>
      <description>If you need to be sure that a user can view an object, you need to check the View permission not only on the object but also all of its parents.  To do this, I slightly modified the script at http://zopelabs.com/cookbook/1018022911 so that it uses the context object and specified the View permission.&lt;br /&gt;&lt;br /&gt;Create a Python script in your acquisition path (I used portal_skins/custom) named can_view and paste in this code:&lt;br /&gt;&lt;code&gt;permission = "View"&lt;br /&gt;try:&lt;br /&gt;  object=context&lt;br /&gt;  if not object.acquiredRolesAreUsedBy( permission ):&lt;br /&gt;    for p in object.rolesOfPermission( permission ):&lt;br /&gt;      if p['selected']:&lt;br /&gt;        if p['name'] in user.getRoles():&lt;br /&gt;          return 1&lt;br /&gt;  else:&lt;br /&gt;   return 1&lt;br /&gt;except:&lt;br /&gt;    pass&lt;br /&gt;return 0&lt;br /&gt;&lt;/code&gt;Then you can check the permission in TAL like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;div tal:condition="some_object/can_view"&gt;&lt;br /&gt;  ...&lt;br /&gt;&lt;/div&gt;</description>
      <pubDate>Tue, 19 Jul 2005 22:41:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/484</guid>
      <author>georgehotelling (George Hotelling)</author>
    </item>
  </channel>
</rss>
