Beispiel #1
0
    def execute(my):
        my.buffer = cStringIO.StringIO()
        try:
            # clear the main containers
            Container.create()
            # clear the buffer
            WebContainer.clear_buffer()

            # initialize the web environment object and register it
            adapter = my.get_adapter()
            WebContainer.set_web(adapter)

            # get the display
            my._get_display()
        finally:
            WebContainer.get_buffer().write(my.buffer.getvalue())
Beispiel #2
0
    def execute(my):
        my.buffer = cStringIO.StringIO()
        try:
            # clear the main containers
            Container.create()
            # clear the buffer
            WebContainer.clear_buffer()

            # initialize the web environment object and register it
            adapter = my.get_adapter()
            WebContainer.set_web(adapter)

            # get the display
            my._get_display()
        finally:
            WebContainer.get_buffer().write(my.buffer.getvalue())
Beispiel #3
0
    def get_display(self):

        profile_flag = False

        if profile_flag:
            BaseAppServer.profile.object = self
            if os.name == 'nt':
                path = "C:/sthpw/profile"
            else:
                path = "/tmp/sthpw/temp/profile"
            profile.run(
                "from pyasm.web.app_server import BaseAppServer; BaseAppServer.profile()",
                path)
            p = pstats.Stats(path)
            p.sort_stats('cumulative').print_stats(30)
            print("*" * 30)
            p.sort_stats('time').print_stats(30)

        else:
            self.execute()

        value = WebContainer.get_buffer().getvalue()
        WebContainer.clear_buffer()

        return value
Beispiel #4
0
    def get_display(my):

        profile_flag = False

        if profile_flag:
            BaseAppServer.profile.object = my
            if os.name == 'nt':
                path = "C:/sthpw/profile"
            else:
                path = "/tmp/sthpw/temp/profile"
            profile.run( "from pyasm.web.app_server import BaseAppServer; BaseAppServer.profile()", path)
            p = pstats.Stats(path)
            p.sort_stats('cumulative').print_stats(30)
            print "*"*30
            p.sort_stats('time').print_stats(30)

        else:
            my.execute()

        value = WebContainer.get_buffer().getvalue()
        WebContainer.clear_buffer()
        return value
Beispiel #5
0
    def get_display(my):
        '''override the get display function of Widget.  This is the function
        that actually draws the html element to the buffer'''
        html = WebContainer.get_buffer()
        buffer = html.get_buffer()
        
        buffer.write("<%s" % my.type)

        attrs = []
        if my.attrs:
            for x,y in my.attrs.items():
                if type(x) == types.UnicodeType:
                    x = Common.process_unicode_string(x)
                if type(y) == types.UnicodeType:
                    y = Common.process_unicode_string(y)
                attrs.append( ' %s="%s"' % (x,y) )


            attr = " ".join( attrs )
            """
            attr = " ".join( [' %s="%s"' % (x,y) for x,y in my.attrs.items()] )
            if type(attr) == types.UnicodeType:
                attr = Common.process_unicode_string(attr)
            """
            buffer.write(attr)
            attr = None

        # now process behaviors and, if there are any, construct the SPT_BVR_LIST attribute and write it out.
        # also add the SPT_BVR class to the element if it does have behaviors.
        if my.behaviors:
            my.add_class('SPT_BVR')
            bvr_str_list = [ ' SPT_BVR_LIST="[' ]
            bvr_type_list = [ ' SPT_BVR_TYPE_LIST="[' ]
            #for c in range(len(my.behaviors)):
            for c, behavior in enumerate(my.behaviors):
                if c:
                    bvr_str_list.append(',')
                    bvr_type_list.append(',')

                bvr_spec_str = HtmlElement.get_json_string(behavior)
                # NOTE: this is to make the HTML be XML compliant
                #bvr_spec_str = bvr_spec_str.replace("<", "&lt;")
                #bvr_spec_str = bvr_spec_str.replace(">", "&gt;")
                #bvr_spec_str = bvr_spec_str.replace("&", "&amp;")
                bvr_str_list.append( bvr_spec_str )

                bvr_info = {
                    'type': behavior.get("type"),
                }
                if behavior.get("_handoff_"):
                    bvr_info['_handoff_'] = behavior.get("_handoff_")

                bvr_info_str = HtmlElement.get_json_string(bvr_info)
                bvr_type_list.append( bvr_info_str )


            bvr_str_list.append( ']"' )
            bvr_type_list.append( ']"' )
            buffer.write( "".join( bvr_str_list ) )
            buffer.write( "".join( bvr_type_list ) )
            bvr_str_list = None
            bvr_type_list = None

        # handle the style
        if my.styles:
            styles = []
            for name, value in my.styles.items():
                styles.append( "%s: %s" % (name,value) )
            buffer.write( " style='%s'" % ";".join(styles) )
            styles = None


        # handle relay styles
        if my.relay_styles:
            for relay_style in my.relay_styles:
                my.add(relay_style)
        
        # handle the class
        if my.classes:
            classes = my.classes.keys()
            buffer.write(" class='%s'" % " ".join(classes))
            classes = None

        # handle events
        if my.events:
            for key in my.events.keys():
                functions = my.events.get(key)
                function = "javascript:%s" % ";".join(functions)
                buffer.write( ' %s="%s"' % (key,function) )
                functions = None


        self_close = False
        if my.type in ["img", "br"] or (my.type == "input" and not my.widgets):
            self_close = True
        else:
            buffer.write(">")

        super(HtmlElement,my).get_display()

        # add the closing tag
        if self_close:
            buffer.write(" />")
        elif my.type == "span":
            buffer.write("</%s>" % my.type)
        elif my.type != 'br':
            #buffer.write("</%s>\n" % my.type)
            buffer.write("</%s>" % my.type)

        my.clear()
Beispiel #6
0
                    return

                my.writeln("<pre>")
                my.writeln("An Error has occurred.  Please see your Tactic Administrator<br/>")
                my.writeln( "Error Message: %s" % log.get_value("message") )
                my.writeln("Error Id: %s" % log.get_id() )
                my.writeln( log.get_value("stack_trace") )
                my.writeln("</pre>")


        finally:
            # ensure that database connections are always closed
            DbContainer.close_all()
            # clear the container
            Container.delete()
            WebContainer.get_buffer().write( my.buffer.getvalue() )




    def handle_not_logged_in(my, allow_change_admin=True):


        site_obj = Site.get()
        site_obj.set_site("default")

        DbResource.clear_cache()


        from pyasm.widget import WebLoginWdg, BottomWdg
        from tactic.ui.app import TitleTopWdg
Beispiel #7
0
                    return

                my.writeln("<pre>")
                my.writeln("An Error has occurred.  Please see your Tactic Administrator<br/>")
                my.writeln( "Error Message: %s" % log.get_value("message") )
                my.writeln("Error Id: %s" % log.get_id() )
                my.writeln( log.get_value("stack_trace") )
                my.writeln("</pre>")


        finally:
            # ensure that database connections are always closed
            DbContainer.close_all()
            # clear the container
            Container.delete()
            WebContainer.get_buffer().write( my.buffer.getvalue() )




    def handle_not_logged_in(my, allow_change_admin=True):

        from pyasm.widget import WebLoginWdg, BottomWdg
        from tactic.ui.app import TitleTopWdg

        from pyasm.biz import Project
        from tactic.ui.panel import HashPanelWdg

        web = WebContainer.get_web()

        widget = Widget()
Beispiel #8
0
    def execute(self):
        self.buffer = cStringIO.StringIO()
        error = None

        try:
            try:

                # clear the main container for this thread
                Container.create()

                # clear the buffer
                WebContainer.clear_buffer()

                # initialize the web environment object and register it
                adapter = self.get_adapter()
                WebContainer.set_web(adapter)

                # get the display
                self._get_display()

            except SetupException as e:
                '''Display setup exception in the interface'''
                print("Setup exception: ", e.__str__())
                DbContainer.rollback_all()
                ExceptionLog.log(e)
                self.writeln("<h3>Tactic Setup Error</h3>")
                self.writeln("<pre>")
                self.writeln(e.__str__())
                self.writeln("</pre>")
                error = "405: TACTIC Setup Error"

            except DatabaseException as e:
                from tactic.ui.startup import DbConfigPanelWdg
                config_wdg = DbConfigPanelWdg()
                self.writeln("<pre>")
                self.writeln(config_wdg.get_buffer_display())
                self.writeln("</pre>")
                error = "405: TACTIC Database Error"

            except Exception as e:
                stack_trace = ExceptionLog.get_stack_trace(e)
                #print(stack_trace)
                self.writeln("<pre>")
                self.writeln(stack_trace)
                self.writeln("</pre>")
                error = "405 %s" % str(e)

                # it is possible that the security object was not set
                security = Environment.get_security()
                if not security:
                    security = Security()
                    WebContainer.set_security(security)

                log = None
                # ensure that database connections are rolled back
                try:
                    DbContainer.rollback_all()
                except Exception as e2:
                    print("Error: Could not rollback: ", e2.__str__())
                    self.writeln("Error: Could not rollback: '%s'" %
                                 e2.__str__())
                    stack_trace = ExceptionLog.get_stack_trace(e2)
                    print(stack_trace)
                    self.writeln("<pre>")
                    self.writeln(stack_trace)
                    self.writeln("</pre>")
                    raise e
                    #return

                try:
                    # WARNING: if this call causes an exception, the error
                    # will be obscure
                    log = ExceptionLog.log(e)
                except Exception as e2:

                    print("Error: Could not log exception: ", e2.__str__())
                    self.writeln("Error '%s': Could not log exception" %
                                 e2.__str__())
                    stack_trace = ExceptionLog.get_stack_trace(e2)
                    print(stack_trace)
                    self.writeln("<pre>")
                    self.writeln(stack_trace)
                    self.writeln("</pre>")
                    return

                self.writeln("<pre>")
                self.writeln(
                    "An Error has occurred.  Please see your Tactic Administrator<br/>"
                )
                self.writeln("Error Message: %s" % log.get_value("message"))
                self.writeln("Error Id: %s" % log.get_id())
                #self.writeln( log.get_value("stack_trace") )
                self.writeln("</pre>")

        finally:
            # ensure that database connections are always closed
            DbContainer.close_all()
            # clear the container
            Container.delete()
            WebContainer.get_buffer().write(self.buffer.getvalue())

            if error:
                import cherrypy
                print("error: ", error)
                cherrypy.response.status = error
Beispiel #9
0
    def execute(self):
        self.buffer = cStringIO.StringIO()
        error = None

        try:
            try:

                # clear the main container for this thread
                Container.create()

                # clear the buffer
                WebContainer.clear_buffer()

                # initialize the web environment object and register it
                adapter = self.get_adapter()
                WebContainer.set_web(adapter)

                # get the display
                self._get_display()

            except SetupException as e:
                '''Display setup exception in the interface'''
                print("Setup exception: ", e.__str__())
                DbContainer.rollback_all()
                ExceptionLog.log(e)
                self.writeln("<h3>Tactic Setup Error</h3>" )
                self.writeln("<pre>" )
                self.writeln(e.__str__() )
                self.writeln("</pre>" )
                error = "405: TACTIC Setup Error"

            except DatabaseException as e:
                from tactic.ui.startup import DbConfigPanelWdg
                config_wdg = DbConfigPanelWdg()
                self.writeln("<pre>")
                self.writeln(config_wdg.get_buffer_display())
                self.writeln("</pre>")
                error = "405: TACTIC Database Error"


            except Exception as e:
                stack_trace = ExceptionLog.get_stack_trace(e)
                #print(stack_trace)
                self.writeln("<pre>")
                self.writeln(stack_trace)
                self.writeln("</pre>")
                error = "405 %s" % str(e)

                # it is possible that the security object was not set
                security = Environment.get_security()
                if not security:
                    security = Security()
                    WebContainer.set_security(security)

                log = None
                # ensure that database connections are rolled back
                try:
                    DbContainer.rollback_all()
                except Exception as e2:
                    print("Error: Could not rollback: ", e2.__str__())
                    self.writeln("Error: Could not rollback: '%s'" % e2.__str__() )
                    stack_trace = ExceptionLog.get_stack_trace(e2)
                    print(stack_trace)
                    self.writeln("<pre>")
                    self.writeln(stack_trace)
                    self.writeln("</pre>")
                    raise e
                    #return


                try:
                    # WARNING: if this call causes an exception, the error
                    # will be obscure
                    log = ExceptionLog.log(e)
                except Exception as e2:

                    print("Error: Could not log exception: ", e2.__str__())
                    self.writeln("Error '%s': Could not log exception" % e2.__str__() )
                    stack_trace = ExceptionLog.get_stack_trace(e2)
                    print(stack_trace)
                    self.writeln("<pre>")
                    self.writeln(stack_trace)
                    self.writeln("</pre>")
                    return

                self.writeln("<pre>")
                self.writeln("An Error has occurred.  Please see your Tactic Administrator<br/>")
                self.writeln( "Error Message: %s" % log.get_value("message") )
                self.writeln("Error Id: %s" % log.get_id() )
                #self.writeln( log.get_value("stack_trace") )
                self.writeln("</pre>")


        finally:
            # ensure that database connections are always closed
            DbContainer.close_all()
            # clear the container
            Container.delete()
            WebContainer.get_buffer().write( self.buffer.getvalue() )

            if error:
                import cherrypy
                print("error: ", error)
                cherrypy.response.status = error