Skip to content

Commit 6c8ca0a

Browse files
author
Justus Pendleton
committed
only validate timezone if they set it
they can clear the timezone which resulted in tz==None and an exception
1 parent 64cc40b commit 6c8ca0a

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

templates/classic/detectors/userauditor.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020
#
21-
#$Id: userauditor.py,v 1.7 2007-09-06 16:52:19 jpend Exp $
21+
#$Id: userauditor.py,v 1.8 2007-09-11 21:28:29 jpend Exp $
2222

2323
def audit_user_fields(db, cl, nodeid, newvalues):
2424
''' Make sure user properties are valid.
@@ -42,19 +42,20 @@ def audit_user_fields(db, cl, nodeid, newvalues):
4242
raise ValueError, 'Role "%s" does not exist'%rolename
4343

4444
if newvalues.has_key('timezone'):
45-
# validate the timezone by attempting to use it
46-
# before we store it to the db.
47-
import roundup.date
48-
import datetime
49-
try:
50-
tz = newvalues['timezone']
51-
TZ = roundup.date.get_timezone(tz)
52-
dt = datetime.datetime.now()
53-
local = TZ.localize(dt).utctimetuple()
54-
except IOError:
55-
raise ValueError, 'Timezone "%s" does not exist' % tz
56-
except ValueError:
57-
raise ValueError, 'Timezone "%s" exceeds valid range [-23...23]' % tz
45+
tz = newvalues['timezone']
46+
if tz:
47+
# if they set a new timezone validate the timezone by attempting to
48+
# use it before we store it to the db.
49+
import roundup.date
50+
import datetime
51+
try:
52+
TZ = roundup.date.get_timezone(tz)
53+
dt = datetime.datetime.now()
54+
local = TZ.localize(dt).utctimetuple()
55+
except IOError:
56+
raise ValueError, 'Timezone "%s" does not exist' % tz
57+
except ValueError:
58+
raise ValueError, 'Timezone "%s" exceeds valid range [-23...23]' % tz
5859

5960
def init(db):
6061
# fire before changes are made

templates/minimal/detectors/userauditor.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020
#
21-
#$Id: userauditor.py,v 1.6 2007-09-06 16:52:20 jpend Exp $
21+
#$Id: userauditor.py,v 1.7 2007-09-11 21:28:29 jpend Exp $
2222

2323
def audit_user_fields(db, cl, nodeid, newvalues):
2424
''' Make sure user properties are valid.
@@ -41,19 +41,20 @@ def audit_user_fields(db, cl, nodeid, newvalues):
4141
raise ValueError, 'Role "%s" does not exist'%rolename
4242

4343
if newvalues.has_key('timezone'):
44-
# validate the timezone by attempting to use it
45-
# before we store it to the db.
46-
import roundup.date
47-
import datetime
48-
try:
49-
tz = newvalues['timezone']
50-
TZ = roundup.date.get_timezone(tz)
51-
dt = datetime.datetime.now()
52-
local = TZ.localize(dt).utctimetuple()
53-
except IOError:
54-
raise ValueError, 'Timezone "%s" does not exist' % tz
55-
except ValueError:
56-
raise ValueError, 'Timezone "%s" exceeds valid range [-23...23]' % tz
44+
tz = newvalues['timezone']
45+
if tz:
46+
# if they set a new timezone validate the timezone by attempting to
47+
# use it before we store it to the db.
48+
import roundup.date
49+
import datetime
50+
try:
51+
TZ = roundup.date.get_timezone(tz)
52+
dt = datetime.datetime.now()
53+
local = TZ.localize(dt).utctimetuple()
54+
except IOError:
55+
raise ValueError, 'Timezone "%s" does not exist' % tz
56+
except ValueError:
57+
raise ValueError, 'Timezone "%s" exceeds valid range [-23...23]' % tz
5758

5859
def init(db):
5960
# fire before changes are made

0 commit comments

Comments
 (0)