def get_site_root(self): from pyasm.security import Site site = Site.get().get_site_root() if site: return site return "tactic"
def get_asset_dir(cls, file_object=None, alias=None): '''get base asset directory''' if file_object: alias = file_object.get_value('base_dir_alias') if not alias: alias = "default" from pyasm.security import Site asset_dir = Site.get().get_asset_dir(file_object=file_object,alias=alias) if asset_dir: return asset_dir alias_dict = cls.get_asset_dirs() asset_dir = alias_dict.get(alias) if not asset_dir: data_dir = Environment.get_data_dir() if data_dir: asset_dir = "%s/assets" % data_dir return asset_dir
def get_default_project(cls): from pyasm.security import Site project = Site.get().get_default_project() if project: return project project = Config.get_value("install", "default_project") return project
def execute(self): if not self.login_name: self.login_name = self.kwargs.get('login'); # invalidate the ticket security = Environment.get_security() ticket = security.get_ticket() if ticket == None: return login_name = ticket.get_value("login") print "Signing out: ", login_name # expire the ticket from pyasm.security import Site site = Site.get() if site: Site.set_site("default") try: from pyasm.search import Sql, DbContainer sql = DbContainer.get("sthpw") ticket.set_value("expiry", sql.get_timestamp_now(), quoted=False) ticket.commit() except: if site: Site.pop_site()
def get_display(self): web = WebContainer.get_web() response = web.get_response() # get info from url site_obj = Site.get() path = web.get_request_path() path_info = site_obj.break_up_request_path(path) site = path_info.get("site") project_code = path_info.get("project_code") # find the relative path hash = self.kwargs.get("hash") parts = hash[1:] rel_path = "/".join(parts) #rel_path = "asset/Fantasy/Castle/54d45150c61251f65687d716cc3951f1_v001.jpg" # construct all of the paths asset_dir = web.get_asset_dir() base_dir = "%s/%s" % (asset_dir, project_code) path = "%s/%s" % (base_dir, rel_path) filename = os.path.basename(rel_path) print "path: ", path # determine the mimetype automatically import mimetypes base, ext = os.path.splitext(path) ext = ext.lower() mimetype = mimetypes.types_map[ext] headers = response.headers response.headers['Content-Type'] = mimetype response.headers['Content-Disposition'] = 'inline; filename={0}'.format(filename) use_xsendfile = True if use_xsendfile: response.headers['X-Sendfile'] = path return Widget(path) else: response.headers['Content-Transfer-Encoding'] = 'BINARY' widget = Widget() f = open(path, 'rb') data = f.read() f.close() widget.add(data) return widget
def get_display(self): web = WebContainer.get_web() response = web.get_response() # get info from url site_obj = Site.get() path = web.get_request_path() path_info = site_obj.break_up_request_path(path) site = path_info.get("site") project_code = path_info.get("project_code") # find the relative path hash = self.kwargs.get("hash") parts = hash[1:] rel_path = "/".join(parts) #rel_path = "asset/Fantasy/Castle/54d45150c61251f65687d716cc3951f1_v001.jpg" # construct all of the paths asset_dir = web.get_asset_dir() base_dir = "%s/%s" % (asset_dir, project_code) path = "%s/%s" % (base_dir, rel_path) filename = os.path.basename(rel_path) print "path: ", path # determine the mimetype automatically import mimetypes base, ext = os.path.splitext(path) ext = ext.lower() mimetype = mimetypes.types_map[ext] headers = response.headers response.headers['Content-Type'] = mimetype response.headers[ 'Content-Disposition'] = 'inline; filename={0}'.format(filename) use_xsendfile = True if use_xsendfile: response.headers['X-Sendfile'] = path return Widget(path) else: response.headers['Content-Transfer-Encoding'] = 'BINARY' widget = Widget() f = open(path, 'rb') data = f.read() f.close() widget.add(data) return widget
def error_page(my, status, message, traceback, version): # check if this project exists response = cherrypy.response request = cherrypy.request path = request.path_info parts = path.split("/") if len(parts) < 3: cherrypy.response.body = '<meta http-equiv="refresh" content="0;url=/tactic" />' return from pyasm.security import Site site_obj = Site.get() path_info = site_obj.break_up_request_path(path) if path_info: site = path_info['site'] project_code = path_info['project_code'] else: project_code = parts[2] site = "" # sites is already mapped in config for cherrypy if site == "plugins": return print "WARNING:" print " status: ", status print " message: ", message print " site: ", site print " project_code: ", project_code # Dump out the error has_site = False try: from pyasm.security import TacticInit TacticInit() Site.set_site(site) if site: eval("cherrypy.root.tactic.%s.%s" % (site, project_code)) else: eval("cherrypy.root.tactic.%s" % project_code) # if project_code is empty , it raises SyntaxError except (AttributeError, SyntaxError), e: print "WARNING: ", e has_project = False has_site = True
def index(my): # check if this project exists response = cherrypy.response request = cherrypy.request path = request.path_info from pyasm.security import Site default_project = Site.get().get_default_project() if not default_project: default_project = "admin" path = path.rstrip("/") path = "%s/%s" % (path, default_project) return '''<META http-equiv="refresh" content="0;URL=%s">''' % path
def get_context_name(my): '''this includes all of the subdirectories as well as the main context''' path = my.get_request_path() p = re.compile( r"/(tactic|projects)/?(\w+)/") m = p.search(path) if not m: return "default" from pyasm.security import Site site_obj = Site.get() path_info = site_obj.break_up_request_path(path) if path_info: context = path_info.get("project_code") else: context = m.groups()[1] return context
def get_web_dir(cls, file_object=None, alias=None): '''get base web directory''' if file_object: alias = file_object.get_value('base_dir_alias') if not alias: alias = "default" from pyasm.security import Site site = Site.get() web_dir = site.get_web_dir(file_object=file_object, alias=alias) if web_dir: return web_dir alias_dict = cls.get_web_dirs() web_dir = alias_dict.get(alias) if not web_dir: web_dir = "/assets" return web_dir
def get_web_dir(cls, file_object=None, alias=None): '''get base web directory''' if file_object: alias = file_object.get_value('base_dir_alias') if not alias: alias = "default" from pyasm.security import Site site = Site.get() web_dir = site.get_web_dir(file_object=file_object,alias=alias) if web_dir: return web_dir alias_dict = cls.get_web_dirs() web_dir = alias_dict.get(alias) if not web_dir: web_dir = "/assets" return web_dir
def get_asset_dir(cls, file_object=None, alias=None): '''get base asset directory''' if file_object: alias = file_object.get_value('base_dir_alias') if not alias: alias = "default" from pyasm.security import Site asset_dir = Site.get().get_asset_dir(file_object=file_object, alias=alias) if asset_dir: return asset_dir alias_dict = cls.get_asset_dirs() asset_dir = alias_dict.get(alias) if not asset_dir: data_dir = Environment.get_data_dir() if data_dir: asset_dir = "%s/assets" % data_dir return asset_dir
def setup_sites(my): context_path = "%s/src/context" % my.install_dir doc_dir = "%s/doc" % my.install_dir plugin_dir = Environment.get_plugin_dir() builtin_plugin_dir = Environment.get_builtin_plugin_dir() dist_dir = Environment.get_dist_dir() log_dir = "%s/log" % Environment.get_tmp_dir() def CORS(): #cherrypy.response.headers["Access-Control-Allow-Origin"] = "http://192.168.0.15:8100" cherrypy.response.headers["Access-Control-Allow-Origin"] = "*" cherrypy.response.headers["Access-Control-Allow-Headers"] = "Origin, X-Requested-With, Content-Type, Accept" cherrypy.tools.CORS = cherrypy.Tool('before_handler', CORS) config = { 'global': { 'server.socket_host': '127.0.0.1', 'server.socket_port': 80, 'log.screen': False, 'request.show_tracebacks': True, 'tools.log_headers.on': True, 'server.log_file': "%s/tactic_log" % log_dir, 'server.max_request_body_size': 0, #'server.socket_timeout': 60, 'response.timeout': 3600, 'tools.encode.on': True, 'tools.encode.encoding': 'utf-8', 'tools.decode.on': True, 'tools.decode.encoding': 'utf-8', #'encoding_filter.on': True, #'decoding_filter.on': True 'tools.CORS.on': True }, '/context': {'tools.staticdir.on': True, 'tools.staticdir.dir': context_path, # Need to do this because on windows servers, jar files # are served as text/html 'tools.staticdir.content_types': { 'jar': 'application/java-archive' } }, '/assets': {'tools.staticdir.on': True, 'tools.staticdir.dir': Environment.get_asset_dir() }, '/doc': {'tools.staticdir.on': True, 'tools.staticdir.dir': doc_dir, 'tools.staticdir.index': "index.html" }, # NOTE: expose the entire plugins directory '/tactic/plugins': { 'tools.staticdir.on': True, 'tools.staticdir.dir': plugin_dir, }, '/tactic/builtin_plugins': { 'tools.staticdir.on': True, 'tools.staticdir.dir': builtin_plugin_dir, }, '/tactic/dist': { 'tools.staticdir.on': True, 'tools.staticdir.dir': dist_dir, }, '/plugins': { 'tools.staticdir.on': True, 'tools.staticdir.dir': plugin_dir, }, '/builtin_plugins': { 'tools.staticdir.on': True, 'tools.staticdir.dir': builtin_plugin_dir, }, '/dist': { 'tools.staticdir.on': True, 'tools.staticdir.dir': dist_dir, }, } # set up the root directory cherrypy.root = Root() cherrypy.tree.mount( cherrypy.root, config=config) from pyasm.search import Search search = Search("sthpw/project") search.add_filter("type", "resource", op="!=") projects = search.get_sobjects() # find out if one of the projects is the root root_initialized = False if not root_initialized: project_code = Project.get_default_project() if project_code and project_code !='default': from tactic.ui.app import SitePage cherrypy.root.tactic = SitePage(project_code) cherrypy.root.projects = SitePage(project_code) root_initialized = True if not root_initialized: # load in the base site at root from tactic_sites.default.context.Index import Index cherrypy.root.tactic = Index() cherrypy.root.projects = Index() for project in projects: project_code = project.get_code() my.register_project(project_code, config) my.register_project("default", config) print from pyasm.security import Site site_obj = Site.get() site_obj.register_sites(my, config) #my.register_project("vfx", config, site="vfx_demo") #my.register_project("default", config, site="vfx_demo") return config
def get_display(self): web = WebContainer.get_web() widget = Widget() html = HtmlElement("html") is_xhtml = False if is_xhtml: web.set_content_type("application/xhtml+xml") widget.add('''<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ''') html.add_attr("xmlns", "http://www.w3.org/1999/xhtml") #html.add_attr("xmlns:svg", "http://www.w3.org/2000/svg") # add the copyright widget.add( self.get_copyright_wdg() ) widget.add(html) # handle redirect request_url = web.get_request_url().get_info().path if request_url in ["/tactic/Index", "/Index", "/"]: # if we have the root path name, provide the ability for the site to # redirect from pyasm.security import Site site_obj = Site.get() redirect = site_obj.get_site_redirect() if redirect: widget.add('''<meta http-equiv="refresh" content="0; url=%s">''' % redirect) return widget # create the header head = HtmlElement("head") html.add(head) head.add('<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>\n') head.add('<meta http-equiv="X-UA-Compatible" content="IE=edge"/>\n') # Add the tactic favicon head.add('<link rel="shortcut icon" href="/context/favicon.ico" type="image/x-icon"/>') # add the css styling head.add(self.get_css_wdg()) # add the title in the header project = Project.get() project_code = project.get_code() project_title = project.get_value("title") if web.is_admin_page(): is_admin = " - Admin" else: is_admin = "" if project_code == 'admin': head.add("<title>TACTIC Site Admin</title>\n" ) else: head.add("<title>%s%s</title>\n" % (project_title, is_admin) ) # add the javascript libraries head.add( JavascriptImportWdg() ) # add the body body = self.body html.add( body ) body.add_event('onload', 'spt.onload_startup(this)') top = self.top # Add a NOSCRIPT tag block here to provide a warning message on browsers where 'Enable JavaScript' # is not checked ... TODO: clean up and re-style to make look nicer top.add( """ <NOSCRIPT> <div style="border: 2px solid black; background-color: #FFFF99; color: black; width: 600px; height: 70px; padding: 20px;"> <img src="%s" style="border: none;" /> <b>Javascript is not enabled on your browser!</b> <p>This TACTIC powered, web-based application requires JavaScript to be enabled in order to function. In your browser's options/preferences, please make sure that the 'Enable JavaScript' option is checked on, click OK to accept the settings change, and then refresh this web page.</p> </div> </NOSCRIPT> """ % ( IconWdg.get_icon_path("ERROR") ) ) # add the content content_div = DivWdg() top.add(content_div) Container.put("TopWdg::content", content_div) # add a dummy button for global behaviors from tactic.ui.widget import ButtonNewWdg, IconButtonWdg ButtonNewWdg(title="DUMMY", icon=IconWdg.FILM) IconButtonWdg(title="DUMMY", icon=IconWdg.FILM) # NOTE: it does not need to be in the DOM. Just needs to be # instantiated #content_div.add(button) if self.widgets: content_wdg = self.get_widget('content') else: content_wdg = Widget() self.add(content_wdg) content_div.add( content_wdg ) # add a calendar wdg from tactic.ui.widget import CalendarWdg cal_wdg = CalendarWdg(css_class='spt_calendar_template_top') cal_wdg.top.add_style('display: none') content_div.add(cal_wdg) if web.is_admin_page(): from tactic_branding_wdg import TacticCopyrightNoticeWdg branding = TacticCopyrightNoticeWdg(show_license_info=True) top.add(branding) # add the admin bar security = Environment.get_security() if not web.is_admin_page() and security.check_access("builtin", "view_site_admin", "allow"): div = DivWdg() top.add(div) top.add_style("padding-top: 21px") div.add_class("spt_admin_bar") # home icon_div = DivWdg() div.add(icon_div) icon_div.add_style("float: left") icon_div.add_style("margin-right: 10px") icon_div.add_style("margin-top: -3px") icon_button = IconButtonWdg(title="Home", icon="BS_HOME") icon_div.add(icon_button) icon_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' window.location.href="/"; ''' } ) div.add_style("height: 15px") div.add_style("padding: 3px 0px 3px 15px") #div.add_style("margin-bottom: -5px") div.add_style("position: fixed") div.add_style("top: 0px") div.add_style("left: 0px") div.add_style("opacity: 0.7") div.add_style("width: 100%") #div.add_gradient("background", "background2", 20, 10) div.add_style("background-color", "#000") div.add_style("color", "#FFF") div.add_style("z-index", "1000") div.add_class("hand") div.set_box_shadow("0px 5px 5px") # remove icon_div = DivWdg() div.add(icon_div) icon_div.add_style("float: right") icon_div.add_style("margin-right: 10px") icon_div.add_style("margin-top: -3px") icon_button = IconButtonWdg(title="Remove Admin Bar", icon="BS_REMOVE") icon_div.add(icon_button) icon_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var parent = bvr.src_el.getParent(".spt_admin_bar"); bvr.src_el.getParent(".spt_top").setStyle("padding-top", "0px"); spt.behavior.destroy_element(parent); ''' } ) # sign-out icon_div = DivWdg() div.add(icon_div) icon_div.add_style("float: right") icon_div.add_style("margin-right: 5px") icon_div.add_style("margin-top: -3px") icon_button = IconButtonWdg(title="Sign Out", icon="BS_LOG_OUT") icon_div.add(icon_button) icon_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var ok = function(){ var server = TacticServerStub.get(); server.execute_cmd("SignOutCmd", {login: bvr.login} ); window.location.href="/"; } spt.confirm("Are you sure you wish to sign out?", ok ) ''' } ) div.add("<b>ADMIN >></b>") div.add_behavior( { 'type': 'listen', 'event_name': 'close_admin_bar', 'cbjs_action': ''' bvr.src_el.getParent(".spt_top").setStyle("padding-top", "0px"); spt.behavior.destroy_element(bvr.src_el); ''' } ) div.add_behavior( { 'type': 'mouseover', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", 0.85) //new Fx.Tween(bvr.src_el).start('height', "30px"); ''' } ) div.add_behavior( { 'type': 'mouseout', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", 0.7) //new Fx.Tween(bvr.src_el).start('height', "15px"); ''' } ) project_code = Project.get_project_code() site_root = web.get_site_root() div.add_behavior( { 'type': 'click_up', 'site_root': site_root, 'project_code': project_code, 'cbjs_action': ''' var url = "/"+bvr.site_root+"/"+bvr.project_code+"/admin/link/_startup"; window.open(url); ''' } ) # Add the script editor listener load_div = DivWdg() top.add(load_div) load_div.add_behavior( { 'type': 'listen', 'event_name': 'show_script_editor', 'cbjs_action': ''' var js_popup_id = "TACTIC Script Editor"; var js_popup = $(js_popup_id); if( js_popup ) { spt.popup.toggle_display( js_popup_id, false ); } else { spt.panel.load_popup(js_popup_id, "tactic.ui.app.ShelfEditWdg", {}, {"load_once": true} ); } '''} ) # deal with the palette defined in /index which can override the palette if self.kwargs.get("hash") == (): key = "index" search = Search("config/url") search.add_filter("url", "/%s/%%"%key, "like") search.add_filter("url", "/%s"%key) search.add_where("or") url = search.get_sobject() if url: xml = url.get_xml_value("widget") palette_key = xml.get_value("element/@palette") # look up palette the expression for index from pyasm.web import Palette palette = Palette.get() palette.set_palette(palette_key) colors = palette.get_colors() colors = jsondumps(colors) script = HtmlElement.script(''' var env = spt.Environment.get(); env.set_colors(%s); env.set_palette('%s'); ''' % (colors, palette_key) ) top.add(script) env = Environment.get() client_handoff_dir = env.get_client_handoff_dir(include_ticket=False, no_exception=True) client_asset_dir = env.get_client_repo_dir() login = Environment.get_login() user_name = login.get_value("login") user_id = login.get_id() login_groups = Environment.get_group_names() from pyasm.security import Site site = Site.get_site() kiosk_mode = Config.get_value("look", "kiosk_mode") if not kiosk_mode: kiosk_mode = 'false' # add environment information script = HtmlElement.script(''' var env = spt.Environment.get(); env.set_site('%s'); env.set_project('%s'); env.set_user('%s'); env.set_user_id('%s'); var login_groups = '%s'.split('|'); env.set_login_groups(login_groups); env.set_client_handoff_dir('%s'); env.set_client_repo_dir('%s'); env.set_kiosk_mode('%s'); ''' % (site, Project.get_project_code(), user_name, user_id, '|'.join(login_groups), client_handoff_dir,client_asset_dir, kiosk_mode)) top.add(script) # add a global container for commonly used widgets div = DivWdg() top.add(div) div.set_id("global_container") # add in the app busy widget # find out if there is an override for this search = Search("config/url") search.add_filter("url", "/app_busy") url = search.get_sobject() if url: busy_div = DivWdg() div.add(busy_div) busy_div.add_class( "SPT_PUW" ) busy_div.add_styles( "display: none; position: absolute; z-index: 1000" ) busy_div.add_class("app_busy_msg_block") busy_div.add_style("width: 300px") busy_div.add_style("height: 100px") busy_div.add_style("padding: 20px") busy_div.add_color("background", "background3") busy_div.add_border() busy_div.set_box_shadow() busy_div.set_round_corners(20) busy_div.set_attr("id","app_busy_msg_block") # put the custom url here title_wdg = DivWdg() busy_div.add(title_wdg) title_wdg.add_style("font-size: 20px") title_wdg.add_class("spt_app_busy_title") busy_div.add("<hr/>") msg_div = DivWdg() busy_div.add(msg_div) msg_div.add_class("spt_app_busy_msg") else: from page_header_wdg import AppBusyWdg div.add( AppBusyWdg() ) # popup parent popup = DivWdg() popup.set_id("popup") div.add(popup) # create another general popup popup_div = DivWdg() popup_div.set_id("popup_container") popup_div.add_class("spt_panel") popup = PopupWdg(id="popup_template",destroy_on_close=True) popup_div.add(popup) div.add(popup_div) inner_html_div = DivWdg() inner_html_div.set_id("inner_html") div.add(inner_html_div) # add in a global color from tactic.ui.input import ColorWdg color = ColorWdg() div.add(color) # add in a global notify wdg from notify_wdg import NotifyWdg widget.add(NotifyWdg()) from tactic.ui.app import DynamicUpdateWdg widget.add( DynamicUpdateWdg() ) return widget
def get_default_project(cls): from pyasm.security import Site project = Site.get().get_default_project() return project
# Dump out the error print "WARNING: ", path, status, message try: eval("cherrypy.root.tactic.%s" % project_code) # if project_code is empty , it raises SyntaxError except (AttributeError, SyntaxError), e: has_project = False else: has_project = True # make sure the appropriate site is set (based on the ticket) from pyasm.security import Site cookie = cherrypy.request.cookie if cookie.has_key("login_ticket"): cookie = cookie["login_ticket"].value site = Site.get().get_by_ticket(cookie) else: html_response = '''<html> <head><meta http-equiv="Refresh" content="0; url=/"></head> </html>''' response.body = '' return html_response Site.set_site(site) # if the url does not exist, but the project does, then check to # to see if cherrypy knows about it project = Project.get_by_code(project_code) if not has_project and project and project.get_value("type") != 'resource':
def get_display(self): web = WebContainer.get_web() widget = Widget() html = HtmlElement("html") is_xhtml = False if is_xhtml: web.set_content_type("application/xhtml+xml") widget.add('''<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ''') html.add_attr("xmlns", "http://www.w3.org/1999/xhtml") #html.add_attr("xmlns:svg", "http://www.w3.org/2000/svg") # add the copyright widget.add(self.get_copyright_wdg()) widget.add(html) # handle redirect request_url = web.get_request_url().get_info().path if request_url in ["/tactic/Index", "/Index", "/"]: # if we have the root path name, provide the ability for the site to # redirect from pyasm.security import Site site_obj = Site.get() redirect = site_obj.get_site_redirect() if redirect: widget.add( '''<meta http-equiv="refresh" content="0; url=%s">''' % redirect) return widget # create the header head = HtmlElement("head") html.add(head) head.add( '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>\n' ) head.add('<meta http-equiv="X-UA-Compatible" content="IE=edge"/>\n') # Add the tactic favicon head.add( '<link rel="shortcut icon" href="/context/favicon.ico" type="image/x-icon"/>' ) # add the css styling head.add(self.get_css_wdg()) # add the title in the header project = Project.get() project_code = project.get_code() project_title = project.get_value("title") if web.is_admin_page(): is_admin = " - Admin" else: is_admin = "" if project_code == 'admin': head.add("<title>TACTIC Site Admin</title>\n") else: head.add("<title>%s%s</title>\n" % (project_title, is_admin)) # add the javascript libraries head.add(JavascriptImportWdg()) # add the body body = self.body html.add(body) body.add_event('onload', 'spt.onload_startup(this)') top = self.top # Add a NOSCRIPT tag block here to provide a warning message on browsers where 'Enable JavaScript' # is not checked ... TODO: clean up and re-style to make look nicer top.add(""" <NOSCRIPT> <div style="border: 2px solid black; background-color: #FFFF99; color: black; width: 600px; height: 70px; padding: 20px;"> <img src="%s" style="border: none;" /> <b>Javascript is not enabled on your browser!</b> <p>This TACTIC powered, web-based application requires JavaScript to be enabled in order to function. In your browser's options/preferences, please make sure that the 'Enable JavaScript' option is checked on, click OK to accept the settings change, and then refresh this web page.</p> </div> </NOSCRIPT> """ % (IconWdg.get_icon_path("ERROR"))) # add the content content_div = DivWdg() top.add(content_div) Container.put("TopWdg::content", content_div) # add a dummy button for global behaviors from tactic.ui.widget import ButtonNewWdg, IconButtonWdg ButtonNewWdg(title="DUMMY", icon=IconWdg.FILM) IconButtonWdg(title="DUMMY", icon=IconWdg.FILM) # NOTE: it does not need to be in the DOM. Just needs to be # instantiated #content_div.add(button) if self.widgets: content_wdg = self.get_widget('content') else: content_wdg = Widget() self.add(content_wdg) content_div.add(content_wdg) # add a calendar wdg from tactic.ui.widget import CalendarWdg cal_wdg = CalendarWdg(css_class='spt_calendar_template_top') cal_wdg.top.add_style('display: none') content_div.add(cal_wdg) if web.is_admin_page(): from tactic_branding_wdg import TacticCopyrightNoticeWdg branding = TacticCopyrightNoticeWdg(show_license_info=True) top.add(branding) # add the admin bar security = Environment.get_security() if not web.is_admin_page() and security.check_access( "builtin", "view_site_admin", "allow"): div = DivWdg() top.add(div) top.add_style("padding-top: 21px") div.add_class("spt_admin_bar") # home icon_div = DivWdg() div.add(icon_div) icon_div.add_style("float: left") icon_div.add_style("margin-right: 10px") icon_div.add_style("margin-top: -3px") icon_button = IconButtonWdg(title="Home", icon="BS_HOME") icon_div.add(icon_button) icon_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' window.location.href="/"; ''' }) div.add_style("height: 15px") div.add_style("padding: 3px 0px 3px 15px") #div.add_style("margin-bottom: -5px") div.add_style("position: fixed") div.add_style("top: 0px") div.add_style("left: 0px") div.add_style("opacity: 0.7") div.add_style("width: 100%") #div.add_gradient("background", "background2", 20, 10) div.add_style("background-color", "#000") div.add_style("color", "#FFF") div.add_style("z-index", "1000") div.add_class("hand") div.set_box_shadow("0px 5px 5px") # remove icon_div = DivWdg() div.add(icon_div) icon_div.add_style("float: right") icon_div.add_style("margin-right: 10px") icon_div.add_style("margin-top: -3px") icon_button = IconButtonWdg(title="Remove Admin Bar", icon="BS_REMOVE") icon_div.add(icon_button) icon_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var parent = bvr.src_el.getParent(".spt_admin_bar"); bvr.src_el.getParent(".spt_top").setStyle("padding-top", "0px"); spt.behavior.destroy_element(parent); ''' }) # sign-out icon_div = DivWdg() div.add(icon_div) icon_div.add_style("float: right") icon_div.add_style("margin-right: 5px") icon_div.add_style("margin-top: -3px") icon_button = IconButtonWdg(title="Sign Out", icon="BS_LOG_OUT") icon_div.add(icon_button) icon_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var ok = function(){ var server = TacticServerStub.get(); server.execute_cmd("SignOutCmd", {login: bvr.login} ); window.location.href="/"; } spt.confirm("Are you sure you wish to sign out?", ok ) ''' }) div.add("<b>ADMIN >></b>") div.add_behavior({ 'type': 'listen', 'event_name': 'close_admin_bar', 'cbjs_action': ''' bvr.src_el.getParent(".spt_top").setStyle("padding-top", "0px"); spt.behavior.destroy_element(bvr.src_el); ''' }) div.add_behavior({ 'type': 'mouseover', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", 0.85) //new Fx.Tween(bvr.src_el).start('height', "30px"); ''' }) div.add_behavior({ 'type': 'mouseout', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", 0.7) //new Fx.Tween(bvr.src_el).start('height', "15px"); ''' }) project_code = Project.get_project_code() site_root = web.get_site_root() div.add_behavior({ 'type': 'click_up', 'site_root': site_root, 'project_code': project_code, 'cbjs_action': ''' var url = "/"+bvr.site_root+"/"+bvr.project_code+"/admin/link/_startup"; window.open(url); ''' }) # Add the script editor listener load_div = DivWdg() top.add(load_div) load_div.add_behavior({ 'type': 'listen', 'event_name': 'show_script_editor', 'cbjs_action': ''' var js_popup_id = "TACTIC Script Editor"; var js_popup = $(js_popup_id); if( js_popup ) { spt.popup.toggle_display( js_popup_id, false ); } else { spt.panel.load_popup(js_popup_id, "tactic.ui.app.ShelfEditWdg", {}, {"load_once": true} ); } ''' }) # deal with the palette defined in /index which can override the palette if self.kwargs.get("hash") == (): key = "index" search = Search("config/url") search.add_filter("url", "/%s/%%" % key, "like") search.add_filter("url", "/%s" % key) search.add_where("or") url = search.get_sobject() if url: xml = url.get_xml_value("widget") palette_key = xml.get_value("element/@palette") # look up palette the expression for index from pyasm.web import Palette palette = Palette.get() palette.set_palette(palette_key) colors = palette.get_colors() colors = jsondumps(colors) script = HtmlElement.script(''' var env = spt.Environment.get(); env.set_colors(%s); env.set_palette('%s'); ''' % (colors, palette_key)) top.add(script) env = Environment.get() client_handoff_dir = env.get_client_handoff_dir(include_ticket=False, no_exception=True) client_asset_dir = env.get_client_repo_dir() login = Environment.get_login() user_name = login.get_value("login") user_id = login.get_id() login_groups = Environment.get_group_names() from pyasm.security import Site site = Site.get_site() kiosk_mode = Config.get_value("look", "kiosk_mode") if not kiosk_mode: kiosk_mode = 'false' # add environment information script = HtmlElement.script(''' var env = spt.Environment.get(); env.set_site('%s'); env.set_project('%s'); env.set_user('%s'); env.set_user_id('%s'); var login_groups = '%s'.split('|'); env.set_login_groups(login_groups); env.set_client_handoff_dir('%s'); env.set_client_repo_dir('%s'); env.set_kiosk_mode('%s'); ''' % (site, Project.get_project_code(), user_name, user_id, '|'.join(login_groups), client_handoff_dir, client_asset_dir, kiosk_mode)) top.add(script) # add a global container for commonly used widgets div = DivWdg() top.add(div) div.set_id("global_container") # add in the app busy widget # find out if there is an override for this search = Search("config/url") search.add_filter("url", "/app_busy") url = search.get_sobject() if url: busy_div = DivWdg() div.add(busy_div) busy_div.add_class("SPT_PUW") busy_div.add_styles( "display: none; position: absolute; z-index: 1000") busy_div.add_class("app_busy_msg_block") busy_div.add_style("width: 300px") busy_div.add_style("height: 100px") busy_div.add_style("padding: 20px") busy_div.add_color("background", "background3") busy_div.add_border() busy_div.set_box_shadow() busy_div.set_round_corners(20) busy_div.set_attr("id", "app_busy_msg_block") # put the custom url here title_wdg = DivWdg() busy_div.add(title_wdg) title_wdg.add_style("font-size: 20px") title_wdg.add_class("spt_app_busy_title") busy_div.add("<hr/>") msg_div = DivWdg() busy_div.add(msg_div) msg_div.add_class("spt_app_busy_msg") else: from page_header_wdg import AppBusyWdg div.add(AppBusyWdg()) # popup parent popup = DivWdg() popup.set_id("popup") div.add(popup) # create another general popup popup_div = DivWdg() popup_div.set_id("popup_container") popup_div.add_class("spt_panel") popup = PopupWdg(id="popup_template", destroy_on_close=True) popup_div.add(popup) div.add(popup_div) inner_html_div = DivWdg() inner_html_div.set_id("inner_html") div.add(inner_html_div) # add in a global color from tactic.ui.input import ColorWdg color = ColorWdg() div.add(color) # add in a global notify wdg from notify_wdg import NotifyWdg widget.add(NotifyWdg()) from tactic.ui.app import DynamicUpdateWdg widget.add(DynamicUpdateWdg()) return widget
# Dump out the error print "WARNING: ", path, status, message try: eval("cherrypy.root.tactic.%s" % project_code) # if project_code is empty , it raises SyntaxError except (AttributeError, SyntaxError), e: has_project = False else: has_project = True # make sure the appropriate site is set (based on the ticket) from pyasm.security import Site cookie = cherrypy.request.cookie if cookie.has_key("login_ticket"): cookie = cookie["login_ticket"].value site = Site.get().get_by_ticket(cookie) else: html_response = '''<html> <head><meta http-equiv="Refresh" content="0; url=/"></head> </html>''' response.body = '' return html_response Site.set_site(site) # if the url does not exist, but the project does, then check to # to see if cherrypy knows about it project = Project.get_by_code(project_code) if not has_project and project and project.get_value( "type") != 'resource':