def _get_adapter(self): # FIXME: Check if payment_method is set. provider_name = re.sub('([a-z]+)([A-Z][a-z]+)', r'\1', self.order_payment.payment_method) app_name = 'payments_' + provider_name class_name = provider_name.title() + 'PaymentAdapter' class_path = 'bluebottle.' + app_name + '.adapters.' + class_name try: adapter_class = import_class(class_path) except ImportError: raise PaymentException("Couldn't find an adapter for payment method '{0}'".format(self.order_payment.payment_method)) adapter = adapter_class(self.order_payment) return adapter
def _get_adapter(self): # FIXME: Check if payment_method is set. provider_name = re.sub("([a-z]+)([A-Z][a-z]+)", r"\1", self.order_payment.payment_method) app_name = "payments_" + provider_name class_name = provider_name.title() + "PaymentAdapter" class_path = "bluebottle." + app_name + ".adapters." + class_name try: adapter_class = import_class(class_path) except ImportError: raise PaymentException( "Couldn't find an adapter for payment method '{0}'".format(self.order_payment.payment_method) ) adapter = adapter_class(self.order_payment) return adapter
def get_serializer_class(model_name=None, serializer_type='default'): """ Returns a serializer model_name: The model eg 'User' or 'Project' serializer_type: The serializer eg 'preview' or 'manage' """ model = get_model_class(model_name) if serializer_type == 'manage': try: serializer_name = model._meta.manage_serializer except AttributeError: serializer_name = model.Meta.manage_serializer elif serializer_type == 'preview': try: serializer_name = model._meta.preview_serializer except AttributeError: serializer_name = model.Meta.preview_serializer elif serializer_type == 'default': try: serializer_name = model._meta.default_serializer except AttributeError: serializer_name = model.Meta.default_serializer else: raise ImproperlyConfigured( "Unknown serializer type '{0}'".format(serializer_type)) serializer_model = import_class(serializer_name) if serializer_model is None: raise ImproperlyConfigured( "serializer_name refers to model '{0}' that has not been " "installed".format(model_name)) return serializer_model