コード例 #1
0
ファイル: view.py プロジェクト: skarphed/skarphed
    def generate_link_from_actionlist(self, actionlist):
        """
        returns a link that describes a call to a view that results of the actionlist
        """
        target = {}
        target['s'] = self.get_page()
        target['v'] = deepcopy(self.get_space_widget_mapping())
        target['b'] = deepcopy(self.get_box_mapping())
        target['c'] = deepcopy(self.get_widget_param_mapping())
        
        for action in actionlist.get_actions():
            if action.get_url() is not None:
                return action.get_url()
            elif action.get_view_id() is not None:
                view = View.get_from_id(action.get_view_id())
                name = view.get_name()
                return "/web/"+quote(name)
            elif action.get_space() is not None and action.get_widget_id() is not None:
                target['v'][action.get_space()] = action.get_widget_id()
                #delete any parameters of this widget. otherwise link will only
                #load current state of that widget again
                if target['c'].has_key(action.get_widget_id()):
                    del(target['c'][action.get_widget_id()])

        #AJAX-rendermode regarded here: ↓
        encoder = JSONEncoder()
        viewjsonstring = quote(encoder.encode(target))
        checkview = View.get_from_json(viewjsonstring)
        existing_name = checkview.check_has_name()
        if existing_name == False:
            return "/web/?"+viewjsonstring
        else:
            return "/web/"+existing_name
コード例 #2
0
ファイル: module.py プロジェクト: skarphed/skarphed
    def uninstall_module(cls,module, hard=False):
        """
        uninstall a module
        the flag "hard" actually deletes the files of this module in modpath
        module can be module or module meta
        """
        if module.__class__.__name__ != "Module":
            nr = cls._get_module_id_from_name(module_meta["name"])
            module = cls.get_module(nr)

        Action.delete_actions_with_module(module)
        View.delete_mappings_with_module(module)
        CSSManager().delete_definitions_with_module(module)

        db = Database()
        db.remove_tables_for_module(module)
        Permission.remove_permissions_for_module(module)

        if hard:
            modpath = Configuration().get_entry('global.modpath')
            version = module.get_version()
            shutil.rmtree(modpath+"/"+module.get_name()+"/v"+version[0]+"_"+version[1]+"_"+version[2])

        cls._unregister_module(module)
        PokeManager.add_activity(ActivityType.MODULE)
コード例 #3
0
ファイル: view.py プロジェクト: skarphed/skarphed
 def derive(self):
     """
     Creates a view derived from this view
     """
     view = View()
     view.set_baseview_id(self.get_id())
     view.set_page(self._page)
     return view
コード例 #4
0
ファイル: view.py プロジェクト: skarphed/skarphed
    def generate_link_from_actionlist(self, actionlist):
        """
        Generates an ajaxlink from an actionlist.
        ajaxlinks look like:
        javascript:SkdAjax.load_link([{'w':<widget_id>,'p':{params}}, ... ])

        the corresponding js on clientside should generate something like:
        /ajax/{'w':<widget_id>,'p':{params}}
        """
        link = "javascript:window.SkdAJAX.execute_action(%s);"
        linkjson = []
        for action in actionlist.get_actions():
            if action.get_url() is not None:
                return action.get_url()
            elif action.get_view_id() is not None:
                view = View.get_from_id(action.get_view_id())
                name = view.get_name()
                return "/web/"+quote(name)
            elif action.get_space() is not None and action.get_widget_id() is not None:
                page = Page.get_page(self.get_page())
                space_names = page.get_space_names()
                space_name = space_names[action.get_space()]
                linkjson.append({"w":action.get_widget_id(), "s":space_name, "p":{}})
        encoder = JSONEncoder()
        ajaxdata = encoder.encode(linkjson)
        ajaxdata = ajaxdata.replace('"',"'")
        return link%ajaxdata
コード例 #5
0
ファイル: view.py プロジェクト: skarphed/skarphed
    def generate_link_from_dict(self, dct):
        """
        Creates a link by analyzing a view-dictionary and merging it to this view
        The incoming dictionary can be thought of as a diff that is added to the 
        existing view.
        Does not affect the View itself.
        """
        target = {}
        target['s'] = self.get_page()
        target['v'] = deepcopy(self.get_space_widget_mapping())
        target['b'] = deepcopy(self.get_box_mapping())
        target['c'] = deepcopy(self.get_widget_param_mapping())
        
        if dct.has_key('s'):
            target['s'] = dct['s']
        if dct.has_key('v'):
            target['v'].update(dct['v'])
        if dct.has_key('b'):
            target['b'].update(dct['b'])
        if dct.has_key('c'):
            for widget_id in dct['c'].keys():
                target['c'][widget_id] = dct['c'][widget_id]
        if dct.has_key('p'):
            target['p'] = dct['p']

        encoder = JSONEncoder()
        viewjsonstring = quote(encoder.encode(target))
        checkview = View.get_from_json(viewjsonstring)
        existing_name = checkview.check_has_name()
        if existing_name == False:
            return "/web/?"+viewjsonstring
        else:
            return "/web/"+existing_name
コード例 #6
0
ファイル: rpc.py プロジェクト: skarphed/skarphed
    def removeWidgetFromSpace(self, params):
        view_id = int(params[0])
        space_id = int(params[1])

        view = View.get_from_id(view_id)
        view.remove_widget_from_space(space_id)
        view.store()
コード例 #7
0
ファイル: module.py プロジェクト: skarphed/skarphed
    def delete(self):
        db = Database()

        if self._id is None:
            raise ModuleCoreException(ModuleCoreException.get_msg(2))

        Action.delete_actions_with_widget(self)

        View.delete_mappings_with_widget(self)

        css_manager = CSSManager()
        css_manager.delete_definitions_with_widget(self)

        stmnt = "DELETE FROM WIDGETS WHERE WGT_ID = ? ;"
        db.query(stmnt,(self._id,),commit=True)
        PokeManager.add_activity(ActivityType.WIDGET)
コード例 #8
0
ファイル: module.py プロジェクト: skarphed/skarphed
 def generate_view(self, viewname, commands):
     """
     Actually generates a named view of the viewname,
     The baseview for this Widget, the space that has been set
     to be the target in the baseview and the set of
     commands provided in the dictionary commands
     """
     module = self.get_module()
     try:
         setting = module.get_config_entry("generate_views", self.get_id())
     except ConfigurationException:
         setting = "False"
     if setting == "True":
         newview = View.get_from_id(self.get_baseview_id()).derive()
         viewname = sluggify(viewname)
         extcount = 0
         while True:
             try:
                 viewmanager.get_from_name(viewname)
             except ViewException:
                 break
             else:
                 extcount +=1
                 viewname = viewname[:-int(1+(math.ceil(math.log(extcount,10))))]+str(extcount)
         newview.set_name(viewname)
         newview.get_space_widget_mapping()[self.get_baseview_space_id()] = self.get_id()
         newview.get_widget_param_mapping()[self.get_id()] = commands
         newview.store()
コード例 #9
0
ファイル: rpc.py プロジェクト: skarphed/skarphed
    def setWidgetParamMapping(self, params):
        view_id = int(params[0])
        widget_id = int(params[1])
        mapping = int(params[2])

        view = View.get_from_id(view_id)
        view.set_params_for_widget(widget_id, mapping)
        view.store(onlyWidgetParamMapping=True)
コード例 #10
0
ファイル: rpc.py プロジェクト: skarphed/skarphed
    def setSpaceWidgetMapping(self, params):
        view_id = int(params[0])
        mapping = dict(params[1])

        view = View.get_from_id(view_id)
        view.set_space_widget_mapping(mapping)
        view.store(onlySpaceWidgetMapping=True)
        return True
コード例 #11
0
ファイル: rpc.py プロジェクト: skarphed/skarphed
    def setBoxMapping(self, params):
        view_id = int(params[0])
        mapping = dict(params[1])

        view = View.get_from_id(view_id)
        view.set_box_mapping(mapping)
        view.store(onlyBoxMapping=True)
        return True
コード例 #12
0
ファイル: rpc.py プロジェクト: skarphed/skarphed
    def assignWidgetToSpace(self,params):
        view_id = int(params[0])
        space_id = int(params[1])
        widget_id = int(params[2])

        view = View.get_from_id(view_id)
        view.place_widget_in_space(space_id, widget_id)
        view.store()
コード例 #13
0
ファイル: rpc.py プロジェクト: skarphed/skarphed
    def widgetActivateViewGeneration(self, params):
        widget_id = int(params[0])
        view_id = int(params[1])
        space_id = int(params[2])

        view = View.get_from_id(view_id)
        widget = ModuleManager.get_widget(widget_id)
        widget.activate_viewgeneration(view, space_id)
        return
コード例 #14
0
ファイル: action.py プロジェクト: skarphed/skarphed
 def render_link(self):
     """
     This method renders an actual link that can be used my a module that
     renders a menu. This method only works if there is currently a view being
     rendered.
     """
     view = View.get_currently_rendering_view()
     if view is None:
         return ""
     return view.generate_link_from_actionlist(self)
コード例 #15
0
ファイル: rpc.py プロジェクト: skarphed/skarphed
    def getView(self, params):
        view_id = int(params[0])

        view = View.get_from_id(view_id)
        ret = {
            'id' : view.get_id(),
            'name' : view.get_name(),
            'site' : view.get_page(),
            'default' : view.get_default(),
            'space_widget_mapping' : view.get_space_widget_mapping(),
            'box_mapping': view.get_box_mapping(),
            'widget_param_mapping' : view.get_widget_param_mapping()
        }
        return ret
コード例 #16
0
ファイル: action.py プロジェクト: skarphed/skarphed
    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
コード例 #17
0
ファイル: action.py プロジェクト: skarphed/skarphed
    def set_view_id(self, view_id, ignore_db = False):
        """
        Make this a View-Link that links to another
        Skarphed-View
        Resets Widget/Page- and URL-Linkattributes
        """
        if View.get_from_id(view_id) is not None:
            self._view_id = int(view_id)
            self._widget_id = None
            self._space_id = None
            self._url = None
        else:
            return

        if not ignore_db:
            db = Database()
            stmnt = "UPDATE ACTIONS SET ACT_URL = NULL, ACT_VIE_ID = ?, \
                     ACT_WGT_ID = NULL, ACT_SPA_ID = NULL WHERE ACT_ID = ? ;"
            db.query(stmnt,(self.get_view_id(),self.get_id()),commit=True)
            PokeManager.add_activity(ActivityType.MENU)
コード例 #18
0
ファイル: template.py プロジェクト: skarphed/skarphed
                    new_template.add_binary(binary.get_id())

            except IOError, e:
                errorlog.append({'severity':0,
                               'type':'PageFile',
                               'msg':'File seems broken static/'+bin_filename})


        #read general.css into CSSPropertysets
        general_csspropertyset.store()

        new_template.store()
        cleanup(temp_installpath)

        #create a defaultview if there isnt
        View.create_default_view()

        if release_maintenance_mode:
            Core().deactivate_maintenance_mode()

        return errorlog


    @classmethod
    def is_template_installed(cls):
        """
        checks whether there is a template installed
        """
        db = Database()
        stmnt = "SELECT COUNT(*) AS AMNT FROM TEMPLATE_INFO ;"
        cur = db.query(stmnt)
コード例 #19
0
ファイル: view.py プロジェクト: skarphed/skarphed
    def render(self, environ):
        View.set_currently_rendering_view(self)
        frame = """
        <!DOCTYPE html>
        <html>
          <head>
            <title>%(title)s</title>
            <link href="/static/%(page_css)s" rel="stylesheet" type="text/css">
            <link href="%(scv_css)s" rel="stylesheet" type="text/css">
            %(head)s
            <script type="text/javascript">%(ajax_script)s</script>
          </head>
          <body>
            %(body)s
          </body>
        </html>
        """
        js_frame = """<script type="text/javascript" id="%d_scr">%s</script>"""
        page = Page.get_page(self._page) 

        head = page.get_html_head()
        body = page.get_html_body()

        # Find placeholders to substitute
        
        space_name_map = page.get_space_names()
        for space, widget_id in self._space_widget_mapping.items():
            space_name = space_name_map[space]
            widget = ModuleManager.get_widget(widget_id)

            args = {} 
            if self._widget_param_mapping.has_key(widget_id):
                args.update(self._widget_param_mapping[widget_id])
            elif self._widget_param_mapping.has_key(str(widget_id)):
                args.update(self._widget_param_mapping[str(widget_id)])
            
            if self._post_widget_id == widget_id:
                # Check whether the viewjson-string is included here, too:
                # if so, eliminate it.
                post_args = FieldStorage(fp=environ['wsgi.input'],environ=environ)
                for key in post_args.keys():
                    args[key] = post_args[key].value

            widget_html = widget.render_html(args)
            widget_js = widget.render_javascript(args)
            widget_html += js_frame%(widget.get_id(), widget_js)
            body = re.sub(r"<%%\s?space:%s\s?%%>"%space_name,widget_html,body)

        for box, boxcontent in self._box_mapping.items():
            box_orientation, box_name = self.get_box_info(box)
            box_html = StringIO.StringIO()
            for widget_id in boxcontent:
                widget = ModuleManager.get_widget(widget_id)

                args = {} 
                if self._widget_param_mapping.has_key(widget_id):
                    args.update(self._widget_param_mapping[widget_id])
                elif self._widget_param_mapping.has_key(str(widget_id)):
                    args.update(self._widget_param_mapping[str(widget_id)])

                if self._post_widget_id == widget_id:
                    # Check whether the viewjson-string is included here, too:
                    # if so, eliminate it.
                    post_args = FieldStorage(fp=environ['wsgi.input'],environ=environ)
                    for key in post_args.keys():
                        args[key] = post_args[key].value
            
                widget_html = widget.render_html(args)
                widget_js = widget.render_javascript(args)
                widget_html += js_frame%(widget.get_id(), widget_js)
                box_html.write(widget_html)
                if box_orientation == BoxOrientation.VERTICAL:
                    box_html.write("<br>")

            if box_orientation == BoxOrientation.HORIZONTAL:
                body = re.sub(r"<%%\s?hbox:%s\s?%%>"%box_name,box_html.getvalue(),body)
            elif box_orientation == BoxOrientation.VERTICAL:
                body = re.sub(r"<%%\s?vbox:%s\s?%%>"%box_name,box_html.getvalue(),body)

        body = re.sub(r"<%[^%>]+%>","",body) #Replace all unused spaces with emptystring

        css_manager = CSSManager()
        css_url = css_manager.get_css_url()

        configuration = Configuration()
        title = configuration.get_entry("core.name")

        page_css = page.get_css_filename()
        View.set_currently_rendering_view(None)
        return frame%{'title':title,
                      'scv_css':css_url,
                      'page_css':page_css,
                      'ajax_script':AJAXScript,
                      'head':head,
                      'body':body}
コード例 #20
0
ファイル: rpc.py プロジェクト: skarphed/skarphed
 def retrieveViews(self, params):
     return View.get_viewlist()
コード例 #21
0
ファイル: view.py プロジェクト: skarphed/skarphed
 def clone(self):
     view = View()
     view.set_space_widget_mapping(deepcopy(self.get_space_widget_mapping()))
     view.set_box_mapping(deepcopy(self.get_box_mapping()))
     view.set_widget_param_mapping(deepcopy(self.get_widget_param_mapping()))
     view.set_page(self.get_page())
     postwidget_id = self.get_post_widget_id()
     if postwidget_id is not None:
         view.set_post_widget_id(postwidget_id)
     return view