diff --git a/musician/models.py b/musician/models.py index 4fae5bd..0f924c4 100644 --- a/musician/models.py +++ b/musician/models.py @@ -1,7 +1,13 @@ +import ast +import logging + from django.utils.html import format_html from django.utils.translation import gettext_lazy as _ +logger = logging.getLogger(__name__) + + class OrchestraModel: """ Base class from which all orchestra models will inherit. """ api_name = None @@ -16,9 +22,6 @@ class OrchestraModel: for (param, default) in self.param_defaults.items(): setattr(self, param, kwargs.get(param, default)) - # def get(self, key): - # # retrieve attr of the object and if undefined get raw data - # return getattr(self, key, self.data.get(key)) @classmethod def new_from_json(cls, data, **kwargs): @@ -35,8 +38,7 @@ class OrchestraModel: c = cls(**json_data) c._json = data - # TODO(@slamora) remove/replace by private variable to ovoid name collisions - c.data = data + return c def __repr__(self): @@ -65,6 +67,15 @@ class PaymentSource(OrchestraModel): "is_active": False, } + def __init__(self, **kwargs): + super().__init__(**kwargs) + # payment details are passed as a plain string + # try to convert to a python structure + try: + self.data = ast.literal_eval(self.data) + except (ValueError, SyntaxError) as e: + logger.error(e) + class UserAccount(OrchestraModel): api_name = 'accounts' diff --git a/musician/templates/musician/profile.html b/musician/templates/musician/profile.html index fead18a..c820007 100644 --- a/musician/templates/musician/profile.html +++ b/musician/templates/musician/profile.html @@ -48,8 +48,12 @@ payment method: {{ payment.method }}