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 add_internal_config(cls, configs, views): '''add an internal config based on project base type''' project = Project.get() project_type = project.get_base_type() # catch potential invalid xpath error try: if project_type: tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path="%s/../config/%s-conf.xml" % (dir_name, project_type) if os.path.exists(file_path): for view in views: config = WidgetConfig.get(file_path=file_path, view=view) if config.get_view_node(): configs.append(config) # finally, just look at the DEFAULT config tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path="%s/../config/%s-conf.xml" % (dir_name, "DEFAULT") if os.path.exists(file_path): for view in views: config = WidgetConfig.get(file_path=file_path, view=view) if config.get_view_node(): configs.append(config) except XmlException, e: msg = "Error with view [%s]"% ' '.join(views) error_list = Container.get_seq(cls.ERR_MSG) if msg not in error_list: Container.append_seq(cls.ERR_MSG, msg) print e.__str__()
def __init__(self, dynamic_load=0, tab_key="tab", css=REG): self.tab_names = [] self.wdg_dict = {} self.dynamic_load = dynamic_load self.set_tab_key(tab_key) self.tab_style = css self.content_height = 0 self.mode = Container.get("tab_mode") # setting tab path self.tab_path = Container.get("tab_path") if not self.tab_path: self.tab_path = "Main" self.error_wdg = None self.div = DivWdg(css='left_content') if Environment.has_tactic_database(): self.invisible_list = ProdSetting.get_seq_by_key('invisible_tabs') else: self.invisible_list = [] super(TabWdg,self).__init__()
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 get(): # try getting from the web from state = Container.get("WebState") if not state: state = WebState() Container.put("WebState", state) return state
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 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 _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 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 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 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 get(): key = 'CacheList' cache_list = Container.get(key) if not cache_list: cache_list = CacheList() Container.put(key, cache_list) return cache_list
def add_internal_config(cls, configs, views): '''add an internal config based on project base type''' project = Project.get() project_type = project.get_base_type() # catch potential invalid xpath error try: if project_type: tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path = "%s/../config/%s-conf.xml" % (dir_name, project_type) if os.path.exists(file_path): for view in views: config = WidgetConfig.get(file_path=file_path, view=view) if config.get_view_node(): configs.append(config) # finally, just look at the DEFAULT config tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path = "%s/../config/%s-conf.xml" % (dir_name, "DEFAULT") if os.path.exists(file_path): for view in views: config = WidgetConfig.get(file_path=file_path, view=view) if config.get_view_node(): configs.append(config) except XmlException as e: msg = "Error with view [%s]" % ' '.join(views) error_list = Container.get_seq(cls.ERR_MSG) if msg not in error_list: Container.append_seq(cls.ERR_MSG, msg) print(e.__str__())
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_resource(my): key = "Project:resource:%s" % my resource = Container.get(key) if resource == None: resource = ProjectResource(my) Container.put(key, resource) return resource
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 __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 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, dynamic_load=0, tab_key="tab", css=REG): my.tab_names = [] my.wdg_dict = {} my.dynamic_load = dynamic_load my.set_tab_key(tab_key) my.tab_style = css my.content_height = 0 my.mode = Container.get("tab_mode") # setting tab path my.tab_path = Container.get("tab_path") if not my.tab_path: my.tab_path = "Main" my.error_wdg = None my.div = DivWdg(css='left_content') if Environment.has_tactic_database(): my.invisible_list = ProdSetting.get_seq_by_key('invisible_tabs') else: my.invisible_list = [] super(TabWdg, my).__init__()
def __init__(self, dynamic_load=0, tab_key="tab", css=REG): self.tab_names = [] self.wdg_dict = {} self.dynamic_load = dynamic_load self.set_tab_key(tab_key) self.tab_style = css self.content_height = 0 self.mode = Container.get("tab_mode") # setting tab path self.tab_path = Container.get("tab_path") if not self.tab_path: self.tab_path = "Main" self.error_wdg = None self.div = DivWdg(css='left_content') if Environment.has_tactic_database(): self.invisible_list = ProdSetting.get_seq_by_key('invisible_tabs') else: self.invisible_list = [] super(TabWdg, self).__init__()
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 __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 __init__(my, dynamic_load=0, tab_key="tab", css=REG): my.tab_names = [] my.wdg_dict = {} my.dynamic_load = dynamic_load my.set_tab_key(tab_key) my.tab_style = css my.content_height = 0 my.mode = Container.get("tab_mode") # setting tab path my.tab_path = Container.get("tab_path") if not my.tab_path: my.tab_path = "Main" my.error_wdg = None my.div = DivWdg(css='left_content') if Environment.has_tactic_database(): my.invisible_list = ProdSetting.get_seq_by_key('invisible_tabs') else: my.invisible_list = [] super(TabWdg,my).__init__()
def get(): key = "JsWrapper" wrapper = Container.get(key) if wrapper == None: wrapper = JsWrapper() Container.put(key, wrapper) return wrapper
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(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 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 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 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 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 _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 __init__(self, project_code=None, login_code=None, site=None): self.set_app_server("batch") if not site: # if not explicitly set, keep the current site site = Site.get_site() plugin_dir = Environment.get_plugin_dir() if plugin_dir not in sys.path: sys.path.insert(0, plugin_dir) super(Batch,self).__init__() self.login_code = login_code # clear the main container Container.create() if site: Site.set_site(site) # set this as the environment if not project_code: self.context = self.get_default_context() else: self.context = project_code Environment.set_env_object( self ) # set up the security object security = Security() Environment.set_security(security) self._do_login() site_dir = Environment.get_site_dir() if site_dir not in sys.path: sys.path.insert(0, site_dir) # set the project from pyasm.biz import Project if self.context == "batch": Project.set_project("admin") else: Project.set_project(self.context) self.initialize_python_path() # start workflow engine #from pyasm.command import Workflow #Workflow().init() DbContainer.commit_thread_sql()
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 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 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 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 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(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 )