Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

Packing ZODB from command line

Packing ZODB from command line

$wget.exe --delete-after --user=admin --password=***** "http://localhost:8090/Control_Panel/manage_pack?days:float=0"


or

"D:\services\support\curl-7.17.0\curl" -d -v -f -u admin:password http://localhost:8090/Control_Panel/manage_pack?days:float=0

Send a message with zope

// description of your code here


      # get a correct mail

      searching_obj = context
      interesatuen_epostak = []

      while interesatuen_epostak == []:
            if searching_obj.interesatuen_epostak != []:
               for m in searching_obj.interesatuen_epostak:
                   if '@' in m:
                      interesatuen_epostak.append(m)
            searching_obj = searching_obj.aq_parent


      # send a mail

      try:
        mailhost=getattr(context, context.superValues('Mail Host')[0].id)
      except:
        raise AttributeError, "cant find a Mail Host object"

      for i in interesatuen_epostak: 
       mMsg = "To: " + i + "\n"
       mMsg = mMsg + "From: intranet@zenbaki.es\n"
       mMsg = mMsg + "Mime-Version: 1.0\n"
       mMsg = mMsg + "Content-Type: text/html; charset=ISO-8859-1\n\n"

       mMsg = mMsg + "<html><head></head><body bgcolor='#dddddd'>"
       mMsg = mMsg + "<h1>Aldaketak:</h1>"
       mMsg = mMsg + "<p>"+user.getUserName()

       if user.getUserName()[-1] in ['a','e','i','o','u']:
          mMsg = mMsg + "k,"
       else:
          mMsg = mMsg + "ek,"

       mMsg = mMsg + " '<a href='"+obj.absolute_url()+"'>"+obj.title+"</a>' HTML fitxategia gehitu zuen "
       mMsg = mMsg + "'<a href='"+container_folder.absolute_url()+"'>"+container_folder.id+"</a>' izendako karpetan.</p>"
       mMsg = mMsg + "</body></html>"

       mSubj = "[intranet] '"+obj.title+"' HTML fitxategia gehituta izan zen"
       mailhost.send(mMsg, subject=mSubj, encode='base64')

IPython shell

// "%PYTHON%" -i -c ..."
from Zope2 import configure; 
import os; 
configure(os.environ['ZOPE_CONFIG_FILE']); 

import Zope2; 
app=Zope2.app(); 

ns={'__name__':'blah','app':app};

import IPython; 
IPython.Shell.IPShell(user_ns=ns).mainloop(sys_exit=1);

SQL export in zope

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:

return context.sql.ordered-sql2csv(context.sql.exportOrders().dictionaries(), ["fullname","email","phone","address","town","postcode","children","adults","comments"])


## Script (Python) "ordered-sql2csv"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=sql, fo
##title=
##
container.REQUEST.RESPONSE.setHeader("Content-Type", "text/csv", 0)
sep = ""
for dk in fo:
  container.REQUEST.RESPONSE.write(sep + dk)
  sep = ","
sep = "\n"

for rec in sql:
  for i in range(0,len(fo)):
    data=rec[fo[i]]
    dl = str(data).split(',')
    data1 = " ".join(dl)
    container.REQUEST.RESPONSE.write(sep + str(data1))
    sep = ","
  sep="\n"

Check that a user has permission on all parents in Zope

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.

Create a Python script in your acquisition path (I used portal_skins/custom) named can_view and paste in this code:
permission = "View"
try:
  object=context
  if not object.acquiredRolesAreUsedBy( permission ):
    for p in object.rolesOfPermission( permission ):
      if p['selected']:
        if p['name'] in user.getRoles():
          return 1
  else:
   return 1
except:
    pass
return 0
Then you can check the permission in TAL like this:


<div tal:condition="some_object/can_view">
...
</div>
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS