Ejemplo n.º 1
0
    def saveCallback(self, widget=None, data=None):
        try:
            view = self.getMyObject()
        except GenericObjectStoreException:
            return
        mapping = {}
        used_widgetIds = []
        for spacewidget in self.compose_spacewidgets.values():
            wgt = spacewidget.getWidget()
            if wgt is not None:
                widgetId = wgt.getId()
                if widgetId in used_widgetIds:
                    raise ViewException(ViewException.get_msg(
                        8, wgt.getName()))
                mapping[spacewidget.getSpaceId()] = widgetId
                used_widgetIds.append(widgetId)
        view.setSpaceWidgetMapping(mapping)

        boxmapping = {}
        for boxwidget in self.compose_boxwidgets.values():
            widgets = boxwidget.getWidgets()
            for wgt in widgets:
                widgetId = wgt.getId()
                if widgetId in used_widgetIds:
                    raise ViewException(ViewException.get_msg(
                        8, wgt.getName()))
                if not boxmapping.has_key(boxwidget.getBoxId()):
                    boxmapping[boxwidget.getBoxId()] = []
                boxmapping[boxwidget.getBoxId()].append(widgetId)
                used_widgetIds.append(widgetId)
        view.setBoxMapping(boxmapping)
Ejemplo n.º 2
0
 def saveCallback(self, widget=None, data=None):
     try:
         view = self.getMyObject()
     except GenericObjectStoreException:
         return
     mapping = {}
     used_widgetIds = []
     for spacewidget in self.compose_spacewidgets.values():
         wgt = spacewidget.getWidget()
         if wgt is not None:
             widgetId = wgt.getId()
             if widgetId in used_widgetIds:
                 raise ViewException(ViewException.get_msg(8,wgt.getName()))
             mapping[spacewidget.getSpaceId()]= widgetId
             used_widgetIds.append(widgetId)
     view.setSpaceWidgetMapping(mapping)
     
     boxmapping = {}
     for boxwidget in self.compose_boxwidgets.values():
         widgets = boxwidget.getWidgets()
         for wgt in widgets:
             widgetId = wgt.getId()
             if widgetId in used_widgetIds:
                 raise ViewException(ViewException.get_msg(8,wgt.getName()))
             if not boxmapping.has_key(boxwidget.getBoxId()):
                 boxmapping[boxwidget.getBoxId()] = []
             boxmapping[boxwidget.getBoxId()].append(widgetId)
             used_widgetIds.append(widgetId)
     view.setBoxMapping(boxmapping)
Ejemplo n.º 3
0
    def get_from_json(cls, json):
        """
        creates a view from a json that looks like this:

        {'s':<page_id>,
         'v':{'<space_id>':<widget_id>,'<space_id>':<widget_id>,[...]},
         'b':{'<box_id>':[<widget_id>, <widget_id>, [...]]},
         'c':{'<wgt_id>': {<widget_args>},'wgt_id':{<widget_args>},[...]},
         'p':<wgt_id>
        }

        's' is the page that this view is going to be rendered on 
        'v' is a dictionary that maps space_ids to widget_ids
        'b' represents box-packed widgets
        'c' maps parameters to widgets
        'p' is an OPTIONAL parameter. if a html-form is submitted, this 
            contains a widget_id to 
        """

        json = unquote(json)
        jd = JSONDecoder()
        try:
            json = jd.decode(json)
        except ValueError:
            raise ViewException(ViewException.get_msg(7))

        view = View(cls._core)
        if json.has_key('s'):
            view.set_page(json['s'])
        else:
            raise ViewException(ViewException.get_msg(6))

        if json.has_key('v'):
            for key, value in json['v'].items(): #transform indices back to int
                json['v'][int(key)] = value
                del(json['v'][key])
            view.set_space_widget_mapping(json['v'])
        else:
            view.set_space_widget_mapping({})

        if json.has_key('b'):
            for key, value in json['b'].items(): #transform indices back to int
                json['b'][int(key)] = value
                del(json['b'][key])
            view.set_box_mapping(json['b'])
        else:
            view.set_box_mapping({})

        if json.has_key('c'):
            for key, value in json['c'].items(): #transform indices back to int
                json['c'][int(key)] = value
                del(json['c'][key])
            view.set_widget_param_mapping(json['c'])
        else:
            view.set_widget_param_mapping({})
        if json.has_key('p'):
            view.set_post_widget_id(json['p'])

        return view
Ejemplo n.º 4
0
 def get_box_info(self, box_id):
     stmnt = "SELECT BOX_ORIENTATION, BOX_NAME FROM BOXES WHERE BOX_ID = ? ;"
     db = self._core.get_db()
     cur = db.query(self._core, stmnt, (int(box_id), ))
     row = cur.fetchonemap()
     if row is None:
         raise ViewException(ViewException.get_msg(9))
     else:
         return row["BOX_ORIENTATION"], row["BOX_NAME"]
Ejemplo n.º 5
0
 def get_default_view(cls):
     db = cls._core.get_db()
     stmnt = "SELECT VIE_NAME FROM VIEWS WHERE VIE_DEFAULT = 1 ;"
     cur = db.query(cls._core, stmnt)
     row = cur.fetchonemap()
     if row is not None:
         return cls.get_from_name(row["VIE_NAME"])
     else:
         raise ViewException(ViewException.get_msg(3))
Ejemplo n.º 6
0
    def remove_widget_from_space(self, space):
        if type(space) == int:
            pass
        elif type(space) == str:
            space = self._page.get_space_id_by_name(space)
        else:
            raise ViewException(ViewException.get_msg(1))

        if self._space_widget_mapping.has_key(space):
            del (self._space_widget_mapping[space])
Ejemplo n.º 7
0
    def set_params_for_widget(self, widget, params):
        if type(widget) != int:
            widget = widget.get_id()
        
        if type(params) != dict:
            raise ViewException(ViewException.get_msg(2))

        if widget not in self._space_widget_mapping.values():
            raise ViewException(ViewException.get_msg(4))

        self._widget_param_mapping[widget] = params
Ejemplo n.º 8
0
    def set_params_for_widget(self, widget, params):
        if type(widget) != int:
            widget = widget.get_id()

        if type(params) != dict:
            raise ViewException(ViewException.get_msg(2))

        if widget not in self._space_widget_mapping.values():
            raise ViewException(ViewException.get_msg(4))

        self._widget_param_mapping[widget] = params
Ejemplo n.º 9
0
    def place_widget_in_space(self, space, widget):
        if type(space) == int:
            pass
        elif type(space) == str:
            space = self._page.get_space_id_by_name(space)
        else:
            raise ViewException(ViewException.get_msg(1))

        if type(widget) != int:
            widget = widget.get_id()

        self._space_widget_mapping[space] = widget
Ejemplo n.º 10
0
    def get_from_id(cls, nr):
        """
        returns the view that is given by this id
        """
        db = cls._core.get_db()
        stmnt = "SELECT VIE_NAME, VIE_SIT_ID, VIE_DEFAULT FROM VIEWS WHERE VIE_ID = ? ;"
        cur = db.query(cls._core, stmnt, (int(nr), ))
        row = cur.fetchonemap()
        if row is None:
            raise ViewException(ViewException.get_msg(0))
        else:
            view = View(cls._core)
            view.set_name(row["VIE_NAME"])
            view.set_default(row["VIE_DEFAULT"])
            view.set_page(row["VIE_SIT_ID"])
            view.set_id(nr)

        stmnt = "SELECT VIW_SPA_ID, VIW_WGT_ID FROM VIEWWIDGETS WHERE VIW_VIE_ID = ? ;"
        cur = db.query(cls._core, stmnt, (view.get_id(), ))
        rows = cur.fetchallmap()
        space_widget_mapping = {}
        for row in rows:
            space_widget_mapping[row["VIW_SPA_ID"]] = row["VIW_WGT_ID"]
        view.set_space_widget_mapping(space_widget_mapping)

        stmnt = "SELECT BOX_ID, BWT_WGT_ID \
                 FROM BOXES LEFT JOIN BOXWIDGETS ON (BOX_ID = BWT_BOX_ID) \
                 WHERE BWT_VIE_ID = ? OR (BWT_VIE_ID IS NULL AND BOX_SIT_ID = ?) \
                 ORDER BY BWT_BOX_ID, BWT_ORDER ;"

        cur = db.query(cls._core, stmnt, (view.get_id(), view.get_page()))
        rows = cur.fetchallmap()
        box_mapping = {}
        for row in rows:
            box_id = int(row["BOX_ID"])
            if not box_mapping.has_key(box_id):
                box_mapping[box_id] = []
            if row["BWT_WGT_ID"] is not None:
                box_mapping[box_id].append(row["BWT_WGT_ID"])
        view.set_box_mapping(box_mapping)

        stmnt = "SELECT VWP_KEY, VWP_VALUE, VWP_WGT_ID FROM VIEWWIDGETPARAMS WHERE VWP_VIE_ID = ? ORDER BY VWP_WGT_ID;"
        cur = db.query(cls._core, stmnt, (view.get_id(), ))
        rows = cur.fetchallmap()
        widget_param_mapping = {}
        for row in rows:
            if not widget_param_mapping.has_key(row["VWP_WGT_ID"]):
                widget_param_mapping[row["VWP_WGT_ID"]] = {}
            widget_param_mapping[row["VWP_WGT_ID"]][
                row["VWP_KEY"]] = row["VWP_VALUE"]
        view.set_widget_param_mapping(widget_param_mapping)

        return view
Ejemplo n.º 11
0
 def get_from_name(cls, name):
     """
     Searches in the database if there is a View
     with the given name. If there is, creates it
     with the data that can be retrieved from the database
     """
     if len(name) > 128:
         return None  # Prevents DB-Error. Change VIE_NAME in scvdb.sql too if changing here
     db = cls._core.get_db()
     stmnt = "SELECT VIE_ID FROM VIEWS WHERE VIE_NAME = ? ;"
     cur = db.query(cls._core, stmnt, (str(name), ))
     row = cur.fetchonemap()
     if row is None:
         raise ViewException(ViewException.get_msg(0))
     else:
         return cls.get_from_id(row["VIE_ID"])
Ejemplo n.º 12
0
 def get_default_view(cls):
     db = cls._core.get_db()
     stmnt = "SELECT VIE_NAME FROM VIEWS WHERE VIE_DEFAULT = 1 ;"
     cur = db.query(cls._core, stmnt)
     row = cur.fetchonemap()
     if row is not None:
         return cls.get_from_name(row["VIE_NAME"])
     else:
         raise ViewException(ViewException.get_msg(3))
Ejemplo n.º 13
0
 def get_box_info(self, box_id):
     stmnt = "SELECT BOX_ORIENTATION, BOX_NAME FROM BOXES WHERE BOX_ID = ? ;"
     db = self._core.get_db()
     cur = db.query(self._core, stmnt, (int(box_id),))
     row = cur.fetchonemap()
     if row is None:
         raise ViewException(ViewException.get_msg(9))
     else:
         return row["BOX_ORIENTATION"], row["BOX_NAME"]
Ejemplo n.º 14
0
 def get_default_view(cls):
     db = Database()
     stmnt = "SELECT VIE_ID FROM VIEWS WHERE VIE_DEFAULT = 1 ;"
     cur = db.query(stmnt)
     row = cur.fetchonemap()
     if row is not None:
         return cls.get_from_id(row["VIE_ID"])
     else:
         raise ViewException(ViewException.get_msg(3))
Ejemplo n.º 15
0
 def remove_widget_from_space(self, space):
     if type(space) == int:
         pass
     elif type(space) == str:
         space = self._page.get_space_id_by_name(space)
     else:
         raise ViewException(ViewException.get_msg(1))
         
     if self._space_widget_mapping.has_key(space):
         del(self._space_widget_mapping[space])
Ejemplo n.º 16
0
    def place_widget_in_space(self, space, widget):
        if type(space) == int:
            pass
        elif type(space) == str:
            space = self._page.get_space_id_by_name(space)
        else:
            raise ViewException(ViewException.get_msg(1))

        if type(widget) != int:
            widget = widget.get_id()

        self._space_widget_mapping[space] = widget
Ejemplo n.º 17
0
    def get_from_id(cls, nr):
        """
        returns the view that is given by this id
        """
        db = cls._core.get_db()
        stmnt = "SELECT VIE_NAME, VIE_SIT_ID, VIE_DEFAULT FROM VIEWS WHERE VIE_ID = ? ;"
        cur = db.query(cls._core, stmnt, (int(nr),))
        row = cur.fetchonemap()
        if row is None:
            raise ViewException(ViewException.get_msg(0))
        else:
            view = View(cls._core)
            view.set_name(row["VIE_NAME"])
            view.set_default(row["VIE_DEFAULT"])
            view.set_page(row["VIE_SIT_ID"])
            view.set_id(nr)

        stmnt = "SELECT VIW_SPA_ID, VIW_WGT_ID FROM VIEWWIDGETS WHERE VIW_VIE_ID = ? ;"
        cur = db.query(cls._core, stmnt, (view.get_id(),))
        rows = cur.fetchallmap()
        space_widget_mapping = {}
        for row in rows:
            space_widget_mapping[row["VIW_SPA_ID"]] = row["VIW_WGT_ID"]
        view.set_space_widget_mapping(space_widget_mapping)

        stmnt = "SELECT BOX_ID, BWT_WGT_ID \
                 FROM BOXES LEFT JOIN BOXWIDGETS ON (BOX_ID = BWT_BOX_ID) \
                 WHERE BWT_VIE_ID = ? OR (BWT_VIE_ID IS NULL AND BOX_SIT_ID = ?) \
                 ORDER BY BWT_BOX_ID, BWT_ORDER ;"
        cur = db.query(cls._core, stmnt, (view.get_id(), view.get_page()))
        rows = cur.fetchallmap()
        box_mapping = {}
        for row in rows:
            box_id = int(row["BOX_ID"])
            if not box_mapping.has_key(box_id):
                box_mapping[box_id] = []
            if row["BWT_WGT_ID"] is not None:
                box_mapping[box_id].append(row["BWT_WGT_ID"])
        view.set_box_mapping(box_mapping)

        stmnt = "SELECT VWP_KEY, VWP_VALUE, VWP_WGT_ID FROM VIEWWIDGETPARAMS WHERE VWP_VIE_ID = ? ORDER BY VWP_WGT_ID;"
        cur = db.query(cls._core, stmnt, (view.get_id(),))
        rows = cur.fetchallmap()
        widget_param_mapping = {}
        for row in rows:
            if not widget_param_mapping.has_key(row["VWP_WGT_ID"]):
                widget_param_mapping[row["VWP_WGT_ID"]] = {}
            widget_param_mapping[row["VWP_WGT_ID"]][row["VWP_KEY"]]= row["VWP_VALUE"]
        view.set_widget_param_mapping(widget_param_mapping)

        return view
Ejemplo n.º 18
0
 def get_from_name(cls, name):
     """
     Searches in the database if there is a View
     with the given name. If there is, creates it
     with the data that can be retrieved from the database
     """
     if len(name) > 128:
         return None # Prevents DB-Error. Change VIE_NAME in scvdb.sql too if changing here
     db = cls._core.get_db()
     stmnt = "SELECT VIE_ID FROM VIEWS WHERE VIE_NAME = ? ;"
     cur = db.query(cls._core, stmnt, (str(name),))
     row = cur.fetchonemap()
     if row is None:
         raise ViewException(ViewException.get_msg(0))
     else:
         return cls.get_from_id(row["VIE_ID"])
Ejemplo n.º 19
0
    def get_from_json(cls, json):
        """
        creates a view from a json that looks like this:

        {'s':<page_id>,
         'v':{'<space_id>':<widget_id>,'<space_id>':<widget_id>,[...]},
         'b':{'<box_id>':[<widget_id>, <widget_id>, [...]]},
         'c':{'<wgt_id>': {<widget_args>},'wgt_id':{<widget_args>},[...]},
         'p':<wgt_id>
        }

        's' is the page that this view is going to be rendered on 
        'v' is a dictionary that maps space_ids to widget_ids
        'b' represents box-packed widgets
        'c' maps parameters to widgets
        'p' is an OPTIONAL parameter. if a html-form is submitted, this 
            contains a widget_id to 
        """

        json = unquote(json)
        jd = JSONDecoder()
        try:
            json = jd.decode(json)
        except ValueError:
            raise ViewException(ViewException.get_msg(7))

        view = View(cls._core)
        if json.has_key('s'):
            view.set_page(json['s'])
        else:
            raise ViewException(ViewException.get_msg(6))

        if json.has_key('v'):
            for key, value in json['v'].items(
            ):  #transform indices back to int
                json['v'][int(key)] = value
                del (json['v'][key])
            view.set_space_widget_mapping(json['v'])
        else:
            view.set_space_widget_mapping({})

        if json.has_key('b'):
            for key, value in json['b'].items(
            ):  #transform indices back to int
                json['b'][int(key)] = value
                del (json['b'][key])
            view.set_box_mapping(json['b'])
        else:
            view.set_box_mapping({})

        if json.has_key('c'):
            for key, value in json['c'].items(
            ):  #transform indices back to int
                json['c'][int(key)] = value
                del (json['c'][key])
            view.set_widget_param_mapping(json['c'])
        else:
            view.set_widget_param_mapping({})
        if json.has_key('p'):
            view.set_post_widget_id(json['p'])

        return view
Ejemplo n.º 20
0
    def get_from_id(cls, nr):
        """
        returns the view that is given by this id
        """
        db = Database()
        stmnt = "SELECT VIE_NAME, VIE_SIT_ID, VIE_VIE_BASEVIEW, VIE_DEFAULT\
                  FROM VIEWS WHERE VIE_ID = ? ;"
        cur = db.query(stmnt, (int(nr),))
        row = cur.fetchonemap()
        if row is None:
            raise ViewException(ViewException.get_msg(0))
        else:
            configuration = Configuration()
            rendermode = configuration.get_entry("core.rendermode")
            if rendermode == "pure":
                view = PureView()
            elif rendermode == "ajax":
                view = AJAXView()
            view.set_name(row["VIE_NAME"])
            view.set_default(row["VIE_DEFAULT"])
            view.set_page(row["VIE_SIT_ID"])
            view.set_baseview_id(row["VIE_VIE_BASEVIEW"])
            view.set_id(nr)
        
        # get the widget space mapping. if the view has a baseview, also get those of
        # the baseview. store into a dictionary. overwrite the space widget mapping
        # of the baseview with those of the view. the derived view only stores the
        # differences of itself and the baseview (same goes for widget_param_mapping
        # and box_mapping
        stmnt = "SELECT VIW_SPA_ID, VIW_WGT_ID FROM VIEWWIDGETS \
                    WHERE VIW_VIE_ID = (SELECT VIE_VIE_BASEVIEW FROM VIEWS WHERE VIE_ID = ?) \
                 UNION SELECT VIW_SPA_ID, VIW_WGT_ID FROM VIEWWIDGETS WHERE VIW_VIE_ID = ? ;"
        cur = db.query(stmnt, (view.get_id(), view.get_id()))
        rows = cur.fetchallmap()
        space_widget_mapping = {}
        for row in rows:
            space_widget_mapping[row["VIW_SPA_ID"]] = row["VIW_WGT_ID"]
        view.set_space_widget_mapping(space_widget_mapping)
        
        # get the box mapping. this mapping maps box_ids to a list of widget_ids.
        stmnt = "SELECT BOX_ID, BWT_WGT_ID FROM (\
                 SELECT BOX_ID, BWT_WGT_ID, BWT_BOX_ID, BWT_ORDER, 0 AS UNIONSORT \
                     FROM BOXES LEFT JOIN BOXWIDGETS ON (BOX_ID = BWT_BOX_ID) \
                     WHERE BWT_VIE_ID = (SELECT VIE_VIE_BASEVIEW FROM VIEWS WHERE VIE_ID = ?) \
                     OR (BWT_VIE_ID IS NULL AND BOX_SIT_ID = ?) \
                 UNION SELECT BOX_ID, BWT_WGT_ID, BWT_BOX_ID, BWT_ORDER, 1 AS UNIONSORT \
                     FROM BOXES LEFT JOIN BOXWIDGETS ON (BOX_ID = BWT_BOX_ID) \
                     WHERE BWT_VIE_ID = ? OR (BWT_VIE_ID IS NULL AND BOX_SIT_ID = ?)) \
                 ORDER BY UNIONSORT, BWT_BOX_ID, BWT_ORDER ;"
        cur = db.query(stmnt, (view.get_id(), view.get_page(),
                                          view.get_id(), view.get_page()))
        rows = cur.fetchallmap()
        box_mapping = {}
        for row in rows:
            box_id = int(row["BOX_ID"])
            if not box_mapping.has_key(box_id):
                box_mapping[box_id] = []
            if row["BWT_WGT_ID"] is not None:
                box_mapping[box_id].append(row["BWT_WGT_ID"])
        view.set_box_mapping(box_mapping)

        # get the widget_param mapping. this maps a dictionary of parameters to
        # a widget_id
        stmnt = "SELECT VWP_KEY, VWP_VALUE, VWP_WGT_ID FROM ( \
                     SELECT VWP_KEY, VWP_VALUE, VWP_WGT_ID, 0 AS UNIONSORT FROM VIEWWIDGETPARAMS \
                     WHERE VWP_VIE_ID = (SELECT VIE_VIE_BASEVIEW FROM VIEWS WHERE VIE_ID = ?) \
                     UNION \
                     SELECT VWP_KEY, VWP_VALUE, VWP_WGT_ID, 1 AS UNIONSORT FROM VIEWWIDGETPARAMS \
                     WHERE VWP_VIE_ID = ?)\
                 ORDER BY UNIONSORT, VWP_WGT_ID;"
        cur = db.query(stmnt, (view.get_id(),view.get_id()))
        rows = cur.fetchallmap()
        widget_param_mapping = {}
        for row in rows:
            if not widget_param_mapping.has_key(row["VWP_WGT_ID"]):
                widget_param_mapping[row["VWP_WGT_ID"]] = {}
            widget_param_mapping[row["VWP_WGT_ID"]][row["VWP_KEY"]]= row["VWP_VALUE"]
        view.set_widget_param_mapping(widget_param_mapping)

        return view