コード例 #1
0
    def handle_config2(my):
        """for db column search config stuff, not used yet"""
        web = WebContainer.get_web()

        search_type = "SearchTypeSchema"
        view = "definition"

        config_search_type = "config/widget_config"

        search = Search(config_search_type)
        search.add_filter("search_type", search_type)
        search.add_filter("view", view)
        config = search.get_sobject()
        if not config:
            config = SearchType.create(config_search_type)
            config.set_value("search_type", search_type)
            config.set_value("view", view)
            xml = config.get_xml_value("config", "config")
            root = xml.get_root_node()
            # reinitialize
            config._init()

            # build a new config
            view_node = xml.create_element(view)
            root.appendChild(view_node)

        config_mode = web.get_form_value("config_mode")
        if config_mode == "advanced":
            config_string = web.get_form_value("config_xml")
        else:
            config_data_type = web.get_form_value("config_data_type")
            if config_data_type == "Other...":
                config_data_type = web.get_form_value("config_data_type_custom")
            config_nullable = web.get_form_value("config_nullable")

            # TAKEN FROM API: should be centralized or something
            from tactic.ui.panel import SideBarBookmarkMenuWdg

            config_view = SideBarBookmarkMenuWdg.get_config(search_type, view)
            node = config_view.get_element_node(my.element_name)
            if node:
                config_xml = config_view.get_xml()

                node = config_view.get_element_node(my.element_name)
                Xml.set_attribute(node, "data_type", config_data_type)
                Xml.set_attribute(node, "nullable", config_nullable)
                Xml.set_attribute(node, "new", "True")

                config_string = config_xml.to_string(node)
            else:
                config_string = """
                <element name="%s" data_type="%s" nullable="%s" new="True"/>
                """ % (
                    my.element_name,
                    config_data_type,
                    config_nullable,
                )

        config.append_xml_element(my.element_name, config_string)
        config.commit_config()
コード例 #2
0
    def handle_config2(my):
        '''for db column search config stuff, not used yet'''
        web = WebContainer.get_web()

        search_type = "SearchTypeSchema"
        view = "definition"

        config_search_type = "config/widget_config"

        search = Search(config_search_type)
        search.add_filter("search_type", search_type)
        search.add_filter("view", view)
        config = search.get_sobject()
        if not config:
            config = SearchType.create(config_search_type)
            config.set_value("search_type", search_type)
            config.set_value("view", view)
            xml = config.get_xml_value("config", "config")
            root = xml.get_root_node()
            # reinitialize
            config._init()

            # build a new config
            view_node = xml.create_element(view)
            root.appendChild(view_node)

        config_mode = web.get_form_value("config_mode")
        if config_mode == "advanced":
            config_string = web.get_form_value("config_xml")
        else:
            config_data_type = web.get_form_value("config_data_type")
            if config_data_type == 'Other...':
                config_data_type = web.get_form_value(
                    "config_data_type_custom")
            config_nullable = web.get_form_value("config_nullable")

            # TAKEN FROM API: should be centralized or something
            from tactic.ui.panel import SideBarBookmarkMenuWdg
            config_view = SideBarBookmarkMenuWdg.get_config(search_type, view)
            node = config_view.get_element_node(my.element_name)
            if node:
                config_xml = config_view.get_xml()

                node = config_view.get_element_node(my.element_name)
                Xml.set_attribute(node, "data_type", config_data_type)
                Xml.set_attribute(node, "nullable", config_nullable)
                Xml.set_attribute(node, "new", "True")

                config_string = config_xml.to_string(node)
            else:
                config_string = '''
                <element name="%s" data_type="%s" nullable="%s" new="True"/>
                ''' % (my.element_name, config_data_type, config_nullable)

        config.append_xml_element(my.element_name, config_string)
        config.commit_config()
コード例 #3
0
ファイル: hash_panel_wdg.py プロジェクト: lucasnemeth/TACTIC
    def _get_predefined_url(cls, key, hash):

        # make some predefined fake urls
        if key in ["link", "tab", "admin"]:
            # this is called by PageNav
            if key == "admin":
                expression = "/admin/link/{link}"
            else:
                expression = "/%s/{link}" % key
            options = Common.extract_dict(hash, expression)
            link = options.get("link")

            if not link:
                return None


            # test link security
            project_code = Project.get_project_code()
            security = Environment.get_security()
            keys = [
                    { "element": link },
                    { "element": "*" },
                    { "element": link, "project": project_code },
                    { "element": "*", "project": project_code }
            ]
            if not security.check_access("link", keys, "allow", default="deny"):
                return None


            from tactic.ui.panel import SideBarBookmarkMenuWdg
            personal = False
            if '.' in link:
                personal = True



            config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", link, personal=personal)
            options = config.get_display_options(link)
            if not options:

                from pyasm.biz import Schema
                config_xml = []
                config_xml.append( '''
                <config>
                ''')
         
                config_schema = Schema.get_predefined_schema('config')
                SideBarBookmarkMenuWdg.get_schema_snippet("_config_schema", config_schema, config_xml)
                schema = Schema.get_admin_schema()
                SideBarBookmarkMenuWdg.get_schema_snippet("_admin_schema", schema, config_xml)

                config_xml.append( '''
                </config>
                ''')

                xml = "".join(config_xml)

                from pyasm.widget import WidgetConfig
                schema_config = WidgetConfig.get(view="_admin_schema", xml=xml)
                options = schema_config.get_display_options(link)
                if not options:
                    schema_config.set_view("_config_schema")
                    options = schema_config.get_display_options(link)

                if not options:
                    return None




            class_name = options.get("class_name")
            widget_key = options.get("widget_key")
            if widget_key:
                class_name = WidgetClassHandler().get_display_handler(widget_key)
            elif not class_name:
                class_name = 'tactic.ui.panel.ViewPanelWdg'


            if key in ["admin", "tab"]:
                use_index = "false"
            else:
                use_index = "true"

            if key in ['admin']:
                use_admin = "true"
            else:
                use_admin = "false"


            xml = []
            xml.append('''<element admin="%s" index="%s">''' % (use_admin, use_index))
            xml.append('''  <display class="%s">''' % class_name)
            for name, value in options.items():
                xml.append("<%s>%s</%s>" % (name, value, name) )
            xml.append('''  </display>''')
            xml.append('''</element>''')

            xml = "\n".join(xml)

            sobject = SearchType.create("config/url")
            sobject.set_value("url", "/%s/{value}" % key)
            sobject.set_value("widget", xml )

            return sobject
 
        else:
            return None
コード例 #4
0
    def _get_predefined_url(cls, key, hash):

        # only allow people with site admin
        security = Environment.get_security()
        is_admin = security.is_admin()
        if not is_admin and key == "admin":
            return None
 
 
        # make some predefined fake urls
        if key in ["link", "tab", "admin"]:
            # this is called by PageNav
            if key == "admin":
                expression = "/admin/link/{link}"
            else:
                expression = "/%s/{link}" % key
            options = Common.extract_dict(hash, expression)
            link = options.get("link")
            
            if not link:
                return None


            from tactic.ui.panel import SideBarBookmarkMenuWdg
            personal = False
            if '.' in link:

                # put in a check to ensure this is a user
                parts = link.split(".")

                user = Environment.get_user_name()
                
                def is_personal(user, parts):
                    '''See if parts contains period
                       seperated form of username.'''
                    acc = ""
                    for part in parts:
                        if acc == "":
                            acc = part
                        else:
                            acc = "%s.%s" % (acc, part)
                        if user == acc:
                            return True
                    return False

                personal = is_personal(user, parts) 
                
            # test link security
            project_code = Project.get_project_code()
            security = Environment.get_security()
            keys = [
                    { "element": link },
                    { "element": "*" },
                    { "element": link, "project": project_code },
                    { "element": "*", "project": project_code }
            ]
            if not personal and not security.check_access("link", keys, "allow", default="deny"):
                print "Not allowed"
                return None


            # This is used to find a sub menu (?)
            #view = link
            view = "definition"
            config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", view, personal=personal)

            view = config.get_element_attribute(link, 'view')
            if view:
                options['widget_key'] = 'custom_layout'
                options['view'] = view
                class_name = None
            else:
                options = config.get_display_options(link)
                class_name = config.get_display_handler(link)


            if not options:

                from pyasm.biz import Schema
                config_xml = []
                config_xml.append( '''
                <config>
                ''')
         
                config_schema = Schema.get_predefined_schema('config')
                SideBarBookmarkMenuWdg.get_schema_snippet("_config_schema", config_schema, config_xml)
                schema = Schema.get_admin_schema()
                SideBarBookmarkMenuWdg.get_schema_snippet("_admin_schema", schema, config_xml)

                config_xml.append( '''
                </config>
                ''')

                xml = "".join(config_xml)

                from pyasm.widget import WidgetConfig
                schema_config = WidgetConfig.get(view="_admin_schema", xml=xml)
                options = schema_config.get_display_options(link)
                if not options:
                    schema_config.set_view("_config_schema")
                    options = schema_config.get_display_options(link)

                if not options:
                    return None


            if not class_name or class_name == "LinkWdg":
                class_name = options.get("class_name")

            widget_key = options.get("widget_key")


            if widget_key:
                class_name = WidgetClassHandler().get_display_handler(widget_key)
            elif not class_name:
                class_name = 'tactic.ui.panel.ViewPanelWdg'


            if key in ["admin", "tab"]:
                use_index = "false"
            else:
                use_index = "true"

            if key in ['admin']:
                use_admin = "true"
            else:
                use_admin = "false"


            xml = []
            xml.append('''<element admin="%s" index="%s">''' % (use_admin, use_index))
            xml.append('''  <display class="%s">''' % class_name)
            for name, value in options.items():
                xml.append("<%s>%s</%s>" % (name, value, name) )
            xml.append('''  </display>''')
            xml.append('''</element>''')

            xml = "\n".join(xml)

            sobject = SearchType.create("config/url")
            sobject.set_value("url", "/%s/{value}" % key)
            sobject.set_value("widget", xml )

            return sobject


        elif key == "rest":

            xml = '''<element widget='true'>
  <display class='tactic.protocol.APIRestHandler'>
  </display>
</element>'''

            sobject = SearchType.create("config/url")
            sobject.set_value("url", "/rest")
            sobject.set_value("widget", xml )

            return sobject


        else:
            return None
コード例 #5
0
    def init(my):

        link = my.kwargs.get('link')
        hash = my.kwargs.get('hash')
        
        my.widget = None

        if link:
            from tactic.ui.panel import SideBarBookmarkMenuWdg
            personal = False
            if '.' in link:
                personal = True

            config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", link, personal=personal)
            options = config.get_display_options(link)

            # this is vital for view saving
            element_name = link
            attr_dict = config.get_element_attributes(link)
            title = attr_dict.get('title')

            hash = "/tab/%s" % link

           
            config = '''
            <config>
            <application>
            <element name="left_nav">
              <display class="tactic.ui.panel.SideBarPanelWdg">
              </display>
            </element>

            <element name="main_body">
              <display class="tactic.ui.panel.HashPanelWdg">
                <hash>%s</hash>
                <element_name>%s</element_name>
                <title>%s</title>
              </display>
              <web/>
            </element>
            </application>
            </config>
            ''' % (hash, element_name, title)


        elif hash:
            from tactic.ui.panel import HashPanelWdg
            my.widget = HashPanelWdg.get_widget_from_hash(hash, force_no_index=True)
            config = None
 
        else:
            security = Environment.get_security()
            start_link = security.get_start_link()
            if start_link:
                my.kwargs['link'] = start_link
                return my.init()



            # search for a defined welcome view
            search = Search("config/widget_config")
            search.add_filter("category", "top_layout")
            search.add_filter("view", "welcome")
            config_sobj = search.get_sobject()
            if config_sobj:
                config = config_sobj.get_value("config")

            else:
                config = WidgetSettings.get_value_by_key("top_layout")


        if not config:
            config = my.get_default_config()


        my.config_xml = Xml()
        my.config_xml.read_string(config)
コード例 #6
0
    def get_display(self):

        config_search_type = "config/widget_config"

        configs = []
        all_element_names = []
        from tactic.ui.panel import SideBarBookmarkMenuWdg
        SideBarBookmarkMenuWdg.add_internal_config(configs, ['definition'])
        for internal_config in configs:
            all_element_names = internal_config.get_element_names()

        search = Search(config_search_type)
        search.add_filter("search_type", 'SideBarWdg')
        search.add_filter("view", 'definition')
        search.add_filter("login", None)

        config = search.get_sobject()
        element_names = []
        if config:
            element_names = config.get_element_names()
            for name in element_names:
                if 'separator' in name:
                    element_names.remove(name)

        all_element_names.extend(element_names)

        all_element_names = [str(name) for name in all_element_names]
        all_element_names = Common.get_unique_list(all_element_names)
        widget = DivWdg(css='spt_load_test_top')

        span = SpanWdg(
            'This loads all the pages defined in the Project views in popups. It will take a few minutes.'
        )
        widget.add(span)
        widget.add('<br/>')
        div = ActionButtonWdg(title='Run')
        web = WebContainer.get_web()
        base_url = web.get_base_url().to_string()
        base_url = '%s/tactic/%s' % (base_url, Project.get_project_code())
        div.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var element_names = eval(%s);
            var all_element_names = eval(%s);
            var top = spt.get_parent(bvr.src_el, '.spt_load_test_top');
            var cb = spt.get_element(top, '.spt_input')
            if (cb.checked)
                element_list = all_element_names;
            else
                element_list = element_names
            for (var k=0; k < element_list.length; k++) {
                var name = element_list[k];
		//if (k > 3) break;

                var url = '%s/#/link/' + name;
		var bvr2 = {
                    title: name,
                    target_id: 'TEST',
                    options: {'link': name,
                    'title': name,
		    'path': '/Link Test/' + name
			},
                    is_popup: true};

                spt.side_bar.display_link_cbk(null, bvr2);

            }
            ''' % (element_names, all_element_names, base_url)
        })
        widget.add('<br/>')

        cb = CheckboxWdg('include_internal', label='include built-in pages')

        span = SpanWdg(cb, css='med')
        span.add_color('color', 'color')
        widget.add(span)
        widget.add(div)

        widget.add('<br/>')
        widget.add('<br/>')

        return widget
コード例 #7
0
ファイル: system_info_wdg.py プロジェクト: mincau/TACTIC
    def get_display(self):

        config_search_type = "config/widget_config"
         
        configs = []
	all_element_names = []
        from tactic.ui.panel import SideBarBookmarkMenuWdg
        SideBarBookmarkMenuWdg.add_internal_config(configs, ['definition'])
        for internal_config in configs:
            all_element_names = internal_config.get_element_names()

	search = Search(config_search_type)
        search.add_filter("search_type", 'SideBarWdg')
        search.add_filter("view", 'definition')
        search.add_filter("login", None)

        config = search.get_sobject()
        element_names = []
        if config:
            element_names = config.get_element_names()
            for name in element_names:
                if 'separator' in name:
                    element_names.remove(name)

	all_element_names.extend(element_names)

	
        all_element_names = [str(name) for name in all_element_names] 
	all_element_names = Common.get_unique_list(all_element_names)
        widget = DivWdg(css='spt_load_test_top')
	
	span =SpanWdg('This loads all the pages defined in the Project views in popups. It will take a few minutes.')
	widget.add(span)
	widget.add('<br/>')
        div = ActionButtonWdg(title='Run')
        web = WebContainer.get_web()
        base_url = web.get_base_url().to_string()
        base_url = '%s/tactic/%s' %(base_url, Project.get_project_code())
        div.add_behavior({'type': 'click_up',
           'cbjs_action': '''
            var element_names = eval(%s);
            var all_element_names = eval(%s);
            var top = spt.get_parent(bvr.src_el, '.spt_load_test_top');
            var cb = spt.get_element(top, '.spt_input')
            if (cb.checked)
                element_list = all_element_names;
            else
                element_list = element_names
            for (var k=0; k < element_list.length; k++) {
                var name = element_list[k];
		//if (k > 3) break;

                var url = '%s/#/link/' + name;
		var bvr2 = {
                    title: name,
                    target_id: 'TEST',
                    options: {'link': name,
                    'title': name,
		    'path': '/Link Test/' + name
			},
                    is_popup: true};

                spt.side_bar.display_link_cbk(null, bvr2);

            }
            ''' %(element_names, all_element_names, base_url)})
        widget.add('<br/>')
        
        cb = CheckboxWdg('include_internal', label='include built-in pages')
        
        span = SpanWdg(cb, css='med')
        span.add_color('color','color')
        widget.add(span)
        widget.add(div)

        widget.add('<br/>')
        widget.add('<br/>')
	
        return widget
コード例 #8
0
    def _get_predefined_url(cls, key, hash):

        # make some predefined fake urls
        if key in ["link", "tab", "admin"]:
            # this is called by PageNav
            if key == "admin":
                expression = "/admin/link/{link}"
            else:
                expression = "/%s/{link}" % key
            options = Common.extract_dict(hash, expression)
            link = options.get("link")

            if not link:
                return None


            # test link security
            project_code = Project.get_project_code()
            security = Environment.get_security()
            keys = [
                    { "element": link },
                    { "element": "*" },
                    { "element": link, "project": project_code },
                    { "element": "*", "project": project_code }
            ]
            if not security.check_access("link", keys, "allow", default="deny"):
                return None


            from tactic.ui.panel import SideBarBookmarkMenuWdg
            personal = False
            if '.' in link:
                personal = True



            config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", link, personal=personal)
            options = config.get_display_options(link)
            if not options:

                from pyasm.biz import Schema
                config_xml = []
                config_xml.append( '''
                <config>
                ''')
         
                config_schema = Schema.get_predefined_schema('config')
                SideBarBookmarkMenuWdg.get_schema_snippet("_config_schema", config_schema, config_xml)
                schema = Schema.get_admin_schema()
                SideBarBookmarkMenuWdg.get_schema_snippet("_admin_schema", schema, config_xml)

                config_xml.append( '''
                </config>
                ''')

                xml = "".join(config_xml)

                from pyasm.widget import WidgetConfig
                schema_config = WidgetConfig.get(view="_admin_schema", xml=xml)
                options = schema_config.get_display_options(link)
                if not options:
                    schema_config.set_view("_config_schema")
                    options = schema_config.get_display_options(link)

                if not options:
                    return None




            class_name = options.get("class_name")
            widget_key = options.get("widget_key")
            if widget_key:
                class_name = WidgetClassHandler().get_display_handler(widget_key)
            elif not class_name:
                class_name = 'tactic.ui.panel.ViewPanelWdg'


            if key in ["admin", "tab"]:
                use_index = "false"
            else:
                use_index = "true"

            if key in ['admin']:
                use_admin = "true"
            else:
                use_admin = "false"


            xml = []
            xml.append('''<element admin="%s" index="%s">''' % (use_admin, use_index))
            xml.append('''  <display class="%s">''' % class_name)
            for name, value in options.items():
                xml.append("<%s>%s</%s>" % (name, value, name) )
            xml.append('''  </display>''')
            xml.append('''</element>''')

            xml = "\n".join(xml)

            sobject = SearchType.create("config/url")
            sobject.set_value("url", "/%s/{value}" % key)
            sobject.set_value("widget", xml )

            return sobject
 
        else:
            return None
コード例 #9
0
    def init(self):

        link = self.kwargs.get('link')
        hash = self.kwargs.get('hash')

        self.widget = None

        if link:
            from tactic.ui.panel import SideBarBookmarkMenuWdg
            personal = False
            if '.' in link:
                personal = True

            config = SideBarBookmarkMenuWdg.get_config("SideBarWdg",
                                                       link,
                                                       personal=personal)
            options = config.get_display_options(link)

            # this is vital for view saving
            element_name = link
            attr_dict = config.get_element_attributes(link)
            title = attr_dict.get('title')

            hash = "/tab/%s" % link

            config = '''
            <config>
            <application>
            <element name="left_nav">
              <display class="tactic.ui.panel.SideBarPanelWdg">
              </display>
            </element>

            <element name="main_body">
              <display class="tactic.ui.panel.HashPanelWdg">
                <hash>%s</hash>
                <element_name>%s</element_name>
                <title>%s</title>
              </display>
              <web/>
            </element>
            </application>
            </config>
            ''' % (hash, element_name, title)

        elif hash:
            from tactic.ui.panel import HashPanelWdg
            self.widget = HashPanelWdg.get_widget_from_hash(
                hash, force_no_index=True)
            config = None

        else:
            security = Environment.get_security()
            start_link = security.get_start_link()
            if start_link:
                self.kwargs['link'] = start_link
                return self.init()

            # search for a defined welcome view
            search = Search("config/widget_config")
            search.add_filter("category", "top_layout")
            search.add_filter("view", "welcome")
            config_sobj = search.get_sobject()
            if config_sobj:
                config = config_sobj.get_value("config")

            else:
                config = WidgetSettings.get_value_by_key("top_layout")

        if not config:
            config = self.get_default_config()

        self.config_xml = Xml()
        self.config_xml.read_string(config)
コード例 #10
0
    def get_widget_from_hashXX(cls, hash, return_none=False, force_no_index=False, kwargs={}):

        from pyasm.web import DivWdg
        if hash.startswith("//"):
            use_top = False
            hash = hash[1:]
        else:
            use_top = True

        import re
        p = re.compile("^/(\w+)")
        m = p.search(hash)
        if not m:
            print "Cannot parse hash[%s]" % hash
            return DivWdg("Cannot parse hash [%s]" % hash)
        key = m.groups()[0]

        # add some predefined ones
        if key == "link":
            expression = "/link/{link}"
            options = Common.extract_dict(hash, expression)

            # This is the standard way of communicating through main interface
            # It uses the link keyword to draw the main widget
            if use_top:
                top_class_name = WebEnvironment.get_top_class_name()
                kwargs = {
                    "link": options.get("link")
                }
            else:
                top_class_name = 'tactic.ui.panel.HashPanelWdg'
                kwargs = {
                    "hash": hash.replace("/link", "/tab")
                }

                
            widget = Common.create_from_class_path(top_class_name, [], kwargs) 
            return widget

            #expression = "/link/{link}"
            #options = Common.extract_dict(hash, expression)
            #return cls.build_widget(options)


        elif key == 'tab':
            # this is called by PageNav
            expression = "/tab/{link}"
            options = Common.extract_dict(hash, expression)
            link = options.get("link")

            # test link security
            project_code = Project.get_project_code()
            security = Environment.get_security()
            link = options.get("link")
            keys = [
                    { "element": link },
                    { "element": "*" },
                    { "element": link, "project": project_code },
                    { "element": "*", "project": project_code }
            ]
            if not security.check_access("link", keys, "allow", default="deny"):
                widget = DivWdg()
                widget.add_color("color", "color")
                widget.add_color("background", "background3")
                widget.add_style("width: 600px")
                widget.add_style("height: 200px")
                widget.add_style("margin: 50px auto")
                widget.add_style("text-align: center")
                widget.add_border()


                widget.add("<br/>"*5)
                widget.add("This link [%s] either does not exist or you are not permitted to see it" % link)
                return widget
 


            from tactic.ui.panel import SideBarBookmarkMenuWdg
            personal = False
            if '.' in link:
                personal = True

            config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", link, personal=personal)
            options = config.get_display_options(link)

            class_name = options.get("class_name")
            widget_key = options.get("widget_key")
            if widget_key:
                class_name = WidgetClassHandler().get_display_handler(widget_key)
            elif not class_name:
                class_name = 'tactic.ui.panel.ViewPanelWdg'
            widget = Common.create_from_class_path(class_name, [], options) 

            return widget

        # these show only the widget without a top
        elif key == "encoded":
            expression = "/encoded/{encoded}"
            options = Common.extract_dict(hash, expression)
            encoded = options['encoded']
            import json, binascii
            data = json.loads( binascii.unhexlify(encoded) )
            class_name = data[0]
            args = data[1]
            kwargs = data[2]

            widget = Common.create_from_class_path(class_name, args, kwargs) 
            return cls.build_widget(options)
            
        else:
            if key == "top":
                kwargs["use_index"] = True
                sobject = None
            else:
                # look up the url
                search = Search("config/url")
                search.add_filter("url", "/%s/%%"%key, "like")
                search.add_filter("url", "/%s"%key)
                search.add_where("or")
                sobject = search.get_sobject()

                if not sobject:
                    if return_none:
                        return None
                    return DivWdg("No Widget found for hash [%s]" % hash)
 

                config = sobject.get_value("widget")
                xml = Xml()
                xml.read_string(config)


            use_index = kwargs.get("use_index")
            if use_index in [True, 'true']:
                use_index = True
            elif use_index in [False, 'false']:
                use_index = False

            use_admin = kwargs.get("use_admin")
            if use_admin in [True, 'true']:
                use_admin = True
            elif use_admin in [False, 'false']:
                use_admin = False


            use_sidebar = kwargs.get("use_sidebar")
            if use_sidebar in [False, 'false']:
                use_sidebar = False
            elif use_admin in [True, 'true']:
                use_sidebar = True


            if use_index is not None or use_admin is not None:
                pass

            elif force_no_index in [True, 'true']:
                use_index = False
            else:
                use_index = sobject.get_value("index", no_exception=True)
                if not use_index:
                    use_index = xml.get_value("/element/@index");
                    if use_index in ['true', True]:
                        use_index = True

                use_admin = sobject.get_value("admin", no_exception=True)
                if not use_admin:
                    use_admin = xml.get_value("/element/@admin");
                    if use_admin in ['true', True]:
                        use_admin = True

                    use_sidebar = xml.get_value("/element/@sidebar");
                    if use_sidebar in ['false', False]:
                        use_sidebar = False


            if use_index or use_admin:
                # check if there is an index
                search = Search("config/url")
                search.add_filter("url", "/index")
                index = search.get_sobject()

                if not index or use_admin:
                    # use admin
                    from tactic.ui.app import PageNavContainerWdg
                    top = PageNavContainerWdg( hash=hash, use_sidebar=use_sidebar )

                else:
                    config = index.get_value("widget")
                    xml = Xml()
                    xml.read_string(config)
                    node = xml.get_node("element/display")

                    options = {}
                    options.update(xml.get_node_values_of_children(node))

                    class_name = xml.get_value("element/display/@class")
                    if class_name:
                        options['class_name'] = class_name

                    # this passes the hash value to the index widget
                    # which must handle it accordingly
                    if key == "top":
                        hash = hash.replace("/top", "/tab")
                    options['hash'] = hash
                    top = cls.build_widget(options)



                return top.get_buffer_display()
 

            # build the widget
            if key == "top":
                class_name = 'tactic.ui.panel.HashPanelWdg'
                options = {
                    "hash": hash.replace("/link", "/tab"),
                    "class_name": class_name
                }
            else:
                url = sobject.get_value("url")
                url = url.strip()

                
                options = Common.extract_dict(hash, url)
                for name, value in kwargs.items():
                    options[name] = value

                node = xml.get_node("element/display")
                options.update(xml.get_node_values_of_children(node))

                class_name = xml.get_value("element/display/@class")
                if class_name:
                    options['class_name'] = class_name

            widget = cls.build_widget(options)

            name = hash.lstrip("/")
            name = name.replace("/", " ")
            widget.set_name(name)

            return widget
コード例 #11
0
ファイル: hash_panel_wdg.py プロジェクト: nuxping/TACTIC
    def _get_predefined_url(cls, key, hash):

        # make some predefined fake urls
        if key in ["link", "tab", "admin"]:
            # this is called by PageNav
            if key == "admin":
                expression = "/admin/link/{link}"
            else:
                expression = "/%s/{link}" % key
            options = Common.extract_dict(hash, expression)
            link = options.get("link")

            if not link:
                return None

            from tactic.ui.panel import SideBarBookmarkMenuWdg

            personal = False
            if "." in link:

                # put in a check to ensure this is a user
                parts = link.split(".")

                user = Environment.get_user_name()

                def is_personal(user, parts):
                    """See if parts contains period
                       seperated form of username."""
                    acc = ""
                    for part in parts:
                        if acc == "":
                            acc = part
                        else:
                            acc = "%s.%s" % (acc, part)
                        if user == acc:
                            return True
                    return False

                personal = is_personal(user, parts)

            # test link security
            project_code = Project.get_project_code()
            security = Environment.get_security()
            keys = [
                {"element": link},
                {"element": "*"},
                {"element": link, "project": project_code},
                {"element": "*", "project": project_code},
            ]
            if not personal and not security.check_access("link", keys, "allow", default="deny"):
                print "Not allowed"
                return None

            config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", link, personal=personal)
            options = config.get_display_options(link)
            if not options:

                from pyasm.biz import Schema

                config_xml = []
                config_xml.append(
                    """
                <config>
                """
                )

                config_schema = Schema.get_predefined_schema("config")
                SideBarBookmarkMenuWdg.get_schema_snippet("_config_schema", config_schema, config_xml)
                schema = Schema.get_admin_schema()
                SideBarBookmarkMenuWdg.get_schema_snippet("_admin_schema", schema, config_xml)

                config_xml.append(
                    """
                </config>
                """
                )

                xml = "".join(config_xml)

                from pyasm.widget import WidgetConfig

                schema_config = WidgetConfig.get(view="_admin_schema", xml=xml)
                options = schema_config.get_display_options(link)
                if not options:
                    schema_config.set_view("_config_schema")
                    options = schema_config.get_display_options(link)

                if not options:
                    return None

            class_name = options.get("class_name")
            widget_key = options.get("widget_key")
            if widget_key:
                class_name = WidgetClassHandler().get_display_handler(widget_key)
            elif not class_name:
                class_name = "tactic.ui.panel.ViewPanelWdg"

            if key in ["admin", "tab"]:
                use_index = "false"
            else:
                use_index = "true"

            if key in ["admin"]:
                use_admin = "true"
            else:
                use_admin = "false"

            xml = []
            xml.append("""<element admin="%s" index="%s">""" % (use_admin, use_index))
            xml.append("""  <display class="%s">""" % class_name)
            for name, value in options.items():
                xml.append("<%s>%s</%s>" % (name, value, name))
            xml.append("""  </display>""")
            xml.append("""</element>""")

            xml = "\n".join(xml)

            sobject = SearchType.create("config/url")
            sobject.set_value("url", "/%s/{value}" % key)
            sobject.set_value("widget", xml)

            return sobject

        else:
            return None