Exemplo n.º 1
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
Exemplo n.º 2
0
    def get_display(my):
        from pyasm.biz import Project

        security = Environment.get_security()
        if not security.check_access("builtin", "side_bar_schema", "allow", default="deny"):
            return DivWdg()


        section_div = LabeledHidableWdg(label="Schema Views")
        section_div.set_attr('spt_class_name', Common.get_full_class_name(my) )

        palette = Palette.get()
        color = palette.color("background3")

        project_div = RoundedCornerDivWdg(hex_color_code=color,corner_size="10")
        project_div.set_dimensions( width_str='175px', content_height_str='100px' )

        project = Project.get()
        project_code = project.get_code()
        project_type = project.get_type()

        div = DivWdg()
        section_div.add(project_div)
        project_div.add(div)

        # get project type schema
        schema = Schema.get_by_code(project_code)
        if schema:
            div.add( my.get_schema_wdg(schema) )
        #if not project_type:
        #    raise SetupException("Project type not found for this [%s]" %project_code)
        if project_type:
            schema = Schema.get_predefined_schema(project_type)
            if schema:
                div.add( my.get_schema_wdg(schema) )

        schema = Schema.get_predefined_schema('config')
        div.add( my.get_schema_wdg(schema) )

        schema = Schema.get_admin_schema()
        div.add( my.get_schema_wdg(schema) )

        return section_div


        # create a fake schema
        project = Project.get()
        db_name = project.get_database()
        sql = DbContainer.get(db_name)
        tables = sql.get_tables()
        tables.sort()
        tables_str = "\n".join( ['<search_type name="%s"/>'%x for x in tables] )

        # look at all of the search objects for mapped tables
        search = Search("sthpw/search_object")
        #search.add_where('''"namespace" = 'MMS' or namespace = '{project}' ''')
        search.add_filter("namespace", 'MMS')
        search.add_filter("namespace", '{project}')
        search.add_where("or")
        search_types = search.get_sobjects()
        #for search_type in search_types:
        #    print "hhhh: ", search_type

        schema_xml = '''
        <schema>
        %s
        </schema>
        ''' % tables_str
        schema = SearchType.create("sthpw/schema")
        schema.set_value("code", "table")
        schema.set_value("schema", schema_xml)
        #div.add( my.get_schema_wdg(schema) )



        return section_div
Exemplo n.º 3
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
Exemplo n.º 4
0
    def get_display(self):
        from pyasm.biz import Project

        security = Environment.get_security()
        if not security.check_access("builtin", "side_bar_schema", "allow", default="deny"):
            return DivWdg()


        section_div = LabeledHidableWdg(label="Schema Views")
        section_div.set_attr('spt_class_name', Common.get_full_class_name(self) )

        palette = Palette.get()
        color = palette.color("background3")

        project_div = RoundedCornerDivWdg(hex_color_code=color,corner_size="10")
        project_div.set_dimensions( width_str='175px', content_height_str='100px' )

        project = Project.get()
        project_code = project.get_code()
        project_type = project.get_type()

        div = DivWdg()
        section_div.add(project_div)
        project_div.add(div)

        # get project type schema
        schema = Schema.get_by_code(project_code)
        if schema:
            div.add( self.get_schema_wdg(schema) )
        #if not project_type:
        #    raise SetupException("Project type not found for this [%s]" %project_code)
        if project_type:
            schema = Schema.get_predefined_schema(project_type)
            if schema:
                div.add( self.get_schema_wdg(schema) )

        schema = Schema.get_predefined_schema('config')
        div.add( self.get_schema_wdg(schema) )

        schema = Schema.get_admin_schema()
        div.add( self.get_schema_wdg(schema) )

        return section_div


        # create a fake schema
        project = Project.get()
        db_name = project.get_database()
        sql = DbContainer.get(db_name)
        tables = sql.get_tables()
        tables.sort()
        tables_str = "\n".join( ['<search_type name="%s"/>'%x for x in tables] )

        # look at all of the search objects for mapped tables
        search = Search("sthpw/search_object")
        #search.add_where('''"namespace" = 'MMS' or namespace = '{project}' ''')
        search.add_filter("namespace", 'MMS')
        search.add_filter("namespace", '{project}')
        search.add_where("or")
        search_types = search.get_sobjects()

        schema_xml = '''
        <schema>
        %s
        </schema>
        ''' % tables_str
        schema = SearchType.create("sthpw/schema")
        schema.set_value("code", "table")
        schema.set_value("schema", schema_xml)
        #div.add( self.get_schema_wdg(schema) )



        return section_div
Exemplo n.º 5
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
Exemplo n.º 6
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

            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