Beispiel #1
0
    def build_serialized(self, buildset):
        """
        Checks whether the serialized data is valid. If yes, builds this CssPropertySet from the data
        """

        if buildset["type"] == CSSPropertySet.GENERAL:
            if buildset["moduleId"] is not None or buildset["widgetId"] is not None or buildset["session"] is not None:
                raise CSSException(CSSException.get_msg(2))
        elif buildset["type"] == CSSPropertySet.MODULE:
            if buildset["moduleId"] is None or buildset["widgetId"] is not None or buildset["session"] is not None:
                raise CSSException(CSSException.get_msg(3))
        elif buildset["type"] == CSSPropertySet.WIDGET:
            if buildset["moduleId"] is not None or buildset["widgetId"] is None or buildset["session"] is not None:
                raise CSSException(CSSException.get_msg(4))
        elif buildset["type"] == CSSPropertySet.SESSION:
            if buildset["moduleId"] is not None or buildset["widgetId"] is not None or buildset["session"] is None:
                raise CSSException(CSSException.get_msg(5))
        else:
            raise CSSException(CSSException.get_msg(6, buildset["type"]))

        self._module_id = buildset["moduleId"]
        self._widget_id = buildset["widgetId"]
        self._session = buildset["session"]
        self._typ = buildset["type"]
        self._properties = {}
        self._properties.update(buildset["properties"])
Beispiel #2
0
    def build_serialized(self, buildset):
        """
        Checks whether the serialized data is valid. If yes, builds this CssPropertySet from the data
        """

        if buildset['type'] == CSSPropertySet.GENERAL:
            if buildset['moduleId'] is not None or buildset[
                    'widgetId'] is not None or buildset['session'] is not None:
                raise CSSException(CSSException.get_msg(2))
        elif buildset['type'] == CSSPropertySet.MODULE:
            if buildset['moduleId'] is None or buildset[
                    'widgetId'] is not None or buildset['session'] is not None:
                raise CSSException(CSSException.get_msg(3))
        elif buildset['type'] == CSSPropertySet.WIDGET:
            if buildset['moduleId'] is not None or buildset[
                    'widgetId'] is None or buildset['session'] is not None:
                raise CSSException(CSSException.get_msg(4))
        elif buildset['type'] == CSSPropertySet.SESSION:
            if buildset['moduleId'] is not None or buildset[
                    'widgetId'] is not None or buildset['session'] is None:
                raise CSSException(CSSException.get_msg(5))
        else:
            raise CSSException(CSSException.get_msg(6, buildset['type']))

        self._module_id = buildset['moduleId']
        self._widget_id = buildset['widgetId']
        self._session = buildset['session']
        self._typ = buildset['type']
        self._properties = {}
        self._properties.update(buildset['properties'])
Beispiel #3
0
 def edit_value(self, selector, tag, value, inherited=False):
     """
     edits a value determined by selector and tag in this csspropertyset
     """
     if self.get_type() == CSSPropertySet.GENERAL and inherited:
         raise CSSException(CSSException.get_msg(1))
     self._properties[selector + CSSPropertySet.SPLIT + tag] = {
         'v': value,
         'i': False
     }
Beispiel #4
0
 def edit_value(self, selector, tag, value, inherited=False):
     """
     edits a value determined by selector and tag in this csspropertyset
     """
     if self.get_type() == CSSPropertySet.GENERAL and inherited:
         raise CSSException(CSSException.get_msg(1))
     self._properties[selector + CSSPropertySet.SPLIT + tag] = {"v": value, "i": False}
Beispiel #5
0
    def get_csspropertyset(cls, module_id=None, widget_id=None, session_id=None, with_inherited=True):
        """
        loads a csspropertyset from the database
        """
        db = Database()
        if module_id is not None:
            if module_id == CSSPropertySet.ALL:
                ret = {}
                stmnt = "SELECT CSS_SELECTOR, CSS_TAG, CSS_VALUE, MOD_NAME, MOD_ID \
                                 FROM CSS \
                                   INNER JOIN MODULES ON (CSS_MOD_ID = MOD_ID) \
                                 WHERE CSS_MOD_ID IS NOT NULL AND CSS_WGT_ID IS NULL AND CSS_SES_ID IS NULL ;"
                cur = db.query(stmnt)
                rows = cur.fetchallmap()
                for row in rows:
                    if not ret.has_key(row["MOD_ID"]):
                        ret[row["MOD_ID"]] = CSSPropertySet()
                        ret[row["MOD_ID"]].set_module_id(row["MOD_ID"])
                    ret[row["MOD_ID"]].edit_value(row["CSS_SELECTOR"], row["CSS_TAG"], row["CSS_VALUE"])
                return ret
            else:
                if with_inherited:
                    propertyset = cls.get_csspropertyset()
                    propertyset.set_all_inherited()
                else:
                    propertyset = CSSPropertySet()
                propertyset.set_module_id(module_id)
                stmnt = "SELECT CSS_SELECTOR, CSS_TAG, CSS_VALUE, MOD_NAME \
                             FROM CSS \
                               INNER JOIN MODULES ON (CSS_MOD_ID = MOD_ID) \
                             WHERE CSS_MOD_ID IS NOT NULL AND CSS_WGT_ID IS NULL AND CSS_SES_ID IS NULL AND CSS_MOD_ID = ? ;"
                cur = db.query(stmnt, (module_id,))
                rows = cur.fetchallmap()
                for row in rows:
                    propertyset.edit_value(row["CSS_SELECTOR"], row["CSS_TAG"], row["CSS_VALUE"])
                return propertyset
        if widget_id is not None:
            if widget_id == CSSPropertySet.ALL:
                ret = {}
                stmnt = "SELECT CSS_SELECTOR, CSS_TAG, CSS_VALUE, MOD_NAME, MOD_ID, WGT_NAME, WGT_ID \
                         FROM CSS \
                           INNER JOIN WIDGETS ON (CSS_WGT_ID = WGT_ID) \
                           INNER JOIN MODULES ON (WGT_MOD_ID = MOD_ID) \
                         WHERE CSS_MOD_ID IS NULL AND CSS_WGT_ID IS NOT NULL AND CSS_SES_ID IS NULL ;"
                cur = db.query(stmnt)
                rows = cur.fetchallmap()
                for row in rows:
                    if not ret.has_key(row["WGT_ID"]):
                        ret[row["WGT_ID"]] = CSSPropertySet()
                        ret[row["WGT_ID"]].set_widget_id(row["WGT_ID"])
                    ret[row["WGT_ID"]].edit_value(row["CSS_SELECTOR"], row["CSS_TAG"], row["CSS_VALUE"])
                return ret
            else:
                if with_inherited:
                    stmnt = "SELECT WGT_MOD_ID FROM WIDGETS WHERE WGT_ID = ? ; "
                    cur = db.query(stmnt, (widget_id,))
                    row = cur.fetchone()
                    if row:
                        propertyset = cls.get_csspropertyset(module_id=row[0])
                        propertyset.set_all_inherited()
                    else:
                        raise CSSException(CSSException.get_msg(0))
                else:
                    propertyset = CSSPropertySet()
                propertyset.set_widget_id(widget_id)
                stmnt = "SELECT CSS_SELECTOR, CSS_TAG, CSS_VALUE, MOD_NAME, WGT_NAME \
                             FROM CSS \
                               INNER JOIN WIDGETS ON (CSS_WGT_ID = WGT_ID) \
                               INNER JOIN MODULES ON (WGT_MOD_ID = MOD_ID) \
                             WHERE CSS_MOD_ID IS NULL AND CSS_WGT_ID IS NOT NULL AND CSS_SES_ID IS NULL AND CSS_WGT_ID = ? ;"
                cur = db.query(stmnt, (widget_id,))
                rows = cur.fetchallmap()
                for row in rows:
                    propertyset.edit_value(row["CSS_SELECTOR"], row["CSS_TAG"], row["CSS_VALUE"])
                return propertyset
        if session_id is not None:
            return None
            # TODO: Implement

        # Standard CSS Propertyset
        propertyset = CSSPropertySet()
        propertyset.set_type_general()
        stmnt = "SELECT CSS_SELECTOR, CSS_TAG, CSS_VALUE FROM CSS WHERE CSS_MOD_ID IS NULL AND CSS_WGT_ID IS NULL AND CSS_SES_ID IS NULL ;"
        cur = db.query(stmnt)
        rows = cur.fetchallmap()
        for row in rows:
            propertyset.edit_value(row["CSS_SELECTOR"], row["CSS_TAG"], row["CSS_VALUE"])
        return propertyset
Beispiel #6
0
    def get_csspropertyset(cls,
                           module_id=None,
                           widget_id=None,
                           session_id=None,
                           with_inherited=True):
        """
        loads a csspropertyset from the database
        """
        db = cls._core.get_db()
        if module_id is not None:
            if module_id == CSSPropertySet.ALL:
                ret = {}
                stmnt = "SELECT CSS_SELECTOR, CSS_TAG, CSS_VALUE, MOD_NAME, MOD_ID \
                                 FROM CSS \
                                   INNER JOIN MODULES ON (CSS_MOD_ID = MOD_ID) \
                                 WHERE CSS_MOD_ID IS NOT NULL AND CSS_WGT_ID IS NULL AND CSS_SES_ID IS NULL ;"

                cur = db.query(cls._core, stmnt)
                rows = cur.fetchallmap()
                for row in rows:
                    if not ret.has_key(row["MOD_ID"]):
                        ret[row["MOD_ID"]] = CSSPropertySet(cls._core)
                        ret[row["MOD_ID"]].set_module_id(row["MOD_ID"])
                    ret[row["MOD_ID"]].edit_value(row["CSS_SELECTOR"],
                                                  row["CSS_TAG"],
                                                  row["CSS_VALUE"])
                return ret
            else:
                if with_inherited:
                    propertyset = cls.get_csspropertyset()
                    propertyset.set_all_inherited()
                else:
                    propertyset = CSSPropertySet(cls._core)
                propertyset.set_module_id(module_id)
                stmnt = "SELECT CSS_SELECTOR, CSS_TAG, CSS_VALUE, MOD_NAME \
                             FROM CSS \
                               INNER JOIN MODULES ON (CSS_MOD_ID = MOD_ID) \
                             WHERE CSS_MOD_ID IS NOT NULL AND CSS_WGT_ID IS NULL AND CSS_SES_ID IS NULL AND CSS_MOD_ID = ? ;"

                cur = db.query(cls._core, stmnt, (module_id, ))
                rows = cur.fetchallmap()
                for row in rows:
                    propertyset.edit_value(row["CSS_SELECTOR"], row["CSS_TAG"],
                                           row["CSS_VALUE"])
                return propertyset
        if widget_id is not None:
            if widget_id == CSSPropertySet.ALL:
                ret = {}
                stmnt = "SELECT CSS_SELECTOR, CSS_TAG, CSS_VALUE, MOD_NAME, MOD_ID, WGT_NAME, WGT_ID \
                         FROM CSS \
                           INNER JOIN WIDGETS ON (CSS_WGT_ID = WGT_ID) \
                           INNER JOIN MODULES ON (WGT_MOD_ID = MOD_ID) \
                         WHERE CSS_MOD_ID IS NULL AND CSS_WGT_ID IS NOT NULL AND CSS_SES_ID IS NULL ;"

                cur = db.query(cls._core, stmnt)
                rows = cur.fetchallmap()
                for row in rows:
                    if not ret.has_key(row["WGT_ID"]):
                        ret[row["WGT_ID"]] = CSSPropertySet(cls._core)
                        ret[row["WGT_ID"]].set_widget_id(row["WGT_ID"])
                    ret[row["WGT_ID"]].edit_value(row["CSS_SELECTOR"],
                                                  row["CSS_TAG"],
                                                  row["CSS_VALUE"])
                return ret
            else:
                if with_inherited:
                    stmnt = "SELECT WGT_MOD_ID FROM WIDGETS WHERE WGT_ID = ? ; "
                    cur = db.query(cls._core, stmnt, (widget_id, ))
                    row = cur.fetchone()
                    if row:
                        propertyset = cls.get_csspropertyset(module_id=row[0])
                        propertyset.set_all_inherited()
                    else:
                        raise CSSException(CSSException.get_msg(0))
                else:
                    propertyset = CSSPropertySet(cls._core)
                propertyset.set_widget_id(widget_id)
                stmnt = "SELECT CSS_SELECTOR, CSS_TAG, CSS_VALUE, MOD_NAME, WGT_NAME \
                             FROM CSS \
                               INNER JOIN WIDGETS ON (CSS_WGT_ID = WGT_ID) \
                               INNER JOIN MODULES ON (WGT_MOD_ID = MOD_ID) \
                             WHERE CSS_MOD_ID IS NULL AND CSS_WGT_ID IS NOT NULL AND CSS_SES_ID IS NULL AND CSS_WGT_ID = ? ;"

                cur = db.query(cls._core, stmnt, (widget_id, ))
                rows = cur.fetchallmap()
                for row in rows:
                    propertyset.edit_value(row["CSS_SELECTOR"], row["CSS_TAG"],
                                           row["CSS_VALUE"])
                return propertyset
        if session_id is not None:
            return None
            #TODO: Implement

        #Standard CSS Propertyset
        propertyset = CSSPropertySet(cls._core)
        propertyset.set_type_general()
        stmnt = "SELECT CSS_SELECTOR, CSS_TAG, CSS_VALUE FROM CSS WHERE CSS_MOD_ID IS NULL AND CSS_WGT_ID IS NULL AND CSS_SES_ID IS NULL ;"
        cur = db.query(cls._core, stmnt)
        rows = cur.fetchallmap()
        for row in rows:
            propertyset.edit_value(row["CSS_SELECTOR"], row["CSS_TAG"],
                                   row["CSS_VALUE"])
        return propertyset