def init(my): top = DivWdg() top.set_id('top_of_application') msg_div = DivWdg() msg_div.add_style('text-align: center') msg_div.add('<img src="/context/icons/common/indicator_snake.gif" border="0"/>') msg_div.add(" ") project = Project.get() title = project.get_value("title") if not title: title = "TACTIC" msg_div.add('''Loading "%s" ....'''% title) msg_div.add_style("font-size: 1.5em") msg_div.add_behavior( { 'type': 'load', 'hash': my.hash, 'cbjs_action': ''' if (bvr.hash) { spt.hash.hash = "/" + bvr.hash; } else { spt.hash.hash = "/index"; } ''' } ) msg_div.add_style("margin: 200 0 500 0") top.add(msg_div) my.add(top) return
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 _test_task(self): project = Project.get() # create a new task task = SearchType.create("sthpw/task") task.set_parent(project) task.set_value("code", "XXX001") task.set_value("process", "unittest") task.set_value("description", "unittest") # set a time with no timezone. A timestamp with no timezone should # assume GMT. test_time = '2011-11-11 00:00:00' task.set_value("timestamp", test_time) # asset that the time has not changed timestamp = task.get_value("timestamp") self.assertEquals(timestamp, test_time) task.commit() # get the task back from the databse search = Search("sthpw/task") search.add_filter("code", "XXX001") task = search.get_sobject() # make sure the time has not changed. This value should is assumed # to be in GMT timestamp = task.get_value("timestamp") self.assertEquals(timestamp, test_time) task.delete()
def get_child_codes(self, parent_collection_code, search_type): ''' All of the children's codes down the relationship tree of the collection will be returned. ''' from pyasm.biz import Project project = Project.get() sql = project.get_sql() impl = project.get_database_impl() search_codes = [] parts = search_type.split("/") collection_type = "%s/%s_in_%s" % (parts[0], parts[1], parts[1]) # Check if connection between asset and asset_in_asset is in place if collection_type not in SearchType.get_related_types(search_type): return search_codes stmt = impl.get_child_codes_cte(collection_type, search_type, parent_collection_code) results = sql.do_query(stmt) for result in results: result = "".join(result) search_codes.append(result) return search_codes
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 get_application_wdg(self): page = None try: project = Project.get() except Exception as e: Project.set_project("sthpw") from pyasm.widget import Error404Wdg page = Error404Wdg() page.set_message(e.__str__()) page.status = '' application = self.get_top_wdg() # get the main page widget # NOTE: this needs to happen after the body is put in a Container if not page: page = self.get_page_widget() page.set_as_top() if type(page) in types.StringTypes: page = StringWdg(page) application.add(page, 'content') return application
def get_naming(cls, naming_type, sobject=None, project=None): '''get a certain type of naming determined by type of naming''' naming_cls = "" # this import statement is needed for running Batch from pyasm.biz import Project if not project: if sobject: project = sobject.get_project() else: project = Project.get() if project: naming_cls = project.get_value("%s_naming_cls" % naming_type, no_exception=True) if not naming_cls and project.get_project_type(): naming_cls = project.get_project_type().get_value( "%s_naming_cls" % naming_type, no_exception=True) # if none is defined, use defaults if not naming_cls: # TODO: this should probably be stored somewhere else if naming_type == "file": naming_cls = "pyasm.biz.FileNaming" elif naming_type == "dir": naming_cls = "pyasm.biz.DirNaming" elif naming_type == "node": naming_cls = "pyasm.prod.biz.ProdNodeNaming" naming = Common.create_from_class_path(naming_cls) return naming
def _test_task(my): project = Project.get() # create a new task task = SearchType.create("sthpw/task") task.set_parent(project) task.set_value("code", "XXX001") task.set_value("process", "unittest") task.set_value("description", "unittest") # set a time with no timezone. A timestamp with no timezone should # assume GMT. test_time = '2011-11-11 00:00:00' task.set_value("timestamp", test_time) # asset that the time has not changed timestamp = task.get_value("timestamp") my.assertEquals(timestamp, test_time) task.commit() # get the task back from the databse search = Search("sthpw/task") search.add_filter("code", "XXX001") task = search.get_sobject() # make sure the time has not changed. This value should is assumed # to be in GMT timestamp = task.get_value("timestamp") my.assertEquals(timestamp, test_time) task.delete()
def get_display(my): #defining init is better than get_display() for this kind of SelectWdg search = Search(SearchType.SEARCH_TYPE) if my.mode == None or my.mode == my.ALL_BUT_STHPW: # always add the login / login group search types filter = search.get_regex_filter( "search_type", "login|task|note|timecard|trigger|milestone", "EQ") no_sthpw_filter = search.get_regex_filter("search_type", "^(sthpw).*", "NEQ") search.add_where('%s or %s' % (filter, no_sthpw_filter)) elif my.mode == my.CURRENT_PROJECT: project = Project.get() project_code = project.get_code() #project_type = project.get_project_type().get_type() project_type = project.get_value("type") search.add_where("\"namespace\" in ('%s','%s') " % (project_type, project_code)) search.add_order_by("search_type") search_types = search.get_sobjects() values = SObject.get_values(search_types, 'search_type') labels = [x.get_label() for x in search_types] values.append('CustomLayoutWdg') labels.append('CustomLayoutWdg') my.set_option('values', values) my.set_option('labels', labels) #my.set_search_for_options(search, "search_type", "get_label()") my.add_empty_option(label='-- Select Search Type --') return super(SearchTypeSelectWdg, my).get_display()
def get_naming(cls, naming_type, sobject=None, project=None): '''get a certain type of naming determined by type of naming''' naming_cls = "" # this import statement is needed for running Batch from pyasm.biz import Project if not project: if sobject: project = sobject.get_project() else: project = Project.get() if project: naming_cls = project.get_value("%s_naming_cls" % naming_type, no_exception=True) if not naming_cls and project.get_project_type(): naming_cls = project.get_project_type().get_value("%s_naming_cls" % naming_type, no_exception=True) # if none is defined, use defaults if not naming_cls: # TODO: this should probably be stored somewhere else if naming_type == "file": naming_cls = "pyasm.biz.FileNaming" elif naming_type == "dir": naming_cls = "pyasm.biz.DirNaming" elif naming_type == "node": naming_cls = "pyasm.prod.biz.ProdNodeNaming" naming = Common.create_from_class_path(naming_cls) return naming
def get_display(my): project = Project.get() search_types = project.get_search_types() task_search_type = SearchType.get("sthpw/task") search_types.append(task_search_type) values = [ x.get_value("search_type") for x in search_types] labels = [] for x in search_types: label = "%s (%s)" % (x.get_value("title"), x.get_value("search_type")) labels.append(label) sobject = my.get_current_sobject() if not sobject: value = "" else: value = sobject.get_value(my.get_name() ) my.set_option("values", values) my.set_option("labels", labels) my.add_empty_option("-- Select --") if value: my.set_value(value) return super(SearchTypeInputWdg, my).get_display()
def create_snapshot_xml(my, file_objects, snapshot_xml=None): builder = SnapshotBuilder(snapshot_xml) root = builder.get_root_node() from pyasm.search.sql import DbContainer from pyasm.biz import Project project = Project.get() db_resource = project.get_project_db_resource() sql = DbContainer.get(db_resource) if sql.get_database_type() == 'SQLServer': import datetime Xml.set_attribute(root, "timestamp", datetime.datetime.now()) else: Xml.set_attribute(root, "timestamp", time.asctime()) Xml.set_attribute(root, "context", my.context) for i in range(0, len(file_objects)): file_object = file_objects[i] file_type = my.file_types[i] file_info = {} file_info['type'] = file_type if file_object.get_file_range(): file_info['file_range'] = my.file_range.get_key() builder.add_file(file_object, file_info) for input_snapshot in my.input_snapshots: builder.add_ref_by_snapshot(input_snapshot) return builder.to_string()
def get_display(my): #defining init is better than get_display() for this kind of SelectWdg search = Search( SearchType.SEARCH_TYPE ) if my.mode == None or my.mode == my.ALL_BUT_STHPW: # always add the login / login group search types filter = search.get_regex_filter("search_type", "login|task|note|timecard|trigger|milestone", "EQ") no_sthpw_filter = search.get_regex_filter("search_type", "^(sthpw).*", "NEQ") search.add_where('%s or %s' %(filter, no_sthpw_filter)) elif my.mode == my.CURRENT_PROJECT: project = Project.get() project_code = project.get_code() #project_type = project.get_project_type().get_type() project_type = project.get_value("type") search.add_where("\"namespace\" in ('%s','%s') " % (project_type, project_code)) search.add_order_by("search_type") search_types = search.get_sobjects() values = SObject.get_values(search_types, 'search_type') labels = [ x.get_label() for x in search_types ] values.append('CustomLayoutWdg') labels.append('CustomLayoutWdg') my.set_option('values', values) my.set_option('labels', labels) #my.set_search_for_options(search, "search_type", "get_label()") my.add_empty_option(label='-- Select Search Type --') return super(SearchTypeSelectWdg, my).get_display()
def create_snapshot_xml(my, file_objects, snapshot_xml=None): builder = SnapshotBuilder(snapshot_xml) root = builder.get_root_node() from pyasm.search.sql import DbContainer from pyasm.biz import Project project = Project.get() db_resource = project.get_project_db_resource() sql = DbContainer.get(db_resource) if sql.get_database_type() == 'SQLServer': import datetime Xml.set_attribute(root, "timestamp", datetime.datetime.now()) else: Xml.set_attribute(root, "timestamp", time.asctime() ) Xml.set_attribute(root, "context", my.context ) for i in range(0, len(file_objects)): file_object = file_objects[i] file_type = my.file_types[i] file_info = {} file_info['type'] = file_type if file_object.get_file_range(): file_info['file_range'] = my.file_range.get_key() builder.add_file(file_object, file_info) for input_snapshot in my.input_snapshots: builder.add_ref_by_snapshot(input_snapshot) return builder.to_string()
def execute(my): sobject = my.get_caller() search_type = sobject.get_base_search_type() all_logins = False if search_type == 'config/widget_config': category = sobject.get_value("category") if not category: category = sobject.get_value("search_type") if category != 'SideBarWdg': return user = sobject.get_value('login') user = user.strip() if not user: all_logins = True from pyasm.biz import Project project = Project.get() project_code = project.get_code() login = Environment.get_user_name() tmp_dir = "%s/cache/side_bar" % Environment.get_tmp_dir() project_check = True if search_type == 'sthpw/login_group': login_objs = sobject.get_logins() logins = [x.get_value('login') for x in login_objs] project_check = False else: if all_logins: expr = '@GET(sthpw/login.login)' logins = Search.eval(expr) else: logins = [login] filenames = [] if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) return search = Search('sthpw/project') projects = search.get_sobjects() project_codes = [x.get_value('code') for x in projects] for login in logins: if project_check: filename = "%s__%s.html" % (project_code, login) filenames.append(filename) else: for project_code in project_codes: filename = "%s__%s.html" % (project_code, login) filenames.append(filename) #filenames = os.listdir(tmp_dir) for filename in filenames: #if not filename.startswith("%s__" % project_code): # print "skip filename ", filename path = "%s/%s" % (tmp_dir, filename) if os.path.exists(path): print "Deleting: ", path os.unlink(path)
def get_header_class_name(cls): project = Project.get() class_name = project.get_value("header_class_name", no_exception=True) if not class_name: class_name = Config.get_value("install", "header_class_name") if not class_name: class_name = 'tactic.ui.app.PageNavContainerWdg' return class_name
def get_main_tab_wdg(): from pyasm.biz import Project project = Project.get() type = project.get_base_type() if type == "": raise TacticException("Project: %s has no type" % project.get_code()) exec( "from pyasm.%s.site import MainTabWdg" % type ) tab = MainTabWdg() return tab
def execute(self): dirname = os.path.dirname(self.script_path) basename = os.path.basename(self.script_path) project = Project.get() # treat the code as a python search = Search("config/custom_script") search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() if not script_sobj: try: # get from the sthpw database search = Search("sthpw/custom_script") search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() if not script_sobj: print( "WARNING: Script with path [%s] does not exist in this project [%s] or Admin Site" % (self.script_path, project.get_code())) return {} except: print( "WARNING: Script with path [%s] does not exist in this project [%s] or Admin Site" % (self.script_path, project.get_code())) return script = script_sobj.get_value("script") if not script: print("WARNING: Empty python script [%s]" % script_sobj.get_code()) return {} if self.trigger_sobj: trigger_sobj = self.trigger_sobj.get_sobject_dict() self.input['trigger_sobject'] = trigger_sobj language = script_sobj.get_value("language") if language == "server_js": from tactic.command import JsCmd cmd = JsCmd(code=script, input=self.input) else: cmd = PythonCmd(code=script, input=self.input) ret_val = cmd.execute() self.ret_val = ret_val self.info['result'] = ret_val #print "input: ", self.input #print "output: ", self.output #print "options: ", self.options return ret_val
def get_application_wdg(my): page = None try: project = Project.get() except Exception, e: Project.set_project("sthpw") from pyasm.widget import Error404Wdg page = Error404Wdg()
def get_predefined_wdg(self): project = Project.get() project_type = project.get_type() from tactic.ui.container import PopupWdg popup = PopupWdg(id="predefined_db_columns", allow_page_activity=True, width="320px") popup.add_title("Predefined Database Columns") popup.add( self.get_section_wdg(view='predefined', default=True)) return popup
def execute(self): dirname = os.path.dirname(self.script_path) basename = os.path.basename(self.script_path) project = Project.get() # treat the code as a python search = Search("config/custom_script") search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() if not script_sobj: try: # get from the sthpw database search = Search("sthpw/custom_script") search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() if not script_sobj: print("WARNING: Script with path [%s] does not exist in this project [%s] or Admin Site" % (self.script_path, project.get_code())) return {} except: print("WARNING: Script with path [%s] does not exist in this project [%s] or Admin Site" % (self.script_path, project.get_code())) return script = script_sobj.get_value("script") if not script: print("WARNING: Empty python script [%s]" %script_sobj.get_code()) return {} if self.trigger_sobj: trigger_sobj = self.trigger_sobj.get_sobject_dict() self.input['trigger_sobject'] = trigger_sobj language = script_sobj.get_value("language") if language == "server_js": from tactic.command import JsCmd cmd = JsCmd(code=script, input=self.input) else: cmd = PythonCmd(code=script, input=self.input) ret_val = cmd.execute() self.ret_val = ret_val self.info['result'] = ret_val #print "input: ", self.input #print "output: ", self.output #print "options: ", self.options return ret_val
def get_milestone_wdg(self): search = Search("sthpw/milestone") project = Project.get() search.add_project_filter(project.get_code()) widget = Widget() widget.set_search(search) table = TableWdg("sthpw/milestone") widget.add(table) return widget
def get_application_wdg(my): page = None try: project = Project.get() except Exception, e: Project.set_project("sthpw") from pyasm.widget import Error404Wdg page = Error404Wdg() page.set_message(e.__str__()) page.status = ''
def get_milestone_wdg(self): search = Search("sthpw/milestone") project = Project.get() search.add_project_filter( project.get_code() ) widget = Widget() widget.set_search(search) table = TableWdg("sthpw/milestone") widget.add(table) return widget
def get_predefined_wdg(my): project = Project.get() project_type = project.get_type() from tactic.ui.container import PopupWdg popup = PopupWdg(id="predefined_db_columns", allow_page_activity=True, width="320px") popup.add_title("Predefined Database Columns") popup.add(my.get_section_wdg(view='predefined', default=True)) return popup
def get_display(my): widget = Widget() div = DivWdg(css="filter_box") show_span = SpanWdg(css="med") show_span.add("Show All Types: ") checkbox = FilterCheckboxWdg("show_all_types") checkbox.set_persistence() show_span.add(checkbox) show_all_types = checkbox.get_value() div.add(show_span) span = SpanWdg(css="med") span.add("Search Type: ") select = SelectWdg("filter|search_type") select.add_empty_option("-- Select --") project = Project.get() project_type = project.get_base_type() search = Search("sthpw/search_object") if show_all_types: search.add_where( """ namespace = '%s' or namespace = '%s' or search_type in ('sthpw/task') """ % (project_type, project.get_code()) ) else: # show only the custom ones search.add_filter("namespace", project.get_code()) search.add_order_by("title") sobjects = search.get_sobjects() select.set_sobjects_for_options(sobjects, "search_type", "title") # select.set_option("query", "sthpw/search_object|search_type|title") select.set_persistence() select.add_event("onchange", "document.form.submit()") search_type = select.get_value() span.add(select) div.add(span) # make sure the current selection exists try: SearchType.get(search_type) except SearchException, e: return div
def init(self): self.config_search_type = self.kwargs.get("config_search_type") if not self.config_search_type: self.config_search_type = "SideBarWdg" self.default = self.kwargs.get('default') == 'True' self.view = self.kwargs.get("view") if type(self.view) in types.StringTypes: self.view = [self.view] web = WebContainer.get_web() self.palette = web.get_palette() self.project = Project.get()
def init(my): my.config_search_type = my.kwargs.get("config_search_type") if not my.config_search_type: my.config_search_type = "SideBarWdg" my.default = my.kwargs.get('default') == 'True' my.view = my.kwargs.get("view") if type(my.view) in types.StringTypes: my.view = [my.view] web = WebContainer.get_web() my.palette = web.get_palette() my.project = Project.get()
def execute(my): project = Project.get() search = Search("sthpw/transaction_log") search.add_filter("namespace", project.get_code()) search.add_column("code") transactions = search.get_sobjects() codes = SObject.get_values(transactions, "code") codes = set(codes) # dump out the transactions for this project f = open("/tmp/transactions_codes", 'wb') f.write(str(codes)) f.close()
def execute(my): project = Project.get() search = Search("sthpw/transaction_log") search.add_filter("namespace", project.get_code() ) search.add_column("code") transactions = search.get_sobjects() codes = SObject.get_values(transactions, "code") codes = set(codes) # dump out the transactions for this project f = open("/tmp/transactions_codes", 'wb') f.write(str(codes)) f.close()
def get_config_wdg(my): widget = Widget() search = Search("sthpw/widget_config") div = DivWdg(css="filter_box") span = SpanWdg(css="med") span.add("Search Type: ") select = FilterSelectWdg("config_search_type") select.add_empty_option("-- Select --") search_type_search = Search("sthpw/search_object") search_type_search.add_order_by("search_type") span.add(select) project = Project.get() project_type = project.get_base_type() filter = search.get_regex_filter("search_type", "login|task|note|timecard", "EQ") search_type_search.add_where( """ namespace = '%s' or namespace = '%s' or %s """ % (project_type, project.get_code(), filter) ) select.set_search_for_options(search_type_search, value_column="search_type") div.add(span) search_type_value = select.get_value() span = SpanWdg() view_text = TextWdg("view") view_text.set_persist_on_submit() span.add("View: ") span.add(view_text) div.add(span) widget.add(div) view = view_text.get_value() if view: search.add_filter("view", view) if search_type_value: search.add_filter("search_type", search_type_value) table = TableWdg("sthpw/widget_config") table.set_search(search) widget.add(table) return widget
def execute(my): assert my.project_code # get the project and find out the date of the last update of the # database project = Project.get() my.version_update = project.get_value("last_version_update", no_exception=True) if not my.version_update: my.version_update = "2.5.0.v01" members = inspect.getmembers(my.__class__, predicate=inspect.ismethod) methods = [] critical_methods = [] for name, member in members: if name.startswith('upgrade_v'): methods.append((name, member)) if name.startswith('critical_v'): critical_methods.append((name, member)) methods.sort() # add the critical methods at the beginning critical_methods.reverse() for critical_method in critical_methods: methods.insert(0, critical_method) # make sure critical methods are run first methods.sort() for name, method in methods: if name.startswith("critical"): method_version = re.sub(r'critical_v(\w*)_(\d{3}(\w)?)$', '\\1', name) else: method_version = re.sub(r'upgrade_v(\w*)_(\d{3}(\w)?)$', '\\1', name) method_version = method_version.replace('_', '.') if my.is_forced: if not (my.version_update <= method_version <= my.to_version): continue elif not (my.version_update < method_version <= my.to_version): continue if not my.quiet: print "Running upgrade for [%s]..." % name my.run_method(name, method)
def get_display(self): top = DivWdg() top.set_id('top_of_application') top.add_style("overflow: hidden") from tactic.ui.panel import HashPanelWdg splash_div = HashPanelWdg.get_widget_from_hash("/splash", return_none=True) if not splash_div: splash_div = DivWdg() splash_div.add_style('text-align: center') splash_div.add( '<img src="/context/icons/common/indicator_snake.gif" border="0"/>' ) splash_div.add(" ") project = Project.get() title = project.get_value("title") if not title: title = "TACTIC" splash_div.add('''Loading "%s" ....''' % title) splash_div.add_style("font-size: 1.5em") splash_div.add_style("margin: 200 0 500 0") splash_div.add_behavior({ 'type': 'load', 'hash': self.hash, 'cbjs_action': ''' if (bvr.hash) { spt.hash.hash = "/" + bvr.hash; } else { spt.hash.hash = "/index"; } spt.hash.set_index_hash("link/_startup"); ''' }) top.add(splash_div) return top
def get_config_wdg(self): widget = Widget() search = Search("sthpw/widget_config") div = DivWdg(css="filter_box") span = SpanWdg(css="med") span.add("Search Type: ") select = FilterSelectWdg("config_search_type") select.add_empty_option("-- Select --") search_type_search = Search("sthpw/search_object") search_type_search.add_order_by("search_type") span.add(select) project = Project.get() project_type = project.get_base_type() filter = search.get_regex_filter("search_type", "login|task|note|timecard", "EQ") search_type_search.add_where(''' namespace = '%s' or namespace = '%s' or %s ''' % (project_type, project.get_code(), filter)) select.set_search_for_options(search_type_search, value_column='search_type') div.add(span) search_type_value = select.get_value() span = SpanWdg() view_text = TextWdg("view") view_text.set_persist_on_submit() span.add("View: ") span.add(view_text) div.add(span) widget.add(div) view = view_text.get_value() if view: search.add_filter("view", view) if search_type_value: search.add_filter("search_type", search_type_value) table = TableWdg("sthpw/widget_config") table.set_search(search) widget.add(table) return widget
def get_display(my): web = WebContainer.get_web() widget = Widget() html = HtmlElement("html") html.add_attr("xmlns:v", 'urn:schemas-microsoft-com:vml') 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(my.get_copyright_wdg()) widget.add(html) # 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(my.get_css_wdg()) # add the title in the header try: project = Project.get() except Exception, e: print "ERROR: ", e # if the project doesn't exist, then use the admin project project = Project.get_by_code("admin")
def execute(my): assert my.project_code # get the project and find out the date of the last update of the # database project = Project.get() my.version_update = project.get_value("last_version_update", no_exception=True) if not my.version_update: my.version_update = "2.5.0.v01" members = inspect.getmembers(my.__class__, predicate=inspect.ismethod) methods = [] critical_methods = [] for name, member in members: if name.startswith('upgrade_v'): methods.append((name, member)) if name.startswith('critical_v'): critical_methods.append((name, member)) methods.sort() # add the critical methods at the beginning critical_methods.reverse() for critical_method in critical_methods: methods.insert(0, critical_method) # make sure critical methods are run first methods.sort() for name, method in methods: if name.startswith("critical"): method_version = re.sub(r'critical_v(\w*)_(\d{3}(\w)?)$', '\\1', name) else: method_version = re.sub(r'upgrade_v(\w*)_(\d{3}(\w)?)$', '\\1', name) method_version = method_version.replace('_', '.') if my.is_forced: if not (my.version_update <= method_version <= my.to_version): continue elif not (my.version_update < method_version <= my.to_version): continue if not my.quiet: print "Running upgrade for [%s]..." %name my.run_method(name, method)
def get_display(my): widget = Widget() div = DivWdg(css="filter_box") show_span = SpanWdg(css='med') show_span.add('Show All Types: ') checkbox = FilterCheckboxWdg('show_all_types') checkbox.set_persistence() show_span.add(checkbox) show_all_types = checkbox.get_value() div.add(show_span) span = SpanWdg(css="med") span.add("Search Type: ") select = SelectWdg("filter|search_type") select.add_empty_option("-- Select --") project = Project.get() project_type = project.get_base_type() search = Search("sthpw/search_object") if show_all_types: search.add_where(''' namespace = '%s' or namespace = '%s' or search_type in ('sthpw/task') ''' % (project_type, project.get_code())) else: # show only the custom ones search.add_filter('namespace', project.get_code()) search.add_order_by("title") sobjects = search.get_sobjects() select.set_sobjects_for_options(sobjects, "search_type", "title") #select.set_option("query", "sthpw/search_object|search_type|title") select.set_persistence() select.add_event("onchange", "document.form.submit()") search_type = select.get_value() span.add(select) div.add(span) # make sure the current selection exists try: SearchType.get(search_type) except SearchException, e: return div
def get_add_menu(my): menu = {'menu_tag_suffix': 'ADD', 'width': 200} opt_spec_list = [ { "type": "action", "label": "Add New sType", "bvr_cb": { 'cbjs_action': ''' var class_name = 'tactic.ui.app.SearchTypeCreatorWdg'; spt.panel.load_popup("Create New sType", class_name); ''' } }, ] from pyasm.biz import Project project = Project.get() search_types = project.get_search_types() if search_types: opt_spec_list.append({"type": "separator"}) for search_type_obj in search_types: title = search_type_obj.get_title() search_type = search_type_obj.get_value("search_type") opt_spec_list.append({ "type": "action", "label": "Add New %s" % title, "bvr_cb": { 'cbjs_action': ''' spt.tab.set_main_body_tab(); spt.tab.add_new("%(title)s", "%(title)s", "tactic.ui.panel.table_layout_wdg.FastTableLayoutWdg", { search_type: "%(search_type)s", view: "table" } ); spt.panel.load_popup("Add New Item", "tactic.ui.panel.EditWdg", { search_type: "%(search_type)s" } ) ''' % { 'title': title, 'search_type': search_type } } }) menu['opt_spec_list'] = opt_spec_list return menu
def get_add_menu(my): menu = {"menu_tag_suffix": "ADD", "width": 200} opt_spec_list = [ { "type": "action", "label": "Add New sType", "bvr_cb": { "cbjs_action": """ var class_name = 'tactic.ui.app.SearchTypeCreatorWdg'; spt.panel.load_popup("Create New sType", class_name); """ }, } ] from pyasm.biz import Project project = Project.get() search_types = project.get_search_types() if search_types: opt_spec_list.append({"type": "separator"}) for search_type_obj in search_types: title = search_type_obj.get_title() search_type = search_type_obj.get_value("search_type") opt_spec_list.append( { "type": "action", "label": "Add New %s" % title, "bvr_cb": { "cbjs_action": """ spt.tab.set_main_body_tab(); spt.tab.add_new("%(title)s", "%(title)s", "tactic.ui.panel.table_layout_wdg.FastTableLayoutWdg", { search_type: "%(search_type)s", view: "table" } ); spt.panel.load_popup("Add New Item", "tactic.ui.panel.EditWdg", { search_type: "%(search_type)s" } ) """ % {"title": title, "search_type": search_type} }, } ) menu["opt_spec_list"] = opt_spec_list return menu
def execute(my): dirname = os.path.dirname(my.script_path) basename = os.path.basename(my.script_path) project = Project.get() # treat the code as a python search = Search("config/custom_script") search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() if not script_sobj: try: search = Search("sthpw/custom_script") search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() if not script_sobj: print( "WARNING: Script with path [%s] does not exist in this project [%s] or Admin Site" % (my.script_path, project.get_code())) return {} except: print( "WARNING: Script with path [%s] does not exist in this project [%s] or Admin Site" % (my.script_path, project.get_code())) return script = script_sobj.get_value("script") if not script: print("WARNING: Empty python script [%s]" % script_sobj.get_code()) return {} if my.trigger_sobj: trigger_sobj = my.trigger_sobj.get_sobject_dict() my.input['trigger_sobject'] = trigger_sobj cmd = PythonCmd(code=script, input=my.input) ret_val = cmd.execute() #print "input: ", my.input #print "output: ", my.output #print "options: ", my.options return ret_val
def get_display(my): web = WebContainer.get_web() widget = Widget() html = HtmlElement("html") html.add_attr("xmlns:v", 'urn:schemas-microsoft-com:vml') 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( my.get_copyright_wdg() ) widget.add(html) # 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(my.get_css_wdg()) # add the title in the header try: project = Project.get() except Exception, e: print "ERROR: ", e # if the project doesn't exist, then use the admin project project = Project.get_by_code("admin")
def get_display(self): top = DivWdg() top.set_id('top_of_application') top.add_style("overflow: hidden") from tactic.ui.panel import HashPanelWdg splash_div = HashPanelWdg.get_widget_from_hash("/splash", return_none=True) if not splash_div: splash_div = DivWdg() splash_div.add_style('text-align: center') splash_div.add('<img src="/context/icons/common/indicator_snake.gif" border="0"/>') splash_div.add(" ") project = Project.get() title = project.get_value("title") if not title: title = "TACTIC" splash_div.add('''Loading "%s" ....'''% title) splash_div.add_style("font-size: 1.5em") splash_div.add_style("margin: 200 0 500 0") splash_div.add_behavior( { 'type': 'load', 'hash': self.hash, 'cbjs_action': ''' if (bvr.hash) { spt.hash.hash = "/" + bvr.hash; } else { spt.hash.hash = "/index"; } spt.hash.set_index_hash("link/_startup"); ''' } ) top.add(splash_div) return top
def get_display(self): widget = DivWdg() widget.add_style("text-align: center") search_type = self.get_current_sobject() project_code = search_type.get_value("database") if project_code == "{project}": # HACK: assumes database == project_code. Can't seem to get # around the {project} variable ... need to look at this # sometime project = Project.get() else: project = Project.get_by_code(project_code) if not project: widget.add( IconWdg("Exists", IconWdg.ERROR) ) widget.add( "Project does not exist") return widget table = search_type.get_table() if not table: return "" try: db_resource = project.get_project_db_resource() sql = DbContainer.get(db_resource) tables = sql.get_tables() has_table = table in tables except DatabaseException: has_table = False if has_table: widget.add( IconWdg("Exists", IconWdg.DOT_GREEN) ) else: widget.add( IconWdg("Does not Exist", IconWdg.DOT_RED) ) return widget
def get_add_menu(my): menu = { 'menu_tag_suffix': 'ADD', 'width': 200 } opt_spec_list = [ { "type": "action", "label": "Add New sType", "bvr_cb": { 'cbjs_action': ''' var class_name = 'tactic.ui.app.SearchTypeCreatorWdg'; spt.panel.load_popup("Create New sType", class_name); ''' } }, ] from pyasm.biz import Project project = Project.get() search_types = project.get_search_types() if search_types: opt_spec_list.append( { "type": "separator" } ) for search_type_obj in search_types: title = search_type_obj.get_title() search_type = search_type_obj.get_value("search_type") opt_spec_list.append( { "type": "action", "label": "Add New %s" % title, "bvr_cb": { 'cbjs_action': ''' spt.tab.set_main_body_tab(); spt.tab.add_new("%(title)s", "%(title)s", "tactic.ui.panel.table_layout_wdg.FastTableLayoutWdg", { search_type: "%(search_type)s", view: "table" } ); spt.panel.load_popup("Add New Item", "tactic.ui.panel.EditWdg", { search_type: "%(search_type)s" } ) ''' % { 'title': title, 'search_type': search_type } } } ) menu['opt_spec_list'] = opt_spec_list; return menu
def execute(my): dirname = os.path.dirname(my.script_path) basename = os.path.basename(my.script_path) project = Project.get() # treat the code as a python search = Search("config/custom_script") search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() if not script_sobj: try: search = Search("sthpw/custom_script") search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() if not script_sobj: print("WARNING: Script with path [%s] does not exist in this project [%s] or Admin Site" % (my.script_path, project.get_code())) return {} except: print("WARNING: Script with path [%s] does not exist in this project [%s] or Admin Site" % (my.script_path, project.get_code())) return script = script_sobj.get_value("script") if not script: print("WARNING: Empty python script [%s]" %script_sobj.get_code()) return {} if my.trigger_sobj: trigger_sobj = my.trigger_sobj.get_sobject_dict() my.input['trigger_sobject'] = trigger_sobj cmd = PythonCmd(code=script, input=my.input) ret_val = cmd.execute() #print "input: ", my.input #print "output: ", my.output #print "options: ", my.options return ret_val
def init(my): #defining init is better than get_display() for this kind of SelectWdg search = Search( SearchType.SEARCH_TYPE ) if my.mode == None or my.mode == my.ALL_BUT_STHPW: # always add the login / login group search types filter = search.get_regex_filter("search_type", "login|task|note|timecard|milestone", "EQ") no_sthpw_filter = search.get_regex_filter("search_type", "^(sthpw).*", "NEQ") search.add_where('%s or %s' %(filter, no_sthpw_filter)) elif my.mode == my.CURRENT_PROJECT: project = Project.get() project_code = project.get_code() #project_type = project.get_project_type().get_type() project_type = project.get_value("type") search.add_where("\"namespace\" in ('%s','%s') " % (project_type, project_code)) search.add_order_by("search_type") my.set_search_for_options(search, "search_type", "get_label()") my.add_empty_option(label='-- Select Search Type --')
def get_final_approval(self): widget = Widget() nav = DivWdg(css='filter_box') episode_filter = None if Project.get().get_type() == 'flash': episode_filter = EpisodeFilterWdg() else: episode_filter = SequenceFilterWdg() nav.add(episode_filter) widget.add(nav) search = Search("prod/shot") episode_filter.alter_search(search) table = TableWdg("prod/shot", "director") table.set_search(search) widget.add(table) return widget
def __init__(my, **kwargs): my.kwargs = kwargs my.colors = my.kwargs.get("colors") palette = my.kwargs.get("palette") if palette: my.set_palette(palette) else: # look at the project from pyasm.biz import Project project = Project.get(no_exception=True) if project: value = project.get_value("palette") my.set_palette(value) # otherwise look at the user if not my.colors: from pyasm.biz import PrefSetting value = PrefSetting.get_value_by_key("palette") my.set_palette(value) # look in the config if not my.colors: value = Config.get_value("look", "palette") my.set_palette(value) if not my.colors: my.colors = my.COLORS # make sure all of the colors are defined for name, value in my.DEFAULT.items(): # make a special provision for theme! if name == 'theme': continue if not my.colors.get(name): my.colors[name] = value
def get_display(self): widget = DivWdg() widget.add_style("text-align: center") search_type = self.get_current_sobject() project_code = search_type.get_value("database") if project_code == "{project}": # HACK: assumes database == project_code. Can't seem to get # around the {project} variable ... need to look at this # sometime project = Project.get() else: project = Project.get_by_code(project_code) if not project: widget.add(IconWdg("Exists", IconWdg.ERROR)) widget.add("Project does not exist") return widget table = search_type.get_table() if not table: return "" try: db_resource = project.get_project_db_resource() sql = DbContainer.get(db_resource) tables = sql.get_tables() has_table = table in tables except DatabaseException: has_table = False if has_table: widget.add(IconWdg("Exists", IconWdg.DOT_GREEN)) else: widget.add(IconWdg("Does not Exist", IconWdg.DOT_RED)) return widget
def get_sobjects(my, group_names): # get the project sobjects sobjects = Project.get().get_search_types() sobject = SearchType.create("sthpw/virtual") sobject.set_value("title", "ALL PROJECTS") sobject.set_value("_extra_data", {"is_all": True}) sobject.set_value("id", 1) sobject.set_value("code", "*") sobjects.insert(0, sobject) # process all of the groups and find out which sobjects security = Environment.get_security() rules_dict = {} for sobject in sobjects: for group_name in group_names: access_rules = rules_dict.get(group_name) if access_rules == None: #!!!!!! #group = LoginGroup.get_by_group_name(group_name) group = my.servers.get(group_name) access_rules = group.get_xml_value("access_rules") rules_dict[group_name] = access_rules node = access_rules.get_node( "rules/rule[@group='search_type' and @code='%s']" % sobject.get_code()) if node is not None: sobject.set_value("_%s" % group_name, True) else: sobject.set_value("_%s" % group_name, False) return sobjects
def init(self): #defining init is better than get_display() for this kind of SelectWdg search = Search(SearchType.SEARCH_TYPE) if self.mode == None or self.mode == self.ALL_BUT_STHPW: # always add the login / login group search types filter = search.get_regex_filter( "search_type", "login|task|note|timecard|milestone", "EQ") no_sthpw_filter = search.get_regex_filter("search_type", "^(sthpw).*", "NEQ") search.add_where('%s or %s' % (filter, no_sthpw_filter)) elif self.mode == self.CURRENT_PROJECT: project = Project.get() project_code = project.get_code() #project_type = project.get_project_type().get_type() project_type = project.get_value("type") search.add_where("\"namespace\" in ('%s','%s') " % (project_type, project_code)) search.add_order_by("search_type") self.set_search_for_options(search, "search_type", "get_label()") self.add_empty_option(label='-- Select Search Type --')
def get_director_notes(self): # FIXME: hard-coded director notes status task_status = "Waiting" widget = Widget() nav = DivWdg(css='filter_box') episode_filter = None if Project.get().get_type() == 'flash': episode_filter = EpisodeFilterWdg() else: episode_filter = SequenceFilterWdg() nav.add(episode_filter) widget.add(nav) shot_search = Search(Shot) episode_filter.alter_search(shot_search) shot_search.add_column('id') shot_ids = shot_search.get_sobjects() shot_ids = SObject.get_values(shot_ids, 'id') # only show shots that have a task at the director level search_type = SearchType.get("prod/shot").get_full_key() search = Search("sthpw/task") search.add_filter("search_type", search_type) search.add_filters("search_id", shot_ids) search.add_filter("status", task_status) tasks = search.get_sobjects() table = TableWdg("sthpw/task", "director") table.set_sobjects(tasks) widget.add(table) return widget