[Grok-dev] Re: Adding a image to form_fields

Christian Theune ct at gocept.com
Thu Aug 30 05:45:09 EDT 2007


Am Mittwoch, den 29.08.2007, 22:15 +0200 schrieb Philipp von
Weitershausen:
> This will present the user with a drop down list of image filenames. If 
> you want something more comfortable, consider writing a vocabulary where 
> the items of the dropdown list can have pretty titles instead of the raw 
> values. My book explains how to do that ("Sources and Vocabularies" 
> chapter).

Notice that zc.sourcefactory makes writing sources much easier:

class AnimalImageSource(zc.sourcefactory.basic.BasicSourceFactory):

    base = os.path.join(os.path.dirname(__file__), 'static')

    def getValues(self):
	return glob.glob(self.base,  '*.jpg'))

    def getTitle(self, value):
        file = open(os.path.join(self.base, value))
        return <magic metadata extraction happens>(file).title images>.

In your form_fields you can then use:

    Choice(title=..., source=AnimalImageSource())


Christian



More information about the Grok-dev mailing list