Skip to content

Commit

Permalink
__getattribute__ now checks for NoneType.
Browse files Browse the repository at this point in the history
yalnazov committed Sep 30, 2015
1 parent 5afaa84 commit 37ef979
Showing 3 changed files with 29 additions and 25 deletions.
25 changes: 13 additions & 12 deletions paymill/models/client.py
Original file line number Diff line number Diff line change
@@ -34,17 +34,18 @@ class Client(JsonObject):
#dynamic JSON to Python representation to resolve circular dependencies between client, payment and subscription
def __getattribute__(self, name):
attr = object.__getattribute__(self, name)
if name == 'subscription':
from . import subscription
return ListProperty(subscription.Subscription).wrap(attr)
if name == 'payment':
from . import payment
if isinstance(attr, dict):
return ListProperty(payment.Payment).wrap(attr)
if isinstance(attr, str):
return list(payment.Payment(id=attr))

return object.__getattribute__(self, name)
if attr is not None:
if name == 'subscription':
from . import subscription
return ListProperty(subscription.Subscription).wrap(attr)
if name == 'payment':
from . import payment
if isinstance(attr, dict):
return ListProperty(payment.Payment).wrap(attr)
if isinstance(attr, str):
return list(payment.Payment(id=attr))

return attr

def updatable_fields(self):
return 'email', 'description'
@@ -123,4 +124,4 @@ def by_updated_at(cls, from_date, to_date=None):
:param int to_date:the to_date to filter by
:return: Filter object
"""
return Filter('updated_at', values=(from_date, to_date), operator=Filter.OPERATOR['INTERVAL'])
return Filter('updated_at', values=(from_date, to_date), operator=Filter.OPERATOR['INTERVAL'])
17 changes: 9 additions & 8 deletions paymill/models/payment.py
Original file line number Diff line number Diff line change
@@ -62,14 +62,15 @@ class Payment(JsonObject):

#dynamic JSON to Python representation
def __getattribute__(self, name):
if name == 'client':
attr = object.__getattribute__(self, name)
if isinstance(attr, str):
return client.Client(id=attr)
if isinstance(attr, dict):
return client.Client(attr)
attr = object.__getattribute__(self, name)
if attr is not None:
if name == 'client':
if isinstance(attr, str):
return client.Client(id=attr)
if isinstance(attr, dict):
return client.Client(attr)

return object.__getattribute__(self, name)
return attr

def updatable_fields(self):
pass
@@ -108,4 +109,4 @@ def by_type(cls, typ='creditcard'):
:param str typ: creditcard or debit
:return: Filter object
"""
return Filter('type', values=(typ,), operator=Filter.OPERATOR['EQUAL'])
return Filter('type', values=(typ,), operator=Filter.OPERATOR['EQUAL'])
12 changes: 7 additions & 5 deletions paymill/models/subscription.py
Original file line number Diff line number Diff line change
@@ -82,10 +82,12 @@ def updatable_fields(self):

#workaround for returned type of amount
def __getattribute__(self, name):
if name == 'amount':
attr = object.__getattribute__(self, name)
return int(attr)
return object.__getattribute__(self, name)
attr = object.__getattribute__(self, name)
if attr is not None:
if name == 'amount':
attr = object.__getattribute__(self, name)
return int(attr)
return attr

class Order(Order):
@classmethod
@@ -126,4 +128,4 @@ def by_created_at(cls, from_date, to_date=None):
:param int to_date:the to_date to filter by
:return: Filter object
"""
return Filter('created_at', values=(from_date, to_date), operator=Filter.OPERATOR['INTERVAL'])
return Filter('created_at', values=(from_date, to_date), operator=Filter.OPERATOR['INTERVAL'])

0 comments on commit 37ef979

Please sign in to comment.