Skip to content

Commit

Permalink
Merge pull request kliment#19 from paymill/fix/attribute_error_when_none
Browse files Browse the repository at this point in the history
Fix/attribute error when none
  • Loading branch information
yalnazov committed Oct 6, 2015
2 parents 0a59dc2 + 2f5f499 commit a6f20c6
Show file tree
Hide file tree
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
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Up @@ -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
Expand Down Expand Up @@ -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 a6f20c6

Please sign in to comment.