Пример #1
0
    def create(cls, name, internal_name, description, html_body, html_head, css, minimap=None):
        """
        Creates A Page (normally as a part of the installation process of a Template)
        in Database
        """

        placeholders = re.findall(r"<%[^%>]+%>",html_body)
        placeholders = [p.replace("<%","",1) for p in placeholders]
        placeholders = [p.replace("%>","",1) for p in placeholders]
        placeholders = [p.strip() for p in placeholders]

        if len(placeholders) < 1:
            pass # Eventually we need to check for Pages with no spaces. Not an error yet

        minimap_id = None
        if minimap is not None:
            minimap_binary = Binary.create("image/png", minimap)
            minimap_binary.set_filename(internal_name+"_minimap.png")
            minimap_binary.store()
            minimap_id = minimap_binary.get_id()

        css_binary = binary_manager.create("text/css", css)
        css_binary.set_filename(internal_name+".css")
        css_binary.store()
        css_id = css_binary.get_id()

        stmnt = "INSERT INTO SITES (SIT_ID, SIT_HTML, SIT_HTML_HEAD, SIT_DESCRIPTION, SIT_NAME, SIT_BIN_MINIMAP, SIT_BIN_CSS) \
                 VALUES (?,?,?,?,?,?,?) ;"

        db = Database()
        new_sit_id = db.get_seq_next("SIT_GEN")

        db.query(stmnt , (new_sit_id, html_body, html_head, description, name, minimap_id, css_id), commit=True)

        stmnt_space= "INSERT INTO SPACES (SPA_ID, SPA_SIT_ID, SPA_NAME ) VALUES (?,?,?) ; "
        stmnt_box = "INSERT INTO BOXES (BOX_ID, BOX_SIT_ID, BOX_NAME, BOX_ORIENTATION) VALUES (?,?,?,?) ;"

        for placeholder in placeholders:
            splitted = placeholder.split(":")
            typ = splitted[0]
            name = splitted[1]
            if typ == "space":
                new_space_id = db.get_seq_next("SPA_GEN")
                db.query(stmnt_space, (new_space_id, new_sit_id, name), commit=True )
            elif typ == "vbox" or typ == "hbox":
                new_box_id = db.get_seq_next("BOX_GEN")
                orientation = int(typ == "vbox")
                db.query(stmnt_box, (new_box_id, new_sit_id, name, orientation), commit=True)
Пример #2
0
    def create_role(cls, data=None):
        if data is None:
            raise PermissionException(PermissionException.get_msg(10))
        if data["name"] is None:
            raise PermissionException(PermissionException.get_msg(11))

        db = Database()

        stmnt = "SELECT ROL_ID FROM ROLES WHERE ROL_NAME = ? ;"
        cur = db.query(stmnt,(data["name"],))
        res = cur.fetchonemap()
        if res is not None:
            raise PermissionException(PermissionException.get_msg(13, data["name"]))
        
        role_id = db.get_seq_next("ROL_GEN")
        role = Role()
        role.set_id(role_id)
        role.set_name(data["name"])
        role.store()

        if data.has_key("rights"):
            for permission in data["rights"]:
                if permission["granted"]:
                    role.add_permission(permission["name"])
                else:
                    role.remove_permission(permission["name"])
            role.store()

        return role
Пример #3
0
 def create_permission(cls, permission, module=""):
     """
     Creates a new permission in database
     """
     db = Database()
     new_id = db.get_seq_next('RIG_GEN')
     stmnt = "INSERT INTO RIGHTS (RIG_ID, RIG_NAME) VALUES (?,?) ;"
     db.query(stmnt,(new_id,module+"."+permission),commit=True)
     PokeManager.add_activity(ActivityType.PERMISSION)
     return module+"."+permission
Пример #4
0
 def create_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 None:
         view_id = db.get_seq_next("VIE_GEN")
         stmnt = "INSERT INTO VIEWS (VIE_ID, VIE_SIT_ID, VIE_NAME, VIE_DEFAULT) \
                    VALUES (?,1,'default',1) ;"
         db.query(stmnt, (view_id,), commit=True)
Пример #5
0
 def _register_module(manifest):
     """
     registers a module into the database
     """
     db = Database()
     nr = db.get_seq_next("MOD_GEN")
     stmnt = "INSERT INTO MODULES (MOD_ID, MOD_NAME, MOD_DISPLAYNAME, MOD_VERSIONMAJOR, MOD_VERSIONMINOR, MOD_VERSIONREV, MOD_JSMANDATORY) \
                   VALUES (?,?,?,?,?,?,?) ;"
     db.query(stmnt,(nr,manifest["name"],manifest["hrname"],
                                manifest["version_major"],manifest["version_minor"],
                                manifest["revision"],manifest["js_mandatory"]),commit=True)
     return nr
Пример #6
0
 def create_action_list(cls, action_list_name = "new actionlist"):
     """
     This function creates a new ActionList
     """
     action_list = ActionList()
     action_list.set_name(action_list_name)
     db = Database()
     action_list.set_id(db.get_seq_next('ATL_GEN'))
     stmnt = "INSERT INTO ACTIONLISTS VALUES (?,?);"
     db.query(stmnt, (action_list.get_id(), action_list.get_name()),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
     return action_list
Пример #7
0
 def create_menu(cls, page, name="new menu"):
     """
     This function creates a menu.
     """
     db = Database()
     menu = Menu()
     menu.set_id(db.get_seq_next('MNU_GEN'))
     menu.set_name(name)
     stmnt = "INSERT INTO MENUS (MNU_ID,MNU_NAME, MNU_SIT_ID) VALUES (?,?, ?) ;"
     db.query(stmnt, (menu.get_id(), menu.get_name(), page.get_id()),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
     return menu 
Пример #8
0
    def store(self):
        db = Database()

        if self._id is None:
            self._id = db.get_seq_next('WGT_GEN')

        if self._module is None:
            raise ModuleCoreException(ModuleCoreException.get_msg(1))

        stmnt = "UPDATE OR INSERT INTO WIDGETS (WGT_ID, WGT_NAME, WGT_SIT_ID, WGT_MOD_ID, WGT_VIE_BASEVIEW, WGT_SPA_BASESPACE) \
                    VALUES (?,?,?,?,?,?) MATCHING (WGT_ID) ;"
        db.query(stmnt,(self._id,self._name, self._site_id,self._module.get_id(), self._baseview_id, self._baseview_space_id ),commit=True)
        PokeManager.add_activity(ActivityType.WIDGET)
Пример #9
0
    def create_action(cls, actionlist=None, view_id=None, url=None, widget_id = None, space_id = None):
        """
        This method creates a new Action and returns it.
        You can create an action based on either:
        1. A Page Id 
        2. An URL
        3. A widgetId combined with a SpaceId (Both applies to the site the menu is showed in)
        If the combination is not valid this function will return null and not do anything in db
        The action will be inserted with the lowest order (execution priority)
        """
        if actionlist is None:
            return None
        action = Action()
        action.set_action_list_id(actionlist.get_id())
        if view_id is not None:
            view = View.get_from_id(view_id)
            if view is not None:
                action.set_view_id(view_id)
            else:
                return None
        elif url is not None:
            action.set_url(str(url),True)
        elif widget_id is not None and space_id is not None:
            widget = ModuleManager.get_widget(widget_id)
            if widget is not None:
                action.set_widget_space_constellation(widget_id,space_id,True)
        else:
            return None

        action.set_name("new action",True)
        db = Database()
        new_id = db.get_seq_next("ACT_GEN")
        stmnt = "SELECT MAX(ACT_ORDER) AS MAXORDER FROM ACTIONS WHERE ACT_ATL_ID = ? ;"
        cur = db.query(stmnt, (action.get_action_list_id(),))
        row = cur.fetchonemap()
        if row["MAXORDER"] is not None:
            new_order = row["MAXORDER"]+1
        else:
            new_order = 0
        action.set_id(new_id)
        action.set_order(new_order)
        stmnt = "INSERT INTO ACTIONS (ACT_ID, ACT_NAME, ACT_ATL_ID, \
                                      ACT_VIE_ID, ACT_SPA_ID, ACT_WGT_ID, ACT_URL, ACT_ORDER) \
                              VALUES (?,?,?,?,?,?,?,?) ;"
        db.query(stmnt, (action.get_id(), action.get_name(), action.get_action_list_id(),
                                     action.get_view_id(), action.get_space(), action.get_widget_id(),
                                     action.get_url(), action.get_order()),commit=True)
        PokeManager.add_activity(ActivityType.MENU)
        return action
Пример #10
0
 def store(self):
     """
     stores this user into database
     """
     db = Database()()
     if self._id == None:
         stmnt = "INSERT INTO USERS (USR_ID, USR_NAME, USR_PASSWORD, USR_SALT) \
                   VALUES (?,?,?,?);"
         self.set_id(db.get_seq_next('USR_GEN'))
         db.query(stmnt,(self._id, self._name, self._password, self._salt),commit=True)
     else:
         stmnt =  "UPDATE USERS SET \
                     USR_NAME = ?, \
                     USR_PASSWORD = ?, \
                     USR_SALT = ? \
                   WHERE USR_ID = ?"
         db.query(stmnt,(self._name, self._password, self._salt, self._id),commit=True)
     PokeManager.add_activity(ActivityType.USER)
Пример #11
0
 def create_menu_item(cls, menu=None, menu_item_parent=None, name="new item"):
     """
     This function creates a new MenuItem based on either:
     1. A parent Menu or
     2. A parent MenuItem
     If none of those is set, the function will abort and return null
     The MenuItem will be spawned with the lowest display order
     """
     if menu is None and menu_item_parent is None:
         return None
     db = Database()
     menu_item = MenuItem()
     menu_item.set_name(name)
     if menu is not None:
         menu_item.set_menu_id(menu.get_id())
         stmnt = "SELECT MAX(MNI_ORDER) AS MAXORDER FROM MENUITEMS WHERE MNI_MNU_ID = ? ;"
         cur = db.query(stmnt, (menu.get_id(),))
     if menu_item_parent is not None:
         menu_item.set_parent_menu_item_id(menu_item_parent.get_id())
         stmnt = "SELECT MAX(MNI_ORDER) AS MAXORDER FROM MENUITEMS WHERE MNI_MNI_ID = ? ;"
         cur = db.query(stmnt, (menu_item_parent.get_id(),))
     menu_item.set_id(db.get_seq_next('MNI_GEN'))
     row = cur.fetchonemap()
     if row["MAXORDER"] is not None:
         new_order = row["MAXORDER"]+1
     else:
         new_order = 0
     menu_item.set_order(new_order)
     stmnt = "INSERT INTO MENUITEMS VALUES (?,?,?,?,?,?) ;"
     db.query(stmnt,(menu_item.get_id(), menu_item.get_name(),
                               menu_item.get_menu_id(), menu_item.get_parent_menu_item_id(),
                               None, menu_item.get_order()),commit=True)
     db.commit()
     action_list = ActionList.create_action_list()
     menu_item.assign_action_list(action_list)
     PokeManager.add_activity(ActivityType.MENU)
     return menu_item
Пример #12
0
 def store(self):
     db = Database()
     if self._id is None:
         self.set_id(db.get_seq_next("ATV_GEN"))
     stmnt = "UPDATE OR INSERT INTO ACTIVITIES (ATV_ID, ATV_TYPE, ATV_SES_ID) VALUES (?,?,?) MATCHING (ATV_ID) ;"
     db.query(stmnt, (self.get_id(), self.get_activity_type(), self.get_session_id()), commit=True)
Пример #13
0
    def store(self, onlySpaceWidgetMapping=False, 
              onlyBoxMapping=False, onlyWidgetParamMapping=False):
        """
        stores this view in the database

        the programmer may store only parts of the view by activating several flags
        this is necessary to avoid a race condition between to simultaneous calls
        when editing a view.
        """
        onlyOneOperation = onlySpaceWidgetMapping or onlyBoxMapping or onlyWidgetParamMapping
        db = Database()
        if self._id is None:
            self._id = db.get_seq_next("VIE_GEN")
        
        # update the view itself
        stmnt = "UPDATE OR INSERT INTO VIEWS (VIE_ID, VIE_SIT_ID, VIE_VIE_BASEVIEW, \
                    VIE_NAME, VIE_DEFAULT) \
                 VALUES (?,?,?,?,?) MATCHING (VIE_ID) ;"
        db.query(stmnt, (self._id, self._page, self._baseview_id, self._name, int(self._default)), commit=True)

        if not onlyOneOperation or onlySpaceWidgetMapping:
            # Get current space-widgetmapping to determine, which mappings to delete
            stmnt = "SELECT VIW_SPA_ID, VIW_WGT_ID FROM VIEWWIDGETS WHERE VIW_VIE_ID = ? ;"
            cur = db.query(stmnt, (self.get_id(),))
            dbSpaceWidgetMap = {}
            for row in cur.fetchallmap():
                dbSpaceWidgetMap[row["VIW_SPA_ID"]] = row["VIW_WGT_ID"]

            # get space-widget-mapping of baseview to determine, which allocations are
            # identical to those of the baseview and thus shall not be stored
            if self.is_derived():
                stmnt = "SELECT VIW_SPA_ID, VIW_WGT_ID FROM VIEWWIDGETS \
                         WHERE VIW_VIE_ID = (SELECT VIE_VIE_BASEVIEW FROM VIEWS WHERE VIE_ID=?) ;"
                baseviewSpaceWidgetMap = {}
                cur = db.query(stmnt, (self.get_id(),))
                for row in cur.fetchallmap():
                    baseviewSpaceWidgetMap[row["VIW_SPA_ID"]] = row["VIW_WGT_ID"]

            # update widgets
            stmnt = "UPDATE OR INSERT INTO VIEWWIDGETS (VIW_VIE_ID, VIW_SPA_ID, VIW_WGT_ID) \
                      VALUES (?,?,?) MATCHING (VIW_VIE_ID, VIW_SPA_ID) ;"
            for space_id, widget_id in self._space_widget_mapping.items():
                # ignore allocation if present in baseview
                space_id = int(space_id)
                if self.is_derived() \
                        and baseviewSpaceWidgetMap.has_key(space_id) \
                        and baseviewSpaceWidgetMap[space_id] == widget_id:
                    continue
                db.query(stmnt,(self._id, int(space_id), int(widget_id)),commit=True)
                try:
                    del(dbSpaceWidgetMap[int(space_id)])
                except KeyError: pass

            # delete Removed Widgets
            stmnt = "DELETE FROM VIEWWIDGETS WHERE VIW_VIE_ID = ? AND VIW_SPA_ID = ? ;"
            for space_id in dbSpaceWidgetMap.keys():
                db.query(stmnt, (self.get_id(), space_id), commit=True)

        if not onlyOneOperation or onlyBoxMapping:
            # get current box_widget_mapping to determine which mappings to delete
            stmnt = "SELECT BWT_BOX_ID, BWT_WGT_ID FROM BOXWIDGETS WHERE BWT_VIE_ID = ? ;"
            cur = db.query(stmnt, (self.get_id(),))
            dbBoxMapping = {}
            for row in cur.fetchallmap():
                dbBoxMapping[(row["BWT_BOX_ID"],row["BWT_WGT_ID"])] = 1
            
            # get box widget mapping of baseview to ignore boxmappings that are
            # present in the baseview
            if self.is_derived():
                stmnt = "SELECT BWT_BOX_ID, BWT_WGT_ID, BWT_ORDER FROM BOXWIDGETS \
                         WHERE BWT_VIE_ID = (SELECT VIE_VIE_BASEVIEW FROM VIEWS WHERE VIE_ID=?) ;"
                baseviewBoxMapping = {}
                cur = db.query(stmnt, (self.get_id(),))
                for row in cur.fetchallmap():
                    baseviewBoxMapping[row["BWT_BOX_ID"],row["BWT_ORDER"]] = row["BWT_WGT_ID"]

            # insert new box-related entries and change existing ones
            stmnt = "UPDATE OR INSERT INTO BOXWIDGETS \
                      (BWT_BOX_ID, BWT_WGT_ID, BWT_ORDER, BWT_VIE_ID) \
                      VALUES (?,?,?,?) MATCHING (BWT_BOX_ID, BWT_VIE_ID, BWT_WGT_ID) ;"
            for box_id, boxcontent in self._box_mapping.items():
                order = 0
                for widget_id in boxcontent:
                    # ignore allocation if present in baseview
                    if self.is_derived() \
                            and baseviewBoxMapping.has_key((box_id,order)) \
                            and baseviewBoxMapping[box_id,order] == widget_id:
                        continue
                    db.query(stmnt, (box_id, widget_id, order, self.get_id()), \
                             commit=True)
                    try:
                        del(dbBoxMapping[(int(box_id),int(widget_id))])
                    except KeyError: pass
                    order +=1

            # delete boxwidgets that are not used anymore
            stmnt = "DELETE FROM BOXWIDGETS \
                     WHERE BWT_BOX_ID = ? AND BWT_WGT_ID = ? AND BWT_VIE_ID = ? ;"
            for box_id, widget_id in dbBoxMapping.keys():
                db.query(stmnt, (box_id, widget_id, self.get_id()), commit=True)

        if not onlyOneOperation or onlyWidgetParamMapping:
            # get all widget-param-mappings to determine which have to been deleted
            stmnt = "SELECT VWP_WGT_ID, VWP_KEY FROM VIEWWIDGETPARAMS WHERE VWP_VIE_ID = ? ;"
            cur = db.query(stmnt, (self.get_id(),))
            dbWidgetParamMap = {}
            for row in cur.fetchallmap():
                dbWidgetParamMap[(row["VWP_WGT_ID"],row["VWP_KEY"])] = 1

            # get widget-param-mappings of baseview to determine which mappings shall
            # not be stored
            if self.is_derived():
                stmnt =  "SELECT VWP_WGT_ID, VWP_KEY, VWP_VALUE FROM VIEWWIDGETPARAMS\
                          WHERE VWP_VIE_ID = (SELECT VIE_VIE_BASEVIEW FROM VIEWS WHERE VIE_ID=?) ;"
                baseviewWidgetParamMap = {}
                cur = db.query(stmnt, (self.get_id(),))
                for row in cur.fetchallmap():
                    baseviewWidgetParamMap[row["VWP_WGT_ID"], row["VWP_KEY"]] = row["VWP_VALUE"]

            # insert new widget params and update existing ones
            stmnt = "UPDATE OR INSERT INTO VIEWWIDGETPARAMS \
                      (VWP_VIE_ID, VWP_WGT_ID, VWP_KEY, VWP_VALUE) \
                      VALUES (?,?,?,?) MATCHING (VWP_VIE_ID, VWP_WGT_ID) ;"
            for widget_id, propdict in self._widget_param_mapping.items():
                for key, value in propdict.items():
                    #ignore if present in baseview:
                    if self.is_derived() \
                            and baseviewWidgetParamMap.has_key((widget_id, key)) \
                            and baseviewWidgetParamMap[widget_id, key] == value:
                        continue
                    db.query(stmnt,(self._id, int(widget_id), str(key), str(value)),\
                             commit=True)
                    try:
                        del(dbWidgetParamMap[(widget_id,key)])
                    except KeyError: pass

            # delete widget params that dont exist anymore
            stmnt = "DELETE FROM VIEWWIDGETPARAMS \
                     WHERE VPW_VIE_ID = ? AND VWP_WGT_ID = ? AND VWP_KEY = ? ;"
            for widget_id, key in dbWidgetParamMap.keys():
                db.query(stmnt, (self.get_id(), widget_id, key), commit=True)

        PokeManager.add_activity(ActivityType.VIEW)