def get_plugin_data(product): if product.module.plugin_label: component = PluginUtils.get_staff_component( plugin_label=product.module.plugin_label, component_name='ProductSettings') if component: return component.get(product=product) return None
def to_representation(self, instance): repres = super(ServerSerializer, self).to_representation(instance) if instance.plugin: component = PluginUtils.get_staff_component( plugin_label=instance.plugin.app_label, component_name=COMPONENT_NAME) settings_serializer = getattr(component, 'server_settings_serializer', None) if settings_serializer: context = { 'request': self.context.get('request'), 'server': instance } repres['settings'] = settings_serializer( instance=instance.settings, context=context).to_representation(instance.settings) return repres
def to_internal_value(self, data): intern = super(ServerSerializer, self).to_internal_value(data) plugin = intern.get('plugin') if plugin: component = PluginUtils.get_staff_component( plugin_label=plugin.app_label, component_name=COMPONENT_NAME) settings_serializer = getattr(component, 'server_settings_serializer', None) if settings_serializer: if self.instance: server = self.instance else: server = None context = { 'request': self.context.get('request'), 'server': server } try: intern['settings'] = settings_serializer( context=context).to_internal_value( intern.get('settings')) except ValidationError as v: raise ValidationError(detail={'settings': [v.detail]}) return intern