示例#1
0
    def _del_path_pattern(self, req):
        """ del filter
        """
        path_pattern = req.args.get("path_pattern", "").strip()

        # add to db
        TracTweakUIModel.del_path_pattern(self.env, path_pattern)
示例#2
0
    def _del_path_pattern(self, req):
        """ del filter
        """
        path_pattern = req.args.get("path_pattern", "").strip()

        # add to db
        TracTweakUIModel.del_path_pattern(self.env, path_pattern)
示例#3
0
    def _add_path_pattern(self, req):
        """ add filter
        """
        path_pattern = req.args.get("path_pattern", "").strip()

        # add to db
        TracTweakUIModel.insert_path_pattern(self.env, path_pattern)
示例#4
0
    def _add_path_pattern(self, req):
        """ add filter
        """
        path_pattern = req.args.get("path_pattern", "").strip()

        # add to db
        TracTweakUIModel.insert_path_pattern(self.env, path_pattern)
示例#5
0
    def filter_stream(self, req, method, filename, stream, data):
        try:
            # get all path patterns
            path_patterns = TracTweakUIModel.get_path_patterns(self.env)
            # try to match pattern
            for path_pattern in path_patterns:
                if re.match(path_pattern, req.path_info):
                    break
            else:
                return stream

            filter_names = TracTweakUIModel.get_path_filters(self.env, path_pattern)
            for filter_name in filter_names:
                self._apply_filter(req, path_pattern, filter_name)
                
            js_files = TracTweakUIModel.get_path_scripts(self.env, path_pattern)
            if js_files:
                script = ";\n".join(js_files)
            else:
                script = ""            
            
            stream = stream | Transformer('head').append(tag.script(Markup(script), type="text/javascript")())
            return stream
        except:
            return stream
示例#6
0
    def filter_stream(self, req, method, filename, stream, data):
        try:
            # get all path patterns
            path_patterns = TracTweakUIModel.get_path_patterns(self.env)
            # try to match pattern
            for path_pattern in path_patterns:
                if re.match(path_pattern, req.path_info):
                    break
            else:
                return stream

            filter_names = TracTweakUIModel.get_path_filters(
                self.env, path_pattern)
            for filter_name in filter_names:
                self._apply_filter(req, path_pattern, filter_name)

            js_files = TracTweakUIModel.get_path_scripts(
                self.env, path_pattern)
            if js_files:
                script = ";\n".join(js_files)
            else:
                script = ""

            stream = stream | Transformer('head').append(
                tag.script(Markup(script), type="text/javascript")())
            return stream
        except:
            return stream
示例#7
0
    def _save_path_pattern(self, req):
        """ add filter
        """
        path_pattern = req.args.get("path_pattern", "").strip()
        path_pattern_orig = req.args.get("path_pattern_orig", "").strip()

        # add to db
        TracTweakUIModel.save_path_pattern(self.env, path_pattern, path_pattern_orig)
示例#8
0
    def _save_path_pattern(self, req):
        """ add filter
        """
        path_pattern = req.args.get("path_pattern", "").strip()
        path_pattern_orig = req.args.get("path_pattern_orig", "").strip()

        # add to db
        TracTweakUIModel.save_path_pattern(self.env, path_pattern,
                                           path_pattern_orig)
示例#9
0
    def _save_tweak_script(self, req):
        """ save tweak_script
        """
        filter_name = req.args.get("filter_name", "").strip()
        path_pattern = req.args.get("path_pattern", "").strip()
        tweak_script = req.args.get("tweak_script", "").strip()

        # add to db
        TracTweakUIModel.save_tweak_script(self.env, path_pattern, filter_name, tweak_script)
示例#10
0
    def _save_tweak_script(self, req):
        """ save tweak_script
        """
        filter_name = req.args.get("filter_name", "").strip()
        path_pattern = req.args.get("path_pattern", "").strip()
        tweak_script = req.args.get("tweak_script", "").strip()

        # add to db
        TracTweakUIModel.save_tweak_script(self.env, path_pattern, filter_name,
                                           tweak_script)
示例#11
0
    def filter_stream(self, req, method, filename, stream, data):
        # get all path patterns
        path_patterns = TracTweakUIModel.get_path_patterns(self.env)
        # try to match pattern
        for path_pattern in path_patterns:
            if re.match(path_pattern, req.path_info):
                break
        else:
            return stream

        filter_names = TracTweakUIModel.get_path_filters(self.env, path_pattern)
        for filter_name in filter_names:
            stream = self._apply_filter(req, stream, path_pattern, filter_name)
        stream = stream | Transformer('head').append(
            tag.script(type="text/javascript", 
            src= req.base_path + "/tractweakui/tweakui_js/" + urllib.quote(path_pattern, "") + ".js")()
            )

        return stream
示例#12
0
    def filter_stream(self, req, method, filename, stream, data):
        # get all path patterns
        path_patterns = TracTweakUIModel.get_path_patterns(self.env)
        # try to match pattern
        for path_pattern in path_patterns:
            if re.match(path_pattern, req.path_info):
                break
        else:
            return stream

        filter_names = TracTweakUIModel.get_path_filters(
            self.env, path_pattern)
        for filter_name in filter_names:
            stream = self._apply_filter(req, stream, path_pattern, filter_name)
        stream = stream | Transformer('head').append(
            tag.script(type="text/javascript",
                       src=req.base_path + "/tractweakui/tweakui_js/" +
                       urllib.quote(path_pattern, "") + ".js")())

        return stream
示例#13
0
    def process_request(self, req):
        filter_base_path = os.path.normpath(os.path.join(self.env.path, "htdocs", "tractweakui"))
        if not os.path.exists(filter_base_path):
            return self._send_response(req, "")

        tweakui_js_path = '/tractweakui/tweakui_js'
        if req.path_info.startswith(tweakui_js_path):
            path_pattern = urllib.unquote(req.path_info[len(tweakui_js_path) + 1: -3])
            js_files = TracTweakUIModel.get_path_scripts(self.env, path_pattern)
            if js_files:
                script = ";\n".join(js_files)
            else:
                script = ""
            self._send_response(req, script)
示例#14
0
    def process_request(self, req):
        filter_base_path = os.path.normpath(
            os.path.join(self.env.path, "htdocs", "tractweakui"))
        if not os.path.exists(filter_base_path):
            return self._send_response(req, "")

        tweakui_js_path = '/tractweakui/tweakui_js'
        if req.path_info.startswith(tweakui_js_path):
            path_pattern = req.path_info[len(tweakui_js_path) + 1:-3]
            js_files = TracTweakUIModel.get_path_scripts(
                self.env, path_pattern)
            if js_files:
                script = ";\n".join(js_files)
            else:
                script = ""
            self._send_response(req, script,
                                {'Content-Type': 'text/x-javascript'})
示例#15
0
    def render_admin_panel(self, req, cat, page, path_info):
        req.perm.assert_permission('TRACTWEAKUI_ADMIN')

        data = {}
        data["page"] = page
        data["encode_url"] = encode_url
        #print cat, page, path_info

        # Analyze url
        action = ""
        if path_info:
            try:
                action, args = path_info.split('?', 1)
                action = action.strip("/")
            except:
                action = path_info.strip("/")
                args = None

        if action:
            if action == "edit_path_pattern":
                # edit path_pattern
                if req.method == 'POST':
                    # TODO
                    if 'save' in req.args:
                        # save filter
                        path_pattern = req.args.get("path_pattern", "").strip()
                        path_pattern_orig = req.args.get(
                            "path_pattern_orig", "").strip()
                        self._save_path_pattern(req)

                        req.redirect(req.abs_href.admin(cat, page))

                    elif 'delete' in req.args:
                        # delete filter
                        path_pattern = req.args.get("path_pattern", "").strip()
                        self._del_path_pattern(req)
                        req.redirect(req.abs_href.admin(cat, page))

                else:
                    # list filters
                    path_pattern = req.args.get("path_pattern", "").strip()
                    data["filter_names"] = self._get_filters()
                    data["path_pattern"] = req.args.get("path_pattern",
                                                        "").strip()
                    #print data
                    return 'tractweakui_admin_list_filter.html', data

            elif action.startswith("edit_filter_script"):
                # edit script
                if req.method == 'POST':
                    if 'save' in req.args:
                        # save filter
                        self._save_tweak_script(req)
                        #req.redirect(req.abs_href.admin(cat, page, path_info))
                        path_pattern = req.args.get("path_pattern", "").strip()
                        data["filter_names"] = self._get_filters()
                        data["path_pattern"] = req.args.get(
                            "path_pattern", "").strip()
                        #print data
                        return 'tractweakui_admin_list_filter.html', data

                    elif 'load_default' in req.args:
                        # load_default js script
                        data['path_pattern'] = req.args.get(
                            "path_pattern", "").strip()
                        data['filter_name'] = req.args.get("filter_name",
                                                           "").strip()
                        data['tweak_script'] = self._load_default_script(req)
                        #print data
                        return 'tractweakui_admin_edit_filter.html', data

                else:
                    # display filter details
                    path_pattern = req.args.get("path_pattern", "").strip()
                    filter_name = req.args.get("filter_name", "").strip()
                    tweak_script = TracTweakUIModel.get_tweak_script(
                        self.env, path_pattern, filter_name)
                    data['tweak_script'] = tweak_script
                    data['path_pattern'] = path_pattern
                    data['filter_name'] = filter_name
                    return 'tractweakui_admin_edit_filter.html', data

            elif action == "add_path_pattern":
                # add path pattern
                if req.method == 'POST':
                    if 'add' in req.args:
                        self._add_path_pattern(req)
                        req.redirect(req.abs_href.admin(cat, page))
        else:
            # list all path patterns
            data["path_patterns"] = TracTweakUIModel.get_path_patterns(
                self.env)
            return 'tractweakui_admin_list_path.html', data
示例#16
0
    def render_admin_panel(self, req, cat, page, path_info):
        req.perm.assert_permission('TRACTWEAKUI_ADMIN')

        data = {}
        data["page"] = page
        data["encode_url"] = encode_url
        #print cat, page, path_info

        # Analyze url
        action = ""
        if path_info:
            try:
                action, args = path_info.split('?', 1)
                action = action.strip("/")
            except:
                action = path_info.strip("/")
                args = None

        if action:
            if action == "edit_path_pattern":
                # edit path_pattern
                if req.method == 'POST':
                    # TODO
                    if 'save' in req.args:
                        # save filter
                        path_pattern = req.args.get("path_pattern", "").strip()
                        path_pattern_orig = req.args.get("path_pattern_orig", "").strip()
                        self._save_path_pattern(req)
                        
                        req.redirect(req.abs_href.admin(cat, page))

                    elif 'delete' in req.args:
                        # delete filter
                        path_pattern = req.args.get("path_pattern", "").strip()
                        self._del_path_pattern(req)
                        req.redirect(req.abs_href.admin(cat, page))

                else:
                    # list filters
                    path_pattern = req.args.get("path_pattern", "").strip()
                    data["filter_names"] = self._get_filters()
                    data["path_pattern"] = req.args.get("path_pattern", "").strip()
                    #print data
                    return 'tractweakui_admin_list_filter.html', data

            elif action.startswith("edit_filter_script"):
                # edit script
                if req.method == 'POST':
                    if 'save' in req.args:
                        # save filter
                        self._save_tweak_script(req)
                        #req.redirect(req.abs_href.admin(cat, page, path_info))
                        path_pattern = req.args.get("path_pattern", "").strip()
                        data["filter_names"] = self._get_filters()
                        data["path_pattern"] = req.args.get("path_pattern", "").strip()
                        #print data
                        return 'tractweakui_admin_list_filter.html', data

                    elif 'load_default' in req.args:
                        # load_default js script
                        data['path_pattern'] = req.args.get("path_pattern", "").strip()
                        data['filter_name'] = req.args.get("filter_name", "").strip()
                        data['tweak_script'] = self._load_default_script(req)
                        #print data
                        return 'tractweakui_admin_edit_filter.html', data

                else:
                    # display filter details
                    path_pattern = req.args.get("path_pattern", "").strip()
                    filter_name = req.args.get("filter_name", "").strip()
                    tweak_script = TracTweakUIModel.get_tweak_script(self.env, path_pattern, filter_name)
                    data['tweak_script'] = tweak_script
                    data['path_pattern'] = path_pattern
                    data['filter_name'] = filter_name
                    return 'tractweakui_admin_edit_filter.html', data

            elif action == "add_path_pattern":
                # add path pattern
                if req.method == 'POST':
                    if 'add' in req.args:
                        self._add_path_pattern(req)
                        req.redirect(req.abs_href.admin(cat, page))
        else:
            # list all path patterns
            data["path_patterns"] = TracTweakUIModel.get_path_patterns(self.env)
            return 'tractweakui_admin_list_path.html', data