示例#1
0
def main_menu_items():
    """Returns the main menu."""

    def assign_defaults(name,title,url,group=[]):
        return (name,title,url,group)

    links = []
    visible_items = []
    static_links = [assign_defaults(*item) for item in tools.get_menu()]

    for (name,title,url,group) in static_links:
        if group==[] or [item for item in group if item in user.groups]:
            if manager.get_app(name) and not manager.get_app(name).visible: continue
            selector = (len(route)>1 and route[0]=='content' and route[1]==name or len(route) and route[0]==name) and ' id="current"' or ''
            bootstrap_selector = (len(route)>1 and route[0]=='content' and route[1]==name or len(route) and route[0]==name) and ' class="active"' or ''
            links.append('<li%s><a href="%s"%s>%s</a></li>' % (bootstrap_selector,url_for(url), selector, title))
            visible_items.append(name)

    visible_items.extend(['content','login'])

    if user.is_developer:
        current_app = route[0]
        if not current_app in visible_items:
            if visible_items[0] in ['index','home']:
                pos = 1
            else:
                pos = 0
            url = '<li class="active"><a href="%s" id="current">%s</a></li>' % (url_for('/'+current_app),system.app.title)
            links.insert(pos, url)

    return ''.join(links)
示例#2
0
def main_menu_items():
    """Returns the main menu."""

    def assign_defaults(name, title, url, group=[]):
        return (name, title, url, group)

    links = []
    visible_items = []
    static_links = [assign_defaults(*item) for item in tools.get_menu()]

    for (name, title, url, group) in static_links:
        if group == [] or [item for item in group if item in user.groups]:
            if manager.get_app(name) and not manager.get_app(name).visible:
                continue
            selector = (
                (len(route) > 1 and route[0] == "content" and route[1] == name or len(route) and route[0] == name)
                and ' id="current"'
                or ""
            )
            bootstrap_selector = (
                (len(route) > 1 and route[0] == "content" and route[1] == name or len(route) and route[0] == name)
                and ' class="active"'
                or ""
            )
            links.append('<li%s><a href="%s"%s>%s</a></li>' % (bootstrap_selector, url_for(url), selector, title))
            visible_items.append(name)

    visible_items.extend(["content", "login"])

    if user.is_developer:
        current_app = route[0]
        if not current_app in visible_items:
            if visible_items[0] in ["index", "home"]:
                pos = 1
            else:
                pos = 0
            url = '<li class="active"><a href="%s" id="current">%s</a></li>' % (
                url_for("/" + current_app),
                system.app.title,
            )
            links.insert(pos, url)

    return "".join(links)
示例#3
0
def generate_response(instance_path):

    profiler = None

    # capture stdout
    real_stdout = sys.stdout
    sys.stdout = StringIO.StringIO()
    try:
        try:
            system.setup(instance_path)
            session.load_session()
            user.setup()
            manager.setup()

            system.subject = get_subject()

            visited(system.subject, session.sid)

            csrf_token = data.pop('csrf_token',None)
            if request.method == 'POST' and system.csrf_validation:
                if csrf_token == session.csrf_token:
                    del session.csrf_token
                else:
                    raise CrossSiteRequestForgeryAttempt('expected:%s got:%s' % (session.csrf_token, csrf_token))

            requested_app_name = manager.requested_app_name()
            default_app_name   = manager.default_app_name()

            os.chdir(system.config.sites_path)

            if not request.route:
                request.route.append(default_app_name)

            if manager.can_run(requested_app_name):
                system.app = manager.get_app(requested_app_name)

                profiler = system.profile and cProfile.Profile()
                if profiler:
                    profiler.enable()

                response = system.app.run()

                if profiler:
                    profiler.disable()

            elif not requested_app_name:
                system.app = manager.get_app(default_app_name)
                response = system.app.run()
            elif manager.can_run(default_app_name):
                response = redirect_to('/')
            else:
                response = Page('<H1>Page Missing</H1>Page not found').render()
                response.status = '404'

            session.save_session(response)

        except CrossSiteRequestForgeryAttempt:
            logger.security('cross site forgery attempt')
            if not (system.config.get('error','users','0')=='1' or user.is_developer or user.is_administrator):
                raise
            else:
                response = redirect_to('/')

        except SessionExpiredException:
            response = Page(load_template('system_application_session_expired', SESSION_EXPIRED_MESSAGE)).render()

        except:
            t = traceback.format_exc()
            logger.error(t)
            if system.show_errors or user.is_developer or user.is_administrator:
                msg = load_template('system_application_error_developer', STANDARD_ERROR_MESSAGE)
                response = Page(msg % dict(message=t)).render()
            else:
                msg = load_template('system_application_error_user', FRIENDLY_ERROR_MESSAGE)
                response = Page(msg).render()

        if profiler:
            stats_s = StringIO.StringIO()
            sortby = 'cumulative'
            ps = pstats.Stats(profiler, stream=stats_s)
            ps.sort_stats(sortby)
            ps.print_stats(.1)
            t = stats_s.getvalue()
            t = t.replace(system.lib_path, '~zoom'
                    ).replace('/usr/lib/python2.7/dist-packages/','~'
                            ).replace('/usr/local/lib/python2.7/dist-packages/','~')
            print t
    finally:
        printed_output = sys.stdout.getvalue()
        sys.stdout.close()
        sys.stdout = real_stdout
        if system.logging:
            logger.complete()

    if hasattr(response,'printed_output'):
        response.printed_output = printed_output.replace('<','&lt;').replace('>','&gt;')

    return response