Skip to content

Commit 8c765f4

Browse files
author
Evan Borgstrom
committed
Version 1.2
1 parent 2260513 commit 8c765f4

File tree

3 files changed

+33
-31
lines changed

3 files changed

+33
-31
lines changed

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Version 1.2
2+
Released: August 17th, 2011
3+
4+
* Refactor handling of special elements (boolean, datetime, etc)
5+
6+
17
Version 1.1
28
Released: August 10th, 2011
39

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
name="XeroPy",
1010
description="Pythonic ORM implementation of the Xero API",
1111
zip_safe= False,
12-
version="1.1",
12+
version="1.2",
1313
packages = ['xero',],
1414
install_requires=[
1515
'httplib2==0.6.0',

xero/__init__.py

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ class XeroExceptionUnknown(XeroException):
2323

2424
class Manager(object):
2525
DECORATED_METHODS = ('get', 'save', 'filter', 'all', 'put')
26-
DATETIME_FIELDS = (u'UpdatedDateUTC',)
26+
27+
DATETIME_FIELDS = (u'UpdatedDateUTC', u'Updated', u'FullyPaidOnDate')
28+
DATE_FIELDS = (u'DueDate', u'Date')
2729
BOOLEAN_FIELDS = (u'IsSupplier', u'IsCustomer')
30+
2831
MULTI_LINES = (u'LineItem', u'Phone', u'Address', 'TaxRate')
2932
PLURAL_EXCEPTIONS = {'Addresse':'Address'}
3033

@@ -63,44 +66,37 @@ def convert_to_dict(self, deep_list):
6366
for key, data in zip(keys, lists):
6467

6568
if len(data) == 1:
66-
out[key] = data[0]
67-
elif len(data) > 1 and key in self.MULTI_LINES and out:
68-
out += (self.convert_to_dict(data),)
69-
elif len(data) > 1 and key in self.MULTI_LINES:
70-
out = (self.convert_to_dict(data),)
71-
elif len(data) > 1 and key == self.singular and out:
72-
out += (self.convert_to_dict(data),)
73-
elif len(data) > 1 and key == self.singular:
74-
out = (self.convert_to_dict(data),)
69+
# we're setting a value
70+
# check to see if we need to apply any special
71+
# formatting to the value
72+
val = data[0]
73+
if key in self.BOOLEAN_FIELDS:
74+
val = True if val.lower() == 'true' else False
75+
if key in self.DATETIME_FIELDS:
76+
val = parse(val)
77+
if key in self.DATE_FIELDS:
78+
val = parse(val).date()
79+
80+
out[key] = val
81+
82+
elif len(data) > 1 and ((key in self.MULTI_LINES) or (key == self.singular)):
83+
# our data is a collection and needs to be handled as such
84+
if out:
85+
out += (self.convert_to_dict(data),)
86+
else:
87+
out = (self.convert_to_dict(data),)
88+
7589
elif len(data) > 1:
7690
out[key] = self.convert_to_dict(data)
7791

7892
elif len(deep_list) == 2:
79-
key = deep_list[0]
93+
key = deep_list[0]
8094
data = deep_list[1]
8195
out[key] = self.convert_to_dict(data)
8296
else:
8397
out = deep_list[0]
8498
return out
8599

86-
def __convert_data(self, data):
87-
if isinstance(data, tuple) or isinstance(data, list):
88-
data = tuple([self.__convert_fields(line) for line in data])
89-
elif isinstance(data, dict):
90-
data = self.__convert_fields(data)
91-
return data
92-
93-
def __convert_fields(self, data):
94-
for key in self.BOOLEAN_FIELDS:
95-
if data.has_key(key):
96-
val = data[key]
97-
val = True if val.lower() == 'true' else False
98-
data[key] = val
99-
for key in self.DATETIME_FIELDS:
100-
if data.has_key(key):
101-
data[key] = parse(data[key])
102-
return data
103-
104100
def dict_to_xml( self, root_elm, dict_data ):
105101
for key in dict_data.keys():
106102
_data = dict_data[key]
@@ -159,7 +155,7 @@ def wrapper(*args, **kwargs):
159155
return body
160156
dom = parseString(body)
161157
data = self.convert_to_dict(self.walk_dom(dom))
162-
return self.__convert_data(self.__get_results(data))
158+
return self.__get_results(data)
163159

164160
elif headers['status'] == '404':
165161
msg = ' : '.join([str(headers['status']), body])

0 commit comments

Comments
 (0)