Skip to content

Commit 483e304

Browse files
author
Richard Jones
committed
lots of date/interval related changes: more relaxed date format for input
1 parent 3197d49 commit 483e304

File tree

6 files changed

+75
-17
lines changed

6 files changed

+75
-17
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Fixed:
2828
. #503340 ] creating issue with [asignedto=p.ohly]
2929
. #502949 ] index view for non-issues and redisplay
3030
. #503793 ] changing assignedto resets nosy list
31+
. lots of date/interval related changes:
32+
- more relaxed date format for input
33+
- handle None for date/interval properties
3134

3235

3336
2002-01-08 - 0.4.0b1

roundup/cgi_client.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: cgi_client.py,v 1.99 2002-01-16 03:02:42 richard Exp $
18+
# $Id: cgi_client.py,v 1.100 2002-01-16 07:02:57 richard Exp $
1919

2020
__doc__ = """
2121
WWW request handler (also used in the stand-alone server).
@@ -309,7 +309,8 @@ def shownode(self, message=None):
309309
', '.join(props.keys())}
310310
elif self.form.has_key('__note') and self.form['__note'].value:
311311
message = _('note added')
312-
elif self.form.has_key('__file'):
312+
elif (self.form.has_key('__file') and
313+
self.form['__file'].filename):
313314
message = _('file added')
314315
else:
315316
message = _('nothing changed')
@@ -1115,9 +1116,17 @@ def parsePropsFromForm(db, cl, form, nodeid=0):
11151116
elif isinstance(proptype, hyperdb.Password):
11161117
value = password.Password(form[key].value.strip())
11171118
elif isinstance(proptype, hyperdb.Date):
1118-
value = date.Date(form[key].value.strip())
1119+
value = form[key].value.strip()
1120+
if value:
1121+
value = date.Date(form[key].value.strip())
1122+
else:
1123+
value = None
11191124
elif isinstance(proptype, hyperdb.Interval):
1120-
value = date.Interval(form[key].value.strip())
1125+
value = form[key].value.strip()
1126+
if value:
1127+
value = date.Interval(form[key].value.strip())
1128+
else:
1129+
value = None
11211130
elif isinstance(proptype, hyperdb.Link):
11221131
value = form[key].value.strip()
11231132
# see if it's the "no selection" choice
@@ -1173,6 +1182,9 @@ def parsePropsFromForm(db, cl, form, nodeid=0):
11731182

11741183
#
11751184
# $Log: not supported by cvs2svn $
1185+
# Revision 1.99 2002/01/16 03:02:42 richard
1186+
# #503793 ] changing assignedto resets nosy list
1187+
#
11761188
# Revision 1.98 2002/01/14 02:20:14 richard
11771189
# . changed all config accesses so they access either the instance or the
11781190
# config attriubute on the db. This means that all config is obtained from

roundup/date.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: date.py,v 1.16 2002-01-08 11:56:24 richard Exp $
18+
# $Id: date.py,v 1.17 2002-01-16 07:02:57 richard Exp $
1919

2020
__doc__ = """
2121
Date, time and time interval handling.
@@ -153,6 +153,8 @@ def __sub__(self, other):
153153

154154
def __cmp__(self, other):
155155
"""Compare this date to another date."""
156+
if other is None:
157+
return 1
156158
for attr in ('year', 'month', 'day', 'hour', 'minute', 'second'):
157159
r = cmp(getattr(self, attr), getattr(other, attr))
158160
if r: return r
@@ -170,7 +172,7 @@ def pretty(self):
170172
self.day, self.hour, self.minute, self.second, 0, 0, 0))
171173

172174
def set(self, spec, offset=0, date_re=re.compile(r'''
173-
(((?P<y>\d\d\d\d)-)?((?P<m>\d\d)-(?P<d>\d\d))?)? # yyyy-mm-dd
175+
(((?P<y>\d\d\d\d)-)?((?P<m>\d\d?)-(?P<d>\d\d?))?)? # yyyy-mm-dd
174176
(?P<n>\.)? # .
175177
(((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d))?)? # hh:mm:ss
176178
(?P<o>.+)? # offset
@@ -254,6 +256,8 @@ def __init__(self, spec, sign=1):
254256

255257
def __cmp__(self, other):
256258
"""Compare this interval to another interval."""
259+
if other is None:
260+
return 1
257261
for attr in ('year', 'month', 'day', 'hour', 'minute', 'second'):
258262
r = cmp(getattr(self, attr), getattr(other, attr))
259263
if r: return r
@@ -379,6 +383,9 @@ def test():
379383

380384
#
381385
# $Log: not supported by cvs2svn $
386+
# Revision 1.16 2002/01/08 11:56:24 richard
387+
# missed an import _
388+
#
382389
# Revision 1.15 2002/01/05 02:27:00 richard
383390
# I18N'ification
384391
#

roundup/hyperdb.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: hyperdb.py,v 1.48 2002-01-14 06:32:34 richard Exp $
18+
# $Id: hyperdb.py,v 1.49 2002-01-16 07:02:57 richard Exp $
1919

2020
__doc__ = """
2121
Hyperdatabase implementation, especially field types.
@@ -348,11 +348,11 @@ def create(self, **propvalues):
348348
raise TypeError, 'new property "%s" not a Password'%key
349349

350350
elif isinstance(prop, Date):
351-
if not isinstance(value, date.Date):
351+
if value is not None and not isinstance(value, date.Date):
352352
raise TypeError, 'new property "%s" not a Date'%key
353353

354354
elif isinstance(prop, Interval):
355-
if not isinstance(value, date.Interval):
355+
if value is not None and not isinstance(value, date.Interval):
356356
raise TypeError, 'new property "%s" not an Interval'%key
357357

358358
# make sure there's data where there needs to be
@@ -370,9 +370,11 @@ def create(self, **propvalues):
370370
# convert all data to strings
371371
for key, prop in self.properties.items():
372372
if isinstance(prop, Date):
373-
propvalues[key] = propvalues[key].get_tuple()
373+
if propvalues[key] is not None:
374+
propvalues[key] = propvalues[key].get_tuple()
374375
elif isinstance(prop, Interval):
375-
propvalues[key] = propvalues[key].get_tuple()
376+
if propvalues[key] is not None:
377+
propvalues[key] = propvalues[key].get_tuple()
376378
elif isinstance(prop, Password):
377379
propvalues[key] = str(propvalues[key])
378380

@@ -414,8 +416,12 @@ def get(self, nodeid, propname, default=_marker, cache=1):
414416

415417
# possibly convert the marshalled data to instances
416418
if isinstance(prop, Date):
419+
if d[propname] is None:
420+
return None
417421
return date.Date(d[propname])
418422
elif isinstance(prop, Interval):
423+
if d[propname] is None:
424+
return None
419425
return date.Interval(d[propname])
420426
elif isinstance(prop, Password):
421427
p = password.Password()
@@ -561,12 +567,12 @@ class or a KeyError is raised.
561567
raise TypeError, 'new property "%s" not a Password'% key
562568
propvalues[key] = value = str(value)
563569

564-
elif isinstance(prop, Date):
570+
elif value is not None and isinstance(prop, Date):
565571
if not isinstance(value, date.Date):
566572
raise TypeError, 'new property "%s" not a Date'% key
567573
propvalues[key] = value = value.get_tuple()
568574

569-
elif isinstance(prop, Interval):
575+
elif value is not None and isinstance(prop, Interval):
570576
if not isinstance(value, date.Interval):
571577
raise TypeError, 'new property "%s" not an Interval'% key
572578
propvalues[key] = value = value.get_tuple()
@@ -1041,6 +1047,9 @@ def Choice(name, *options):
10411047

10421048
#
10431049
# $Log: not supported by cvs2svn $
1050+
# Revision 1.48 2002/01/14 06:32:34 richard
1051+
# . #502951 ] adding new properties to old database
1052+
#
10441053
# Revision 1.47 2002/01/14 02:20:15 richard
10451054
# . changed all config accesses so they access either the instance or the
10461055
# config attriubute on the db. This means that all config is obtained from

test/test_dates.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_dates.py,v 1.7 2001-08-13 23:01:53 richard Exp $
18+
# $Id: test_dates.py,v 1.8 2002-01-16 07:02:57 richard Exp $
1919

2020
import unittest, time
2121

@@ -35,6 +35,10 @@ def testDate(self):
3535
ae = self.assertEqual
3636
date = Date("2000-04-17")
3737
ae(str(date), '2000-04-17.00:00:00')
38+
date = Date("2000-4-7")
39+
ae(str(date), '2000-04-07.00:00:00')
40+
date = Date("2000-4-17")
41+
ae(str(date), '2000-04-17.00:00:00')
3842
date = Date("01-25")
3943
y, m, d, x, x, x, x, x, x = time.gmtime(time.time())
4044
ae(str(date), '%s-01-25.00:00:00'%y)
@@ -83,6 +87,9 @@ def suite():
8387

8488
#
8589
# $Log: not supported by cvs2svn $
90+
# Revision 1.7 2001/08/13 23:01:53 richard
91+
# fixed a 2.1-ism
92+
#
8693
# Revision 1.6 2001/08/07 00:24:43 richard
8794
# stupid typo
8895
#

test/test_db.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_db.py,v 1.13 2002-01-14 02:20:15 richard Exp $
18+
# $Id: test_db.py,v 1.14 2002-01-16 07:02:57 richard Exp $
1919

2020
import unittest, os, shutil
2121

2222
from roundup.hyperdb import String, Password, Link, Multilink, Date, \
2323
Interval, Class, DatabaseError
2424
from roundup.roundupdb import FileClass
25+
from roundup import date
2526

2627
def setupSchema(db, create):
2728
status = Class(db, "status", name=String())
@@ -33,7 +34,7 @@ def setupSchema(db, create):
3334
status.create(name="resolved")
3435
Class(db, "user", username=String(), password=Password())
3536
Class(db, "issue", title=String(), status=Link("status"),
36-
nosy=Multilink("user"))
37+
nosy=Multilink("user"), deadline=Date(), foo=Interval())
3738
FileClass(db, "file", name=String(), type=String())
3839
db.commit()
3940

@@ -76,9 +77,19 @@ def testChanges(self):
7677
props = self.db.issue.getprops()
7778
keys = props.keys()
7879
keys.sort()
79-
self.assertEqual(keys, ['fixer', 'id', 'nosy', 'status', 'title'])
80+
self.assertEqual(keys, ['deadline', 'fixer', 'foo', 'id', 'nosy',
81+
'status', 'title'])
8082
self.db.issue.set('5', status='2')
8183
self.db.issue.get('5', "status")
84+
85+
a = self.db.issue.get('5', "deadline")
86+
self.db.issue.set('5', deadline=date.Date())
87+
self.assertNotEqual(a, self.db.issue.get('5', "deadline"))
88+
89+
a = self.db.issue.get('5', "foo")
90+
self.db.issue.set('5', foo=date.Interval('-1d'))
91+
self.assertNotEqual(a, self.db.issue.get('5', "foo"))
92+
8293
self.db.status.get('2', "name")
8394
self.db.issue.get('5', "title")
8495
self.db.issue.find(status = self.db.status.lookup("in-progress"))
@@ -274,6 +285,15 @@ def suite():
274285

275286
#
276287
# $Log: not supported by cvs2svn $
288+
# Revision 1.13 2002/01/14 02:20:15 richard
289+
# . changed all config accesses so they access either the instance or the
290+
# config attriubute on the db. This means that all config is obtained from
291+
# instance_config instead of the mish-mash of classes. This will make
292+
# switching to a ConfigParser setup easier too, I hope.
293+
#
294+
# At a minimum, this makes migration a _little_ easier (a lot easier in the
295+
# 0.5.0 switch, I hope!)
296+
#
277297
# Revision 1.12 2001/12/17 03:52:48 richard
278298
# Implemented file store rollback. As a bonus, the hyperdb is now capable of
279299
# storing more than one file per node - if a property name is supplied,

0 commit comments

Comments
 (0)