[Zope] Zope database file grows when no one is modifying it

Thomas Bennett bennetttm at appstate.edu
Fri Oct 19 13:41:25 EDT 2007


On Friday 19 October 2007 11:12, Jonathan wrote:
> ----- Original Message -----
> From: "Jamie O'Keefe" <jokeefe at jamesokeefe.org>
> To: <zope at zope.org>
> Sent: Friday, October 19, 2007 11:05 AM
> Subject: Re: [Zope] Zope database file grows when no one is modifying it
>
> > Any suggestions as to how to thwart such attempts besides requiring
> > user accounts for even the most minor edit and then remaining vigilant
> > about who get accounts?
>
> Not a zope-based solution, but how about using 'captcha' images if spambots
> are your problem?
>
> Jonathan
>
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )

or for a Zope based solution (and if you have PIL and PIL fonts installed) 
use the following as an external method and stick the call to the method
inside your form.  Of course instead of putting the random number in a 
hidden field you could also write it to the current directory as a document 
and then get the value from the document when you process it, by the way
you have to create your code to verify the image number where ever you
process the form.  In the example below I compare cost to picnum.

There are also features in PIL to add effects to the image if you want
slant, swirl or anything.

Thomas

***************************************************

from PIL import Image,ImageDraw,ImageFont
import random
import os
from StringIO import StringIO
from OFS.Image import manage_addImage

# CREATED AUGUST 8, 2007 - Thomas Bennett
# REQUIREMENTS
#   PIL FONTS FROM http://effbot.org/pil/pilfonts.zip
#   PIL FROM http://www.pythonware.com/products/pil/

def random_number_image(self):

  #GENERATE A RANDOM NUMBER OF 5 DIGITS
  mynumtext = str(random.randrange(10000,99999,1))
  my_image_id = "number.jpg"

  #DEFINE FONT PATH AND NAME
  fontpath="/usr/lib/python2.4/site-packages/pilfonts"
  fontname="ncenB14.pil"

  # CREATE A TEXT IMAGE USING MYNUMTEXT
  textImg = Image.new('RGB',(75,25),(56,56,50))               # INSTANTIATE A NEW IMAGE (a dark gray box)
  tmpDraw = ImageDraw.Draw(textImg)                           # DRAW THE IMAGE INTO TEMP
  textFont = ImageFont.load(os.path.join(fontpath,fontname))  # LOAD A FONT FOR THE IMAGE
  tmpDraw.text((15,1), mynumtext, font = textFont)            # PLACE TEXT IN NEW IMAGE

  # PUT THE IMAGE INTO MEMORY AND SAVE IMAGE TO MEMORY
  imageFile = StringIO()
  textImg.save(imageFile,"JPEG")

  # IF THERE IS A NUMBER.JPG IN THE CURRETN DIRECTORY, DELETE IT SO UNDO WON'T BUILD UP
  if my_image_id in self.objectIds():
    self.manage_delObjects([my_image_id])
  manage_addImage(self,"number.jpg",imageFile)

  # WRITE THE IMAGE AND FORM CODE TO THE PAGE
  text = '\n<input type="hidden" name="cost" value="%s">' %mynumtext
  text = text+'\n<font face="Verdana, Arial, Helvetica, sans-serif" size="1">\n<b>Please enter the number pictured below.</b></font>'
  text = text+'<br>\n<img src="%s" alt="%s"/><input type=text name="picnum" value="">\n<br />' %(my_image_id,mynumtext)
  return text

*************************************************************************



-- 
====================================================================
Thomas McMillan Grant Bennett		Appalachian State University
Operations & Systems Analyst		P O Box 32026
University Library				Boone, North Carolina 28608
(828) 262 6587

They say a picture is worth a thousand words.  As videos could be 25 pictures per second and might last several minutes, how many words is that? 
- Linux Journal, July 2007

Library Systems Help Desk: http://www.library.appstate.edu/help/
====================================================================


More information about the Zope mailing list