Пример #1
0
class ClientModelManager(ModelManager):
    """Client ModelManager.

    Has access to the `resource_manager`.
    In charge of the conversion between and store and client models.
    """

    def __init__(self, resource_manager, **kwargs):
        ModelManager.__init__(self, **kwargs)
        self._resource_manager = resource_manager
        self._conversion_manager = ModelConversionManager()

    @property
    def resource_manager(self):
        return self._resource_manager

    def import_model(self, store_model, data_store, is_default=False):
        """ Imports a store model. Creates the corresponding client model. """
        if is_default:
            # Default model
            client_model = self.get_model(None)
        else:
            client_model = ClientModel.copy_store_model(self._resource_manager, store_model)
            # Hierarchy registration
            self._registry.register(client_model, is_default=False)
        # Converter
        converter = EquivalentModelConverter(client_model, store_model)
        self._conversion_manager.register_model_converter(client_model, store_model, data_store, converter)

    def convert_store_resources(self, store_resources):
        """Returns converted client resources. """
        return self._conversion_manager.convert_store_to_client_resources(store_resources, self._resource_manager)

    def convert_client_resource(self, client_resource):
        """Returns converted store resources. """
        return self._conversion_manager.convert_client_to_store_resource(client_resource)
Пример #2
0
 def __init__(self, resource_manager, **kwargs):
     ModelManager.__init__(self, **kwargs)
     self._resource_manager = resource_manager
     self._conversion_manager = ModelConversionManager()