Message from discussion
Colander: Is preparer supported in schema binding?
Received: by 10.236.190.68 with SMTP id d44mr38757101yhn.1.1321201716880;
Sun, 13 Nov 2011 08:28:36 -0800 (PST)
X-BeenThere: pylons-discuss@googlegroups.com
Received: by 10.101.55.11 with SMTP id h11ls11089419ank.4.gmail; Sun, 13 Nov
2011 08:28:32 -0800 (PST)
Received: by 10.236.168.70 with SMTP id j46mr31351762yhl.2.1321201712164;
Sun, 13 Nov 2011 08:28:32 -0800 (PST)
Received: by 10.236.168.70 with SMTP id j46mr31351758yhl.2.1321201712150;
Sun, 13 Nov 2011 08:28:32 -0800 (PST)
Return-Path: <mariano.m...@gmail.com>
Received: from mail-gx0-f180.google.com (mail-gx0-f180.google.com [209.85.161.180])
by gmr-mx.google.com with ESMTPS id a27si5935932yhi.2.2011.11.13.08.28.32
(version=TLSv1/SSLv3 cipher=OTHER);
Sun, 13 Nov 2011 08:28:32 -0800 (PST)
Received-SPF: pass (google.com: domain of mariano.m...@gmail.com designates 209.85.161.180 as permitted sender) client-ip=209.85.161.180;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of mariano.m...@gmail.com designates 209.85.161.180 as permitted sender) smtp.mail=mariano.m...@gmail.com; dkim=pass (test mode) header...@gmail.com
Received: by mail-gx0-f180.google.com with SMTP id v5so12461640ggn.25
for <pylons-discuss@googlegroups.com>; Sun, 13 Nov 2011 08:28:32 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=date:from:to:subject:message-id:mail-followup-to:references
:mime-version:content-type:content-disposition:in-reply-to
:user-agent;
bh=oqkn4m/zWyZpG/J2h7Gmz8szKInzpb/6KzAqp1OQA1E=;
b=qHojwjlMQvDiBghrKlBY0OPKE/JLQl4lzVQRx3HKTpLbTKqY1UCKDLj91bT+QQam/j
K5EQxFq6MoT8exo5pcbCEgAb46ZOnuHp727bZq4EQJMRick+xOr0GvJEXE6dYxWLpVd9
mFpQ+Jf/wNixlkTuZA8w20oVX/bNp+stVACuk=
Received: by 10.236.179.2 with SMTP id g2mr9026333yhm.27.1321201711433;
Sun, 13 Nov 2011 08:28:31 -0800 (PST)
Return-Path: <mariano.m...@gmail.com>
Received: from localhost ([186.182.146.74])
by mx.google.com with ESMTPS id y1sm6515532anj.18.2011.11.13.08.28.28
(version=TLSv1/SSLv3 cipher=OTHER);
Sun, 13 Nov 2011 08:28:29 -0800 (PST)
Date: Sun, 13 Nov 2011 13:28:25 -0300
From: Mariano Mara <mariano.m...@gmail.com>
To: pylons-discuss@googlegroups.com
Subject: Re: Colander: Is preparer supported in schema binding?
Message-ID: <20111113162825.GA4236@suspiria>
Mail-Followup-To: pylons-discuss@googlegroups.com
References: <20111108044357.GA6013@suspiria>
<CAMysB04930kz1anT_k0WX_2KPiQWRxtg8nUcqjJjA6hdhYJ...@mail.gmail.com>
<20111108125221.GB2806@suspiria>
<CAMysB07hZWhRaP+ERZvrCxSiM34EkxXD3kc=NQCsdgyXDm8...@mail.gmail.com>
<CAMysB07CvZ5+df3Ka78VgSXVRaWQ72R44_Zxt2g_Zdo_gyr...@mail.gmail.com>
<20111109220938.GB20393@suspiria>
<20111110175720.GA2842@suspiria>
<4EBD6E16.9040...@simplistix.co.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <4EBD6E16.9040...@simplistix.co.uk>
User-Agent: Mutt/1.5.21 (2010-09-15)
On 11.11.11 18:48, Chris Withers wrote:
> On 10/11/2011 17:57, Mariano Mara wrote:
> >
> >I even ran the tests and it worked ok (and my problem seems to be fixed too).
> >It would be great if somebody with great colander jutsu can say why such
> >behavior was not implemented.
>
> I implemented the feature, but I don't used deferreds.
> (I didn't like the idea myself, but that doesn't mean they're bad...)
>
> I also have my finger in the xlrd pie, and personally I wish xlrd
> would just create date objects on parsing the .xls rather than the
> annoying number-you-need-to-bend-over-backwards-to-turn-into-a-date
> ;-)
>
> Why not just store the book *and* the preparer as attributes of the
> Schema instance, then they can both get access to the state?
>
> cheers,
>
> Chris
Hi Chris, thanks for your input, I'm already following Eric's advice and I'm
storing datemode in a previous step (users has the option to validate their
excel file and while at it, I retrieve the data and store it), precluding the
need for a deferred, which proved to be a really tough adversary.
I have even ended creating my own type to have a better error message for users and
so far it seems to be working (actually I don't need the serialize method so I
didn't test it):
class XLSDate(object):
"""
http://docs.pylonsproject.org/projects/colander/dev/extending.html
"""
def serialize(self, node, appstruct):
if appstruct is colander.null:
return colander.null
if not isinstance(appstruct, datetime.datetime):
raise colander.Invalid(node, _('{0} is not a value that can be '
'parse into the excel internal date representation'.\
format(appstruct)))
return appstruct and 'true' or 'false'
def deserialize(self, node, cstruct):
if cstruct is colander.null or cstruct==u'':
return colander.null
try:
return float(cstruct)
except ValueError, e:
raise(colander.Invalid(node, _('{0} is not value that can be '
'parse into a valid Excel date'.format(cstruct))))