From stepht at duke.edu Wed Oct 21 14:23:54 2009 From: stepht at duke.edu (Stephanie Thirolle) Date: Wed, 21 Oct 2009 10:23:54 -0400 Subject: [triangle-zpug] Quick help w/a python statement Message-ID: <4ADF197A.5010902@duke.edu> Hey All, I'm a relative python newbie and the following is driving me crazy. If anyone has ANY suggestions, I'd be most grateful. I've got a FileField called 'execsummlink' and I want to test if the field contains a file (or was left blank). I've tried the following, but no matter what I do, I get a 'true' result regardless of whether the field contains anything: tal:condition="execsummlink" tal:condition="python: len(execsummlink) > 0" tal:condition="python: exists('here/execsummlink')" tal:condition="python: hasattr(here, 'execsummlink')" tal:condition="python: getattr(here, 'execsummlink')" ALL of these work with other field types (Image, string, text, etc) -- any ideas why they won't work with a file field and what will??? Thanks SO much for your time. Cheers! Stephanie -- Stephanie Thirolle Director of Web Projects Nicholas School of the Environment Duke University stepht at duke.edu office:(919)613-8702 cell:(919)225-0742 www.nicholas.duke.edu From rob_lineberger at med.unc.edu Wed Oct 21 15:13:17 2009 From: rob_lineberger at med.unc.edu (Rob Lineberger) Date: Wed, 21 Oct 2009 11:13:17 -0400 Subject: [triangle-zpug] Quick help w/a python statement In-Reply-To: <4ADF197A.5010902@duke.edu> References: <4ADF197A.5010902@duke.edu> Message-ID: <1256137997.8026.17.camel@phantasy-star> That sounds like the Plone wall we've all hit at one time or another. I'm not somewhere that I can test this, but you might try this statement to test if execsumlink is an instance of file: tal:condition="python: isinstance(execsummlink, file)" Also, it might be returning true because it thinks execsummlink is a string. Try tal:condition="here/execsummlink." On Wed, 2009-10-21 at 10:23 -0400, Stephanie Thirolle wrote: > Hey All, > I'm a relative python newbie and the following is driving me crazy. > If anyone has ANY suggestions, I'd be most grateful. > > I've got a FileField called 'execsummlink' and I want to test if the > field contains a file (or was left blank). I've tried the following, > but no matter what I do, I get a 'true' result regardless of whether the > field contains anything: > > tal:condition="execsummlink" > tal:condition="python: len(execsummlink) > 0" > tal:condition="python: exists('here/execsummlink')" > tal:condition="python: hasattr(here, 'execsummlink')" > tal:condition="python: getattr(here, 'execsummlink')" > > ALL of these work with other field types (Image, string, text, etc) -- > any ideas why they won't work with a file field and what will??? > > Thanks SO much for your time. > > Cheers! > Stephanie > From bgailer at gmail.com Wed Oct 21 15:39:36 2009 From: bgailer at gmail.com (bob gailer) Date: Wed, 21 Oct 2009 11:39:36 -0400 Subject: [triangle-zpug] Quick help w/a python statement In-Reply-To: <4ADF197A.5010902@duke.edu> References: <4ADF197A.5010902@duke.edu> Message-ID: <4ADF2B38.7030904@gmail.com> Stephanie Thirolle wrote: > Hey All, > I'm a relative python newbie and the following is driving me > crazy. If anyone has ANY suggestions, I'd be most grateful. > > I've got a FileField called 'execsummlink' and I want to test if the > field contains a file (or was left blank). I've tried the following, > but no matter what I do, I get a 'true' result regardless of whether > the field contains anything: > > tal:condition="execsummlink" > tal:condition="python: len(execsummlink) > 0" > tal:condition="python: exists('here/execsummlink')" > tal:condition="python: hasattr(here, 'execsummlink')" > tal:condition="python: getattr(here, 'execsummlink')" > > ALL of these work with other field types (Image, string, text, etc) -- > any ideas why they won't work with a file field and what will??? \ Try tal:condition="python: execsummlink.filename" -- Bob Gailer Chapel Hill NC 919-636-4239 From stephan_altmueller at unc.edu Wed Oct 21 16:34:54 2009 From: stephan_altmueller at unc.edu (Stephan Altmueller) Date: Wed, 21 Oct 2009 12:34:54 -0400 Subject: [triangle-zpug] Quick help w/a python statement In-Reply-To: <4ADF197A.5010902@duke.edu> References: <4ADF197A.5010902@duke.edu> Message-ID: <4ADF382E.2050105@unc.edu> Hi Stephanie, Depending on where this template code executes (Zope3 view or a page template in a skin layer and also persmissions) the following might work: tal:condition="context/execsummlink/get_size" or try tal:condition="python: context.getExecsummlink().get_size() There are a million ways to do the same thing in Plone, I am sure there are 5 other way ;-) If you can, it would be a good idea to turn this in to a Zope 3 view, then you can stick this kind of logic into a pure python function which is much easier to debug. Hope this helps, -- Stephan Stephanie Thirolle wrote: > Hey All, > I'm a relative python newbie and the following is driving me > crazy. If anyone has ANY suggestions, I'd be most grateful. > > I've got a FileField called 'execsummlink' and I want to test if the > field contains a file (or was left blank). I've tried the following, > but no matter what I do, I get a 'true' result regardless of whether > the field contains anything: > > tal:condition="execsummlink" > tal:condition="python: len(execsummlink) > 0" > tal:condition="python: exists('here/execsummlink')" > tal:condition="python: hasattr(here, 'execsummlink')" > tal:condition="python: getattr(here, 'execsummlink')" > > ALL of these work with other field types (Image, string, text, etc) -- > any ideas why they won't work with a file field and what will??? > > Thanks SO much for your time. > > Cheers! > Stephanie > -- ------------------------------------------------- OASIS welcomes your feedback: http://oasis.unc.edu/client-feedback Stephan Altmueller Applications Analyst, Enterprise Applications Office of Arts and Sciences Information Services University of North Carolina at Chapel Hill CB 3056, 06 Howell Hall Chapel Hill, NC 27599-3056 919.448.5936 (direct line) stephan_altmueller at unc.edu AIM: oasisaltmuell http://oasis.unc.edu/people/altmuell