Getting the day from a Timestamp / gvibda
Hi! I have a query returning a timestamp column from my interbase 6 database using the Going Virtual database adapter. I want to extract the values of the day/month/year ... from the variable. I tried this <dtml-var date_column fmt="%d"> for the day, but it doesn't work, probably because the variable's type is not the usual python DateTime. Similarly, this <dtml-var "_.DateTime(date_column).day()"> doesn't work either. <dtml-var date_column> renders a nice string representation, so I don't really understand why the above will not work, but that's certainly my lack of python concept. Ok, now I found out that date_column is actually of a type called Timestamp, which is defined in some way in the gvibda sources. That class has a method tuple, def tuple(self): return (self.year, self.month, self.day, self.hour, self.minute, self.second) which seems to return everything I need. But how do I call that thing? In fact, every time I write something like <dtml-var "date_column.tuple()"> or <dtml-var "_.date_column.tuple()"> I get some Unauthorized exception for no apparent reason. Wow... Now, much text, most important question: How can I extract the values I need from that variable? Can anyone help, please? Oliver -- Oliver Sturm / <sturm@oliver-sturm.de>
On Tuesday 22 May 2001 15:47, Oliver Sturm wrote:
Hi!
I have a query returning a timestamp column from my interbase 6 database using the Going Virtual database adapter. I want to extract the values of the day/month/year ... from the variable. I tried this
<dtml-var date_column fmt="%d">
for the day, but it doesn't work, probably because the variable's type is not the usual python DateTime. Similarly, this
<dtml-var "_.DateTime(date_column).day()">
Have you tried with: <dtml-var "_.DateTime(date_column).strftime('%d')"> ?? Gitte
On 22.05.2001 15:53:07 +0200 Gitte Wange <gitte@mmmanager.org> wrote:
I have a query returning a timestamp column from my interbase 6 database using the Going Virtual database adapter. I want to extract the values of the day/month/year ... from the variable. I tried this
<dtml-var date_column fmt="%d">
for the day, but it doesn't work, probably because the variable's type is not the usual python DateTime. Similarly, this
<dtml-var "_.DateTime(date_column).day()">
Have you tried with: <dtml-var "_.DateTime(date_column).strftime('%d')">
Yes, I had tried that before. It gives me a "NameError" with the "Error value" being "date_column". Thanks... Oliver -- Oliver Sturm / <sturm@oliver-sturm.de>
On Tuesday 22 May 2001 16:20, Oliver Sturm wrote:
On 22.05.2001 15:53:07 +0200 Gitte Wange <gitte@mmmanager.org> wrote:
I have a query returning a timestamp column from my interbase 6 database using the Going Virtual database adapter. I want to extract the values of the day/month/year ... from the variable. I tried this
<dtml-var date_column fmt="%d">
for the day, but it doesn't work, probably because the variable's type is not the usual python DateTime. Similarly, this
<dtml-var "_.DateTime(date_column).day()">
Have you tried with: <dtml-var "_.DateTime(date_column).strftime('%d')">
Yes, I had tried that before. It gives me a "NameError" with the "Error value" being "date_column". Thanks...
Oliver
Maybe it's the date_column that is wrong??? Gitte
On 22.05.2001 16:22:13 +0200 Gitte Wange <gitte@mmmanager.org> wrote:
I have a query returning a timestamp column from my interbase 6 database using the Going Virtual database adapter. I want to extract the values of the day/month/year ... from the variable. I tried this
<dtml-var date_column fmt="%d">
for the day, but it doesn't work, probably because the variable's type is not the usual python DateTime. Similarly, this
<dtml-var "_.DateTime(date_column).day()">
Have you tried with: <dtml-var "_.DateTime(date_column).strftime('%d')">
Yes, I had tried that before. It gives me a "NameError" with the "Error value" being "date_column". Thanks...
Maybe it's the date_column that is wrong???
You were right, but that doesn't change my problem... I had mistyped the column's name when I retried that version in response to your mail. Now, what I really get as an error message is an "AttributeError", the "Error value" being "__int__". I had that before and I think it means that the variable can't be rendered to an integer, as python thinks it should because it doesn't know that the variable is supposed to contain a date value. Oliver -- Oliver Sturm / <sturm@oliver-sturm.de>
On 22 May 2001, at 15:47, Oliver Sturm wrote:
I have a query returning a timestamp column from my interbase 6 database using the Going Virtual database adapter. I want to extract the values of the day/month/year ... from the variable. I tried this
Here are two Extension methods I use.. Pick one def FormatDate(date,format="%a, %B %d %H:%M"): """format the date object""" if not date: return "[unknown]" t = list(date.tuple()) if len(t) < 9: t.append(0) t.append(0) t.append(-1) return time.strftime(format,t) def DateTimeCast(s): """convert an interbase Timestamp to datetime""" if not s: return s try: return apply(DateTime,s.tuple()) except AttributeError: return DateTime(s) <dtml-var "_.DateTime(date_column.tuple()).day()"> Based on this, I think this DTML might work Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax netmeeting: ils://ils.murkworks.com AOL-IM: BKClements
On 22.05.2001 10:57:34 -0400 Brad Clements <bkc@murkworks.com> wrote:
I have a query returning a timestamp column from my interbase 6 database using the Going Virtual database adapter. I want to extract the values of the day/month/year ... from the variable. I tried this
Here are two Extension methods I use.. Pick one
[ ... cut ... ]
<dtml-var "_.DateTime(date_column.tuple()).day()">
Based on this, I think this DTML might work
Very nice idea. But I keep having the same problem with the method FormatDate and with that line you give above: When I try to use them (for the method I created a python script and have this DTML: <dtml-var "FormatDate(date_column, '%d/%m/%Y')"> ), a message box pops up telling me my permissions are not good enough. I get the chance to re-enter my authorization, but it doesn't work. Although I have a "Manager" account and the Manager role has all permissions that is has by default (seems like that's actually all there are, apart from "Take possession"), I get an Unauthorized exception sooner or later. What funny kind of additional permission setting is needed for this function? Thanks a lot, Brad, for your help! Oliver -- Oliver Sturm / <sturm@oliver-sturm.de>
On 22.05.2001 10:57:34 -0400 Brad Clements <bkc@murkworks.com> wrote:
I have a query returning a timestamp column from my interbase 6 database using the Going Virtual database adapter. I want to extract the values of the day/month/year ... from the variable. I tried this
Here are two Extension methods I use.. Pick one
[ ... cut ... ] I have it now. I tried the very same thing with an external method and suddenly it works. Seems like there's no access to the tuple() method as long as Zope's in the way... I'd still be interested if there's a way to get around this limitation. Thanks again, Brad! Oliver -- Oliver Sturm / <sturm@oliver-sturm.de>
On 23 May 2001, at 11:18, Oliver Sturm wrote:
I have it now. I tried the very same thing with an external method and suddenly it works. Seems like there's no access to the tuple() method as long as Zope's in the way... I'd still be interested if there's a way to get around this limitation. Thanks again, Brad!
Yes, two ways to fix this. Modify the gvib DA to participate in product roles, or hack with __allow_access_to_unprotected_subobjects__=1 Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax netmeeting: ils://ils.murkworks.com AOL-IM: BKClements
On 23.05.2001 09:29:43 -0400 Brad Clements <bkc@murkworks.com> wrote:
I have it now. I tried the very same thing with an external method and suddenly it works. Seems like there's no access to the tuple() method as long as Zope's in the way... I'd still be interested if there's a way to get around this limitation. Thanks again, Brad!
Yes, two ways to fix this. Modify the gvib DA to participate in product roles, or hack with
__allow_access_to_unprotected_subobjects__=1
Wow. Isn't that a rather complicated way to do Something Real Simple(tm)? Thanks very much, I don't think I could have guessed that :-) Oliver Sturm / <sturm@oliver-sturm.de> -- Key ID: 71D86996 Fingerprint: 8085 5C52 60B8 EFBD DAD0 78B8 CE7F 38D7 71D8 6996
participants (3)
-
Brad Clements -
Gitte Wange -
Oliver Sturm