Example #1
0
File: base.py Project: dgoyard/piws
    def __init__(self, session, can_read=True, can_update=False,
                 use_store=True, piws_security_model=True):
        """ Initialize the SeniorData class.

        Parameters
        ----------
        session: Session (mandatory)
            a cubicweb session.
        can_read: bool (optional, default True)
            set the read permission to the imported data.
        can_update: bool (optional, default False)
            set the update permission to the imported data.
        use_store: bool (optional, default True)
            if True use an SQLGenObjectStore, otherwise the session.
        piws_security_model: bool (optional, default True)
            if True apply the PIWS security model.
        """
        # CW parameters
        self.can_read = can_read
        self.can_update = can_update
        self.use_store = use_store
        self.session = session
        if self.use_store:
            self.store = SQLGenObjectStore(self.session)
            self.relate_method = self.store.relate
            self.create_entity_method = self.store.create_entity
        else:
            self.relate_method = self.session.add_relation
            self.create_entity_method = self.session.create_entity
        self.piws_security_model = piws_security_model

        # Speed up parameters
        self.inserted_assessments = {}
        self.inserted_devices = {}
Example #2
0
    def __init__(self,
                 session,
                 can_read=True,
                 can_update=False,
                 store_type="RQL",
                 piws_security_model=True):
        """ Initialize the SeniorData class.

        Parameters
        ----------
        session: Session (mandatory)
            a cubicweb session.
        can_read: bool (optional, default True)
            set the read permission to the imported data.
        can_update: bool (optional, default False)
            set the update permission to the imported data.
        store_type: str (optional, default 'RQL')
            Must be in ['RQL', 'SQL', 'MASSIVE'].
            'RQL' to use session, 'SQL' to use SQLGenObjectStore, or 'MASSIVE'
            to use MassiveObjectStore.
        piws_security_model: bool (optional, default True)
            if True apply the PIWS security model.
        """
        # Check input parameters
        if store_type not in ["RQL", "SQL", "MASSIVE"]:
            raise Exception("Store type must be in ['RQL', 'SQL', 'Massive'].")

        # Massive store is supported for CW version > 3.24
        if store_type == "MASSIVE":
            if cw_version < version.parse("3.24.0"):
                raise ValueError("Massive store not supported for CW version "
                                 "{0}.".format(cw_version))
            else:
                from cubicweb.dataimport.massive_store import MassiveObjectStore

        # CW parameters
        self.can_read = can_read
        self.can_update = can_update
        self.store_type = store_type
        self.session = session
        if self.store_type == "SQL":
            self.store = SQLGenObjectStore(self.session)
            if cw_version >= version.parse("3.21.0"):
                self.relate_method = self.store.prepare_insert_relation
            else:
                self.relate_method = self.store.relate
            if cw_version >= version.parse("3.21.0"):
                self.create_entity_method = self.prepare_insert_entity
            else:
                self.create_entity_method = self.store.create_entity
        elif self.store_type == "MASSIVE":
            self.store = MassiveObjectStore(self.session)
            self.relate_method = self.store.prepare_insert_relation
            self.create_entity_method = self.prepare_insert_entity
        else:
            self.relate_method = self.session.add_relation
            self.create_entity_method = self.session.create_entity
        self.piws_security_model = piws_security_model

        # Speed up parameters
        self.inserted_assessments = {}
        self.inserted_devices = {}
        self.already_related_subjects = {}