def get_by_key(cls, key, user=None, project_code=None, use_cache=True): if not user: user = Environment.get_user_name() # ignore the project_code column for now dict_key = '%s:%s:%s' %(cls.SEARCH_TYPE, project_code, user) if use_cache: settings_dict = Container.get(dict_key) else: settings_dict = None # explicit check for None if settings_dict == None: settings_dict = {} if use_cache: Container.put(dict_key, settings_dict) search = Search(cls.SEARCH_TYPE) search.add_filter("login", user) if project_code: search.add_filter("project_code", project_code) else: search.add_null_filter("project_code") # don't filter with the key in order to build a dict pref_settings = search.get_sobjects() for setting in pref_settings: settings_dict[setting.get_value('key')] = setting pref_setting = settings_dict.get(key) return pref_setting
def get_connections(cls, sobjects, direction="dst", context='', context_filters=[], src_search=None): '''return a Search instance if src_search is provided''' if not sobjects and not src_search: return [] search = Search(SObjectConnection) if direction == "dst": prefix = "src" else: prefix = "dst" if src_search: search.add_filter("%s_search_type" % prefix, src_search.get_search_type()) search.add_search_filter('%s_search_id' % prefix, src_search, op="in") else: search_types = [x.get_search_type() for x in sobjects] search_ids = [x.get_id() for x in sobjects] if len(Common.get_unique_list(search_types)) == 1: search.add_filter("%s_search_type" % prefix, search_types[0]) search.add_filters("%s_search_id" % prefix, search_ids) else: search.add_op("begin") for search_type, search_id in zip(search_types, search_ids): search.add_op("begin") search.add_filter("%s_search_type" % prefix, search_type) search.add_filter("%s_search_id" % prefix, search_id) search.add_op("and") search.add_op("or") if context: search.add_filter("context", context) elif context_filters: search.add_op_filters(context_filters) if src_search: return search # cache for connection sobjects key = search.get_statement() cache = Container.get("SObjectConnection:cache") if cache == None: cache = {} Container.put("SObjectConnection:cache", cache) ret_val = cache.get(key) if ret_val != None: return ret_val connections = search.get_sobjects() return connections
def set_project(cls, project_code): '''This is kept here because everybody is used to using this''' security = Environment.get_security() # FIXME: # Because it is possible to call this before one is # logged in. This is required to see the login screen. from pyasm.security import get_security_version security_version = get_security_version() if security_version != 1 and not project_code == 'admin': key = { 'code': project_code } key2 = { 'code': "*" } keys = [key, key2] if not security.check_access("project", keys, access="allow", default="deny"): user = Environment.get_login() if user: user = user.get_value("login") raise SecurityException("User [%s] is not permitted to view project [%s]" % (user, project_code)) else: raise SecurityException("User is not permitted to view project [%s]" % (project_code)) from pyasm.security import Site site = Site.get_site() PROJECT_KEY = "Project:global:%s:" % site Container.put(PROJECT_KEY, project_code)
def get(): # try getting from the web from state = Container.get("WebState") if not state: state = WebState() Container.put("WebState", state) return state
def init(self): help = HelpItemWdg( 'Loader', 'The Loader lets you load 3D assets into your 3D applications. Among many options, you can choose to either reference, import, or open the asset through http or the internal file system.' ) self.add(help) pref = PrefSetting.get_value_by_key("use_java_maya") app = WebContainer.get_web().get_app_name_by_uri() if app == "Maya": if not Container.get('GeneralAppletWdg'): self.add(GeneralAppletWdg()) Container.put('GeneralAppletWdg', True) site_menu = SiteMenuWdg() site_menu.add_style("float", "right") site_menu.add_style("margin-top", "-2px") self.add(site_menu) WebContainer.add_js('MayaWebTools.js') WebContainer.add_js('PyMaya.js') tab = MayaTabWdgImpl() tab_value = tab.set_tab_key("maya_tab") #self.handle_tab(tab) #self.add(tab,"tab") self.setup_tab("maya_tab", tab=tab) self.add(ProgressWdg())
def get_resource(my): key = "Project:resource:%s" % my resource = Container.get(key) if resource == None: resource = ProjectResource(my) Container.put(key, resource) return resource
def push_palette(cls, palette): palettes = Container.get("Palette:palettes") if palettes == None: palettes = [] Container.put("Palette:palettes", palettes) palette = Palette(palette=palette) palettes.append(palette)
def __init__(my, buffer_id=None, display_id=None): super(DynamicLoaderWdg, my).__init__() ref_count = Container.get("DyanmicLoaderWdg:ref_count") if ref_count is None: ref_count = 0 if display_id is None: my.display_id = "dynamic_display_%s" % ref_count else: my.display_id = display_id if buffer_id is None: my.buffer_id = "dynamic_buffer_%s" % ref_count else: my.buffer_id = buffer_id my.loader_id = "dynamic_loader_%s" % ref_count Container.put("DyanmicLoaderWdg:ref_count", ref_count + 1) my.load_class = None my.load_args = None web = WebContainer.get_web() my.loader_url = web.get_dynamic_loader_url()
def execute(self): search = Search("sthpw/snapshot") self.person = Person.create( "Unit", "Test", "ComputerWorld", "unittest/checkin_test") self._test_checkin() self._test_copycheckin() self._test_groupcheckin() self._test_inplace_checkin() self._test_preallocation_checkin() self._test_get_children() self._test_file_owner() self._test_symlink() self._test_with_naming() self._test_auto_checkin() self._test_strict_checkin() self._test_base_dir_alias() # clear the xml and config cache introduced by test_base_dir_alias data = {} Container.put(Config.CONFIG_KEY, data) Xml.XML_FILE_CACHE = {} Xml.XML_FILE_MTIME = {}
def get_by_key(cls, key, user=None, project_code=None, use_cache=True): if not user: user = Environment.get_user_name() # ignore the project_code column for now dict_key = '%s:%s:%s' % (cls.SEARCH_TYPE, project_code, user) if use_cache: settings_dict = Container.get(dict_key) else: settings_dict = None # explicit check for None if settings_dict == None: settings_dict = {} if use_cache: Container.put(dict_key, settings_dict) search = Search(cls.SEARCH_TYPE) search.add_filter("login", user) if project_code: search.add_filter("project_code", project_code) else: search.add_null_filter("project_code") # don't filter with the key in order to build a dict pref_settings = search.get_sobjects() for setting in pref_settings: settings_dict[setting.get_value('key')] = setting pref_setting = settings_dict.get(key) return pref_setting
def get(): key = 'CacheList' cache_list = Container.get(key) if not cache_list: cache_list = CacheList() Container.put(key, cache_list) return cache_list
def __init__(my, buffer_id=None, display_id=None): super(DynamicLoaderWdg,my).__init__() ref_count = Container.get("DyanmicLoaderWdg:ref_count") if ref_count is None: ref_count = 0 if display_id is None: my.display_id = "dynamic_display_%s" % ref_count else: my.display_id = display_id if buffer_id is None: my.buffer_id = "dynamic_buffer_%s" % ref_count else: my.buffer_id = buffer_id my.loader_id = "dynamic_loader_%s" % ref_count Container.put("DyanmicLoaderWdg:ref_count", ref_count + 1 ) my.load_class = None my.load_args = None web = WebContainer.get_web() my.loader_url = web.get_dynamic_loader_url()
def get(): key = "JsWrapper" wrapper = Container.get(key) if wrapper == None: wrapper = JsWrapper() Container.put(key, wrapper) return wrapper
def set_pipeline(my, pipeline_xml, cache=True): '''set the pipeline externally''' # cache according to pipeline code, which will share the same xml object if my.is_insert(): cache = False search_key = my.get_search_key() xml_dict = Container.get("Pipeline:xml") if xml_dict == None: xml_dict = {} Container.put("Pipeline:xml", xml_dict) my.xml = xml_dict.get(search_key) if my.xml == None: my.xml = Xml() if cache: xml_dict[search_key] = my.xml if not pipeline_xml: pipeline_xml = "<pipeline/>" try: my.xml.read_string(pipeline_xml) except XmlException, e: my.xml.read_string("<pipeline/>")
def init(my): help = HelpItemWdg('Loader', 'The Loader lets you load 3D assets into your 3D applications. Among many options, you can choose to either reference, import, or open the asset through http or the internal file system.') my.add(help) pref = PrefSetting.get_value_by_key("use_java_maya") app = WebContainer.get_web().get_app_name_by_uri() if app == "Maya": if not Container.get('GeneralAppletWdg'): my.add( GeneralAppletWdg() ) Container.put('GeneralAppletWdg', True) site_menu = SiteMenuWdg() site_menu.add_style("float", "right") site_menu.add_style("margin-top", "-2px") my.add(site_menu) WebContainer.add_js('MayaWebTools.js') WebContainer.add_js('PyMaya.js') tab = MayaTabWdgImpl() tab_value = tab.set_tab_key("maya_tab") #my.handle_tab(tab) #my.add(tab,"tab") my.setup_tab("maya_tab", tab=tab) my.add( ProgressWdg() )
def install(language=""): # get from preferences if not language: from pyasm.biz import PrefSetting language = PrefSetting.get_value_by_key("language") # else get from project setting #if not language: # from pyasm.prod.biz import ProdSetting # language = ProdSetting.get_by_key("language") if os.environ.get("LC_MESSAGES"): language = os.environ.get("LC_MESSAGES") if os.environ.get("TACTIC_LANG"): language = os.environ.get("TACTIC_LANG") # else it is english if not language: language = "en" Container.put("language", language) # add some localization code #gettext.install("messages", unicode=True) #path = "%s/src/locale" % Environment.get_install_dir() #lang = gettext.translation("messages", localedir=path, languages=[language]) #lang.install() # override the _ function import __builtin__ __builtin__._ = Translation._translate
def _test_add_drop_column(my): #Project.set_project('unittest') from pyasm.command import ColumnAddCmd, ColumnDropCmd, Command cmd = ColumnAddCmd('unittest/country','special_place','varchar(256)') Command.execute_cmd(cmd) search_type = 'unittest/country' # clear cache Container.put("SearchType:column_info:%s" % search_type, None) DatabaseImpl.clear_table_cache() exists = SearchType.column_exists(search_type, 'special_place') my.assertEquals(exists, True) # now drop the column cmd = ColumnDropCmd(search_type,'special_place') Command.execute_cmd(cmd) # clear cache Container.put("SearchType:column_info:%s" % search_type, None) cache_dict = Container.get("DatabaseImpl:column_info") # assume database is the same as sthpw database_type = Project.get_by_code("unittest").get_database_type() db_resource = DbResource.get_default('unittest') table_info = cache_dict.get("%s:%s" % (db_resource, "country")) #table_info = cache_dict.get('DbResource:PostgreSQL:localhost:5432:unittest:country') my.assertEquals(table_info != None, True) #key = "%s:%s" % ('DbResource:PostgreSQL:localhost:5432:unittest', 'country') key = "%s:%s" % (db_resource, "country") cache_dict[key] = None exists = SearchType.column_exists(search_type, 'special_place') my.assertEquals(exists, False)
def execute(self): search = Search("sthpw/snapshot") self.person = Person.create("Unit", "Test", "ComputerWorld", "unittest/checkin_test") self._test_checkin() self._test_copycheckin() self._test_groupcheckin() self._test_inplace_checkin() self._test_preallocation_checkin() self._test_get_children() self._test_file_owner() self._test_symlink() self._test_with_naming() self._test_auto_checkin() self._test_strict_checkin() self._test_base_dir_alias() # clear the xml and config cache introduced by test_base_dir_alias data = {} Container.put(Config.CONFIG_KEY, data) Xml.XML_FILE_CACHE = {} Xml.XML_FILE_MTIME = {}
def __init__(self, data=[]): if not data: self.data = [] elif type(data) in types.StringTypes: try: # optimize the loading of json data json_data = Container.get("json_data") if json_data == None: json_data = {} Container.put("json_data", json_data) self.data = json_data.get(data) if self.data == None: self.data = jsonloads(data) json_data[data] = self.data except ValueError, e: if e.__str__().find('No JSON object') != -1: raise SetupException('Data is not decodable as JSON.') # try a straight eval self.data = eval(data) except Exception as e: if e.__str__().find('cannot parse JSON description') != -1: raise SetupException('Data is not valid JSON.')
def set_project(cls, project_code): '''This is kept here because everybody is used to using this''' security = Environment.get_security() # FIXME: # Because it is possible to call this before one is # logged in. This is required to see the login screen. from pyasm.security import get_security_version security_version = get_security_version() if security_version != 1 and not project_code == 'admin': key = {'code': project_code} key2 = {'code': "*"} keys = [key, key2] if not security.check_access( "project", keys, access="allow", default="deny"): user = Environment.get_login() if user: user = user.get_value("login") raise SecurityException( "User [%s] is not permitted to view project [%s]" % (user, project_code)) else: raise SecurityException( "Not permitted to view project [%s]" % (project_code)) from pyasm.security import Site site = Site.get_site() PROJECT_KEY = "Project:global:%s:" % site Container.put(PROJECT_KEY, project_code)
def __init__(my, data=[]): if not data: my.data = [] elif type(data) in types.StringTypes: try: # optimize the loading of json data json_data = Container.get("json_data") if json_data == None: json_data = {} Container.put("json_data", json_data) my.data = json_data.get(data) if my.data == None: my.data = jsonloads(data) json_data[data] = my.data except ValueError, e: if e.__str__().find('No JSON object') != -1: raise SetupException('Data is not decodable as JSON.') # try a straight eval my.data = eval(data) except Exception, e: if e.__str__().find('cannot parse JSON description') != -1: raise SetupException('Data is not valid JSON.')
def get_title(self): widget = Widget() if not Container.get('GeneralAppletWdg'): widget.add( GeneralAppletWdg() ) Container.put('GeneralAppletWdg', True) widget.add(super(LayerTableElementWdg, self).get_title()) return widget
def get_title(self): widget = Widget() if not Container.get('GeneralAppletWdg'): widget.add(GeneralAppletWdg()) Container.put('GeneralAppletWdg', True) widget.add(super(LayerTableElementWdg, self).get_title()) return widget
def get(cls): filter_data = Container.get("FilterData") if filter_data == None: web = WebContainer.get_web() data = web.get_form_value('json') filter_data = FilterData(data) Container.put("FilterData", filter_data) return filter_data
def pop_palette(cls): palettes = Container.get("Palette:palettes") if palettes == None: palettes = [] Container.put("Palette:palettes", palettes) if len(palettes) == 0: return palettes[0] return palettes.pop()
def execute(self): #print("Searching for sync shares ....") search = Search("sthpw/sync_server") search.add_filter("state", "online") servers = search.get_sobjects() #print("... found [%s] online remote share/s" % len(servers)) Container.put("TransactionQueueServers", servers)
def _test_progress_reject(self): # FIXME: it is not completely clear what should happen when a progress # node recieves a revise message. return # create a dummy sobject city = SearchType.create("unittest/city") people = [] person_pipeline_xml = ''' <pipeline> <process type="action" name="p1"/> </pipeline> ''' person_pipeline, person_processes = self.get_pipeline( person_pipeline_xml, search_type="unittest/person") person_pipeline_code = person_pipeline.get_value("code") city_pipeline_xml = ''' <pipeline> <process type="progress" name="c1" pipeline_code="%s" search_type="unittest/person" process="p1" status="complete"/> <process type="approval" name="c2"/> <connect from="c1" to="c2"/> </pipeline> ''' % person_pipeline_code city_pipeline, city_processes = self.get_pipeline( city_pipeline_xml, search_type="unittest/city") city.set_value("pipeline_code", city_pipeline.get_code()) city.commit() from pyasm.common import Container Container.put("process_listeners", None) for name in ['Beth', 'Cindy', 'John']: person = SearchType.create("unittest/person") person.set_value("name_first", name) person.set_value("pipeline_code", person_pipeline.get_code()) person.set_value("city_code", city.get_code()) person.commit() person.set_value("p1", "complete") people.append(person) process = "c2" output = { "pipeline": city_pipeline, "sobject": city, "process": process } Trigger.call(self, "process|reject", output) for person in people: self.assertEquals("revise", person.get_value("p1"))
def get_unique_event_name(self): # generate a unique function name ref_count = Container.get("EventContainer:ref_count") if ref_count == None: ref_count = 0 event_name = "event_name_%s" % ref_count Container.put("EventContainer:ref_count", ref_count + 1 ) return event_name
def init(self): tab_path = Container.get("tab_path") if not tab_path: tab_path = self.name Container.put("tab_path", tab_path) if len(tab_path.split("/")) > 0: self.setup_tab(tab_path, css=TabWdg.SMALL) else: self.setup_tab(tab_path)
def get_unique_event_name(my): # generate a unique function name ref_count = Container.get("EventContainer:ref_count") if ref_count == None: ref_count = 0 event_name = "event_name_%s" % ref_count Container.put("EventContainer:ref_count", ref_count + 1 ) return event_name
def get(cls): palettes = Container.get("Palette:palettes") if palettes == None: palettes = [] Container.put("Palette:palettes", palettes) if not palettes: palette = Palette() palettes.append(palette) else: palette = palettes[-1] return palette
def set_pipeline(self, pipeline_xml, cache=True): '''set the pipeline externally''' # cache according to pipeline code, which will share the same xml object if self.is_insert(): cache = False search_key = self.get_search_key() xml_dict = Container.get("Pipeline:xml") if xml_dict == None: xml_dict = {} Container.put("Pipeline:xml", xml_dict) self.xml = xml_dict.get(search_key) if self.xml == None: self.xml = Xml() if cache: xml_dict[search_key] = self.xml if not pipeline_xml: pipeline_xml = "<pipeline/>" try: self.xml.read_string(pipeline_xml) except XmlException as e: self.xml.read_string("<pipeline/>") # clear these again when set externally self.processes = [] self.recursive_processes = [] # create the process and pipelines process_nodes = self.xml.get_nodes( "pipeline/process | pipeline/pipeline") for node in process_nodes: node_name = self.xml.get_node_name(node) process = Process(node) process.set_parent_pipeline_code(self.get_code()) self.processes.append(process) if node_name == "pipeline": name = Xml.get_attribute(node, "name") # prevent infinite loop if name == self.get_code(): continue child = Pipeline.get_by_code(name) if not child: continue self.pipeline_dict[name] = child process.set_child_pipeline(child)
def get_predefined_schema(cls, code): assert(code) schema = Container.get("Schema:%s" % code) if not schema: schema = Schema("sthpw/schema", dependencies=False) schema.set_value("schema", SCHEMA_XML[code]) schema.set_value("code", code) schema.init() Container.put("Schema:%s" % code, schema) return schema
def init(self): self.sobjects_drawn = {} self.date = datetime.today() self.sobject_display_expr = self.kwargs.get('sobject_display_expr') if self.sobject_display_expr == "None": self.sobject_display_expr = None key = "TaskCalendarDayWdg:display_values" self.display_values = Container.get(key) if self.display_values == None: self.display_values = {} Container.put(key, self.display_values)
def add_behavior(my, bvr_spec): '''adds an individual behavior specification to the HTML based widget''' #print "bvr: ", str(bvr_spec).replace(r"\n", "\n") #print "---" if my.behaviors == None: my.behaviors = [] if type(bvr_spec) == types.DictType: # handle any cbjs string value that has newlines (e.g. ones specified using triple single quote block # quotes in order to have the javascript code readable as indented multi-line code) ... regex = re.compile( r'\n\s*' ) if my.__class__.__name__.find('CheckboxWdg') != -1: if bvr_spec.get('propagate_evt') == None: bvr_spec['propagate_evt'] = True script_path = bvr_spec.get('cbjs_script_path') if script_path: script_sobj = Container.get("HTML::custom_script") if script_sobj == None: basename = os.path.basename(script_path) dirname = os.path.dirname(script_path) search = Search("config/custom_script") search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() if script_sobj: Container.put("HTML::custom_script", script_sobj) v = script_sobj.get_value("script") bvr_spec['cbjs_action'] = regex.sub( '\n', v ) else: raise Exception( "Error: script path [%s] does not exist" % script_path ) for k,v in bvr_spec.iteritems(): if 'cbjs' in k and '\n' in v: bvr_spec[k] = regex.sub( '\n', v ) my.behaviors.append( bvr_spec ) elif type(bvr_spec) == types.StringType: # legacy support for any '.add_behavior' calls that provide a bvr_spec argument that is a string # representation of a behavior specification dictionary my.behaviors.append( my.convert_behavior_str(bvr_spec) ) else: raise Exception( "Behavior specification should be a dictionary, %s spec is not supported." % type(bvr_spec) ) count = Container.get("Widget:bvr_count") if not count: count = 1 else: count += 1 Container.put("Widget:bvr_count", count)
def get_connections(cls, sobjects, direction="dst", context='', context_filters=[], src_search=None): '''return a Search instance if src_search is provided''' if not sobjects and not src_search: return [] search = Search(SObjectConnection) if direction == "dst": prefix = "src" else: prefix = "dst" if src_search: search.add_filter("%s_search_type" % prefix, src_search.get_search_type() ) search.add_search_filter('%s_search_id'%prefix, src_search, op="in") else: search_types = [x.get_search_type() for x in sobjects] search_ids = [x.get_id() for x in sobjects] if len(Common.get_unique_list(search_types)) == 1: search.add_filter("%s_search_type" % prefix, search_types[0] ) search.add_filters("%s_search_id" % prefix, search_ids) else: search.add_op("begin") for search_type, search_id in zip(search_types, search_ids): search.add_op("begin") search.add_filter("%s_search_type" % prefix, search_type ) search.add_filter("%s_search_id" % prefix, search_id ) search.add_op("and") search.add_op("or") if context: search.add_filter("context", context) elif context_filters: search.add_op_filters(context_filters) if src_search: return search # cache for connection sobjects key = search.get_statement() cache = Container.get("SObjectConnection:cache") if cache == None: cache = {} Container.put("SObjectConnection:cache", cache) ret_val = cache.get(key) if ret_val != None: return ret_val connections = search.get_sobjects() return connections
def init(my): my.sobjects_drawn = {} my.date = datetime.today() my.sobject_display_expr = my.kwargs.get('sobject_display_expr') if my.sobject_display_expr == "None": my.sobject_display_expr = None key = "TaskCalendarDayWdg:display_values" my.display_values = Container.get(key) if my.display_values == None: my.display_values = {} Container.put(key, my.display_values)
def add_listener(self, event_name, script_text, replace=False): # generate a unique function name ref_count = Container.get("EventContainer:ref_count") if ref_count == None: cur_time = str(int(time.time())) # the last few digits of the current time ref_count = int(cur_time[-5:]) function = "event_listener_%s" % ref_count Container.put("EventContainer:ref_count", ref_count + 1 ) self.script.add("function %s() { %s }\n" % (function, script_text) ) self.add_listener_func( event_name, function, replace )
def add_listener(my, event_name, script_text, replace=False): # generate a unique function name ref_count = Container.get("EventContainer:ref_count") if ref_count == None: cur_time = str(int(time.time())) # the last few digits of the current time ref_count = int(cur_time[-5:]) function = "event_listener_%s" % ref_count Container.put("EventContainer:ref_count", ref_count + 1 ) my.script.add("function %s() { %s }\n" % (function, script_text) ) my.add_listener_func( event_name, function, replace )
def get_display(my): top = DivWdg() hash = my.kwargs.get("hash") Container.put("url_hash", hash) security = Environment.get_security() is_admin = security.check_access("builtin", "view_site_admin", "allow") if hash == "/admin" and not is_admin: hash = "/index" if not hash: # NOTE: this really doesn't get call anymore because an empty # hash gets remapped to "/index" widget = my.get_default_wdg() top.add(widget) # This would provide a way to get the default index widget. #elif hash == "/projects": # widget = my.get_default_wdg() # from tactic_sites.default.modules import IndexWdg # top.add( IndexWdg() ) else: from tactic.ui.panel import HashPanelWdg project_code = Project.get_project_code() if project_code == 'admin' and hash == '/index': widget = my.get_default_wdg() else: #print "HASH: ", hash #print "project: ", project_code from pyasm.security import Site #print "site: ", Site.get_site() widget = HashPanelWdg.get_widget_from_hash(hash, return_none=True) if not widget: if hash == "/index": widget = my.get_default_wdg() elif hash == '/admin': widget = my.get_default_wdg() else: widget = HashPanelWdg.get_widget_from_hash("/index", return_none=True) top.add(widget) return top
def get_display(my): top = DivWdg() hash = my.kwargs.get("hash") Container.put("url_hash", hash) security = Environment.get_security() is_admin = security.check_access("builtin", "view_site_admin", "allow") if hash == "/admin" and not is_admin: hash = "/index" if not hash: # NOTE: this really doesn't get call anymore because an empty # hash gets remapped to "/index" widget = my.get_default_wdg() top.add(widget) # This would provide a way to get the default index widget. #elif hash == "/projects": # widget = my.get_default_wdg() # from tactic_sites.default.modules import IndexWdg # top.add( IndexWdg() ) else: from tactic.ui.panel import HashPanelWdg project_code = Project.get_project_code() if project_code == 'admin' and hash == '/index': widget = my.get_default_wdg() else: print "HASH: ", hash print "project: ", project_code from pyasm.security import Site print "site: ", Site.get_site() widget = HashPanelWdg.get_widget_from_hash(hash, return_none=True) if not widget: if hash == "/index": widget = my.get_default_wdg() elif hash == '/admin': widget = my.get_default_wdg() else: widget = HashPanelWdg.get_widget_from_hash("/index", return_none=True) top.add(widget) return top
def execute(my): sudo = Sudo() input = my.get_input() search_key = input.get("search_key") update_data = input.get("update_data") mode = input.get("mode") if mode in ['insert', 'delete', 'retire']: return task = Search.get_by_search_key(search_key) process = task.get_value("process") context = task.get_value("context") parent = task.get_parent() # find all of the tasks with the same parent and same context search = Search("sthpw/task") search.add_parent_filter(parent) search.add_filter("process", process) search.add_filter("context", context) tasks = search.get_sobjects() trigger_dict = Container.get('RelatedTaskUpdateTrigger') if not trigger_dict: trigger_dict = {} for attr, value in update_data.items(): # skip assigned as this is the only difference between related tasks if attr == 'assigned': continue # update_data could have the post-conversion value None if value == None: value = '' for task in tasks: task_search_key = task.get_search_key() # skip the current one if task_search_key == search_key or trigger_dict.get( task_search_key): continue task.set_value(attr, value) trigger_dict[task_search_key] = True Container.put('RelatedTaskUpdateTrigger', trigger_dict) # this should run trigger where applicable task.commit(triggers=True) del sudo
def execute(my): sudo = Sudo() input = my.get_input() search_key = input.get("search_key") update_data = input.get("update_data") mode = input.get("mode") if mode in ['insert','delete','retire']: return task = Search.get_by_search_key(search_key) process = task.get_value("process") context = task.get_value("context") parent = task.get_parent() # find all of the tasks with the same parent and same context search = Search("sthpw/task") search.add_parent_filter(parent) search.add_filter("process", process) search.add_filter("context", context) tasks = search.get_sobjects() trigger_dict = Container.get('RelatedTaskUpdateTrigger') if not trigger_dict: trigger_dict = {} for attr, value in update_data.items(): # skip assigned as this is the only difference between related tasks if attr == 'assigned': continue # update_data could have the post-conversion value None if value == None: value = '' for task in tasks: task_search_key = task.get_search_key() # skip the current one if task_search_key == search_key or trigger_dict.get(task_search_key): continue task.set_value(attr, value) trigger_dict[task_search_key] = True Container.put('RelatedTaskUpdateTrigger', trigger_dict) # this should run trigger where applicable task.commit(triggers=True) del sudo
def add(my,widget,title=None,index=None): if title == None: title = widget.__class__.__name__ # determine the url and check security # DEPRECATED!!!! use "tab" security url_selector = WebContainer.get_web().get_request_url().get_selector() check = "%s|%s" % (url_selector,title) # check tab security if my.mode != "check": security = WebContainer.get_security() if not security.check_access("url", check, "view"): return # new security mechanism if not security.check_access("tab_title", title, "view"): return # new, new security mechanism tab_path = my.get_tab_path(title) if not security.check_access("tab", tab_path, "view"): return # check if this tab is invisible if not my.check_visibility(tab_path): return if index == None: my.tab_names.append(title) else: my.tab_names.insert(index,title) my.wdg_dict[title] = widget # for tabs, the widget passed in can be None. Only the # title is added if widget == None: return # only the selected one really gets added if not my.tab_value or title == my.tab_value: Container.put("tab_path", my.get_tab_path(title)) widget = my.init_widget(widget, title) # the very first time user click on the main tab if not my.tab_value: my.tab_value = title super(TabWdg,my)._add_widget(widget, title)