def init(self): self.add("Process: ") checkbox = CheckboxWdg("process") checkbox.set_option("value", "on") checkbox.set_persistence() checkbox.add_event("onclick", "document.form.submit()") self.add(checkbox)
class ArtistViewWdg(SpanWdg): def init(self): self.add("Show assigned only: ") self.checkbox = CheckboxWdg("show_assigned_only") self.checkbox.set_option("value", "on") self.checkbox.set_persistence() self.checkbox.add_event("onclick", "document.form.submit()") self.add(self.checkbox) self.add_class("med") def is_supervisor(self): # if the user is a supervisor, look at all of the assets project = Project.get_project_name() security = Environment.get_security() return security.check_access("prod/%s" % project, "model/supervisor", "true") def is_artist(self): # if the user is a artist, look at all of the assets project = Project.get_project_name() security = Environment.get_security() return security.check_access("prod/%s" % project, "model/artist", "true") def alter_search(self, search): # get all of the relevant tasks to the user task_search = Search("sthpw/task") task_search.add_column("search_id") # only look at this project project = Project.get_project_name() task_search.add_filter("search_type", search.get_search_type()) # figure out who the user is security = Environment.get_security() login = security.get_login() user = login.get_value("login") print "is_artist: ", self.is_artist() print "is_supervisor: ", self.is_supervisor() # do some filtering web = WebContainer.get_web() show_assigned_only = self.checkbox.get_value() show_process = web.get_form_values("process") if not show_process or show_process[0] == '': show_process = [] show_task_status = web.get_form_values("task_status") if not show_task_status or show_task_status[0] == '': show_task_status = [] if show_assigned_only == "on": task_search.add_filter("assigned", user) if show_process: where = "process in (%s)" % ", ".join( ["'%s'" % x for x in show_process]) task_search.add_where(where) if show_task_status: where = "status in (%s)" % ", ".join( ["'%s'" % x for x in show_task_status]) task_search.add_where(where) else: task_search.add_where("NULL") # record the tasks self.tasks = task_search.get_sobjects() # get all of the sobject ids sobject_ids = ["'%s'" % x.get_value("search_id") for x in self.tasks] # get all of the sobjects related to this task if sobject_ids: search.add_where("id in (%s)" % ", ".join(sobject_ids))
def get_upload_wdg(my): '''get search type select and upload wdg''' widget = DivWdg(css='spt_import_csv') widget.add_color('color','color') widget.add_color('background','background') widget.add_style('width: 600px') # get the search type title = DivWdg("<b>Select sType to import data into:</b> ") widget.add( title ) title.add_style("float: left") # handle new search_types new_search_type = CheckboxWdg("new_search_type_checkbox") new_search_type.add_event("onclick", "toggle_display('new_search_type_div')") #span = SpanWdg(css="med") #span.add(new_search_type) #span.add("Create new type") #span.add(" ... or ... ") #widget.add(span) new_search_type_div = DivWdg() new_search_type_div.set_id("new_search_type_div") name_input = TextWdg("asset_name") title = TextWdg("asset_title") description = TextAreaWdg("asset_description") key='csv_import' table = Table() table.set_id('csv_main_body') table.add_style("margin: 10px 10px") table.add_col().set_attr('width','140') table.add_col().set_attr('width','400') table.add_row() table.add_header("Search Type: ").set_attr('align','left') table.add_cell(name_input) table.add_row() table.add_header("Title: ").set_attr('align','left') table.add_cell(title) table.add_row() table.add_header("Description: ").set_attr('align','left') table.add_cell(description) new_search_type_div.add(table) new_search_type_div.add_style("display: none") #widget.add(new_search_type_div) div = DivWdg() search_type_select = SearchTypeSelectWdg("search_type_filter", mode=SearchTypeSelectWdg.ALL) search_type_select.add_empty_option("-- Select --") if not search_type_select.get_value(): search_type_select.set_value(my.search_type) search_type_select.set_persist_on_submit() div.add(search_type_select) widget.add(div) search_type_select.add_behavior( {'type': 'change', \ 'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': bvr.src_el.value});" %(Common.get_full_class_name(my)) } ) if my.search_type: sobj = None try: sobj = SObjectFactory.create(my.search_type) except ImportError: widget.add(HtmlElement.br()) widget.add(SpanWdg('WARNING: Import Error encountered. Please choose another search type.', css='warning')) return widget required_columns = sobj.get_required_columns() if required_columns: widget.add(HtmlElement.br()) req_span = SpanWdg("Required Columns: ", css='med') req_span.add_color('color','color') widget.add(req_span) #required_columns = ['n/a'] req_span.add(', '.join(required_columns)) widget.add( HtmlElement.br() ) if my.file_path: hidden = HiddenWdg("file_path", my.file_path) widget.add(hidden) if my.web_url: file_span = FloatDivWdg('URL: <i>%s</i> ' %my.web_url, css='med') else: file_span = FloatDivWdg('File uploaded: <i>%s</i> ' %os.path.basename(my.file_path), css='med') file_span.add_color('color','color') file_span.add_style('margin: 8px 0 0 10px') file_span.add_style('font-size: 14px') widget.add(file_span) button = ActionButtonWdg(title='Change') button.add_style('float','left') button.add_behavior( {'type': 'click_up', \ 'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': '%s'});" %(Common.get_full_class_name(my), my.search_type) } ) widget.add(button) widget.add("<br clear='all'/>") widget.add(HtmlElement.br()) return widget widget.add("<br/>") widget.add_style("overflow-y: auto") msg = DivWdg() widget.add(msg) msg.add( "<div style='float: left; padding-left: 100px; padding-top: 6px'><b>Upload a csv file: </b></div>") msg.add_border() msg.add_style("width: 400px") msg.add_color("background", "background3") msg.add_style("padding: 20px") msg.add_style("margin: 30 auto") msg.add_style("text-align: center") ticket = Environment.get_security().get_ticket_key() on_complete = '''var server = TacticServerStub.get(); var file = spt.html5upload.get_file(); if (file) { var file_name = file.name; // clean up the file name the way it is done in the server file_name = spt.path.get_filesystem_name(file_name); var server = TacticServerStub.get(); var class_name = 'tactic.ui.widget.CsvImportWdg'; var values = spt.api.Utility.get_input_values('csv_import_main'); values['is_refresh'] = true; values['file_name'] = file_name; values['html5_ticket'] = '%s'; try { var info = spt.panel.load('csv_import_main', class_name, {}, values); spt.app_busy.hide(); } catch(e) { spt.alert(spt.exception.handler(e)); } } else { alert('Error: file object cannot be found.') } spt.app_busy.hide();'''%ticket from tactic.ui.input import UploadButtonWdg browse = UploadButtonWdg(name='new_csv_upload', title="Browse", tip="Click to choose a csv file",\ on_complete=on_complete, ticket=ticket) browse.add_style('float: left') msg.add(browse) # this is now only used in the copy and paste Upload button for backward-compatibility upload_wdg = SimpleUploadWdg(key=key, show_upload=False) upload_wdg.add_style('display: none') msg.add(upload_wdg) #widget.add(span) msg.add("<br/><br/>-- OR --</br/><br/>") msg.add("<b>Published URL: </b>") text = TextWdg("web_url") msg.add(text) msg.add("<br/><br/>-- OR --</br/><br/>") msg.add("<b>Copy and Paste from a Spreadsheet: </b>") text = TextAreaWdg("data") text.add_style('width: 33em') text.add_class("spt_import_cut_paste") msg.add(text) button = ActionButtonWdg(title="Parse") button.add_style("margin: 5px auto") msg.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_import_top"); var el = top.getElement(".spt_import_cut_paste"); var applet = spt.Applet.get(); var value = el.value; var csv = []; // convert to a csv file! lines = value.split("\\n"); for (var i = 0; i < lines.length; i++) { if (lines[i] == '') { continue; } var parts = lines[i].split("\\t"); var new_line = []; for (var j = 0; j < parts.length; j++) { if (parts[j] == '') { new_line.push(''); } else { new_line.push('"'+parts[j]+'"'); } } new_line = new_line.join(","); csv.push(new_line); } csv = csv.join("\\n") // FIXME: need to get a local temp directory var path = spt.browser.os_is_Windows() ? "C:/sthpw/copy_n_paste.csv" : "/tmp/sthpw/copy_n_paste.csv"; applet.create_file(path, csv); // upload the file applet.upload_file(path) applet.rmtree(path); var top = bvr.src_el.getParent(".spt_import_csv"); var hidden = top.getElement(".spt_upload_hidden"); hidden.value = path; var file_name = spt.path.get_basename(hidden.value); file_name = spt.path.get_filesystem_name(file_name); var class_name = 'tactic.ui.widget.CsvImportWdg'; var values = spt.api.Utility.get_input_values('csv_import_main'); values['is_refresh'] = true; values['file_name'] = file_name; var info = spt.panel.load('csv_import_main', class_name, {}, values); ''' } ) return widget
def get_upload_wdg(self): widget = Widget() # get the search type widget.add("1. Select type of asset: ") # handle new search_types new_search_type = CheckboxWdg("new_search_type_checkbox") new_search_type.add_event("onclick", "toggle_display('new_search_type_div')") #span = SpanWdg(css="med") #span.add(new_search_type) #span.add("Create new type") #span.add(" ... or ... ") #widget.add(span) new_search_type_div = DivWdg() new_search_type_div.set_id("new_search_type_div") name_input = TextWdg("asset_name") title = TextWdg("asset_title") description = TextAreaWdg("asset_description") table = Table() table.add_style("margin: 10px 20px") table.add_col().set_attr('width', '140') table.add_col().set_attr('width', '400') table.add_row() table.add_header("Search Type: ").set_attr('align', 'left') table.add_cell(name_input) table.add_row() table.add_header("Title: ").set_attr('align', 'left') table.add_cell(title) table.add_row() table.add_header("Description: ").set_attr('align', 'left') table.add_cell(description) new_search_type_div.add(table) new_search_type_div.add_style("display: none") #widget.add(new_search_type_div) # or use a pre-existing one search_type_select = SearchTypeSelectWdg("filter|search_type") search_type_select.add_empty_option("-- Select --") search_type_select.set_persist_on_submit() search_type_select.set_submit_onchange() widget.add(search_type_select) self.search_type = search_type_select.get_value() if self.search_type: sobj = SObjectFactory.create(self.search_type) required_columns = sobj.get_required_columns() widget.add(SpanWdg("Required Columns: ", css='med')) if not required_columns: required_columns = ['n/a'] widget.add(SpanWdg(', '.join(required_columns), css='med')) widget.add(HtmlElement.br(2)) widget.add("2. Upload a csv file: ") upload_wdg = HtmlElement.upload("uploaded_file") widget.add(upload_wdg) submit = IconSubmitWdg("Upload", IconWdg.UPLOAD, True) widget.add(submit) web = WebContainer.get_web() field_storage = web.get_form_value("uploaded_file") if field_storage != "": upload = FileUpload() upload.set_field_storage(field_storage) upload.set_create_icon(False) upload.execute() files = upload.get_files() if files: self.file_path = files[0] else: self.file_path = web.get_form_value("file_path") if self.file_path: hidden = HiddenWdg("file_path", self.file_path) widget.add(hidden) return widget
class ArtistViewWdg(SpanWdg): def init(self): self.add("Show assigned only: ") self.checkbox = CheckboxWdg("show_assigned_only") self.checkbox.set_option("value", "on") self.checkbox.set_persistence() self.checkbox.add_event("onclick", "document.form.submit()") self.add(self.checkbox) self.add_class("med") def is_supervisor(self): # if the user is a supervisor, look at all of the assets project = Project.get_project_name() security = Environment.get_security() return security.check_access("prod/%s" % project, "model/supervisor", "true") def is_artist(self): # if the user is a artist, look at all of the assets project = Project.get_project_name() security = Environment.get_security() return security.check_access("prod/%s" % project, "model/artist", "true") def alter_search(self, search): # get all of the relevant tasks to the user task_search = Search("sthpw/task") task_search.add_column("search_id") # only look at this project project = Project.get_project_name() task_search.add_filter("search_type", search.get_search_type()) # figure out who the user is security = Environment.get_security() login = security.get_login() user = login.get_value("login") print "is_artist: ", self.is_artist() print "is_supervisor: ", self.is_supervisor() # do some filtering web = WebContainer.get_web() show_assigned_only = self.checkbox.get_value() show_process = web.get_form_values("process") if not show_process or show_process[0] == '': show_process = [] show_task_status = web.get_form_values("task_status") if not show_task_status or show_task_status[0] == '': show_task_status = [] if show_assigned_only == "on": task_search.add_filter("assigned", user) if show_process: where = "process in (%s)" % ", ".join( ["'%s'" % x for x in show_process] ) task_search.add_where(where) if show_task_status: where = "status in (%s)" % ", ".join( ["'%s'" % x for x in show_task_status] ) task_search.add_where(where) else: task_search.add_where("NULL") # record the tasks self.tasks = task_search.get_sobjects() # get all of the sobject ids sobject_ids = ["'%s'" % x.get_value("search_id") for x in self.tasks] # get all of the sobjects related to this task if sobject_ids: search.add_where( "id in (%s)" % ", ".join(sobject_ids) )
def get_upload_wdg(my): widget = Widget() # get the search type widget.add( "1. Select type of asset: ") # handle new search_types new_search_type = CheckboxWdg("new_search_type_checkbox") new_search_type.add_event("onclick", "toggle_display('new_search_type_div')") #span = SpanWdg(css="med") #span.add(new_search_type) #span.add("Create new type") #span.add(" ... or ... ") #widget.add(span) new_search_type_div = DivWdg() new_search_type_div.set_id("new_search_type_div") name_input = TextWdg("asset_name") title = TextWdg("asset_title") description = TextAreaWdg("asset_description") table = Table() table.add_style("margin: 10px 20px") table.add_col().set_attr('width','140') table.add_col().set_attr('width','400') table.add_row() table.add_header("Search Type: ").set_attr('align','left') table.add_cell(name_input) table.add_row() table.add_header("Title: ").set_attr('align','left') table.add_cell(title) table.add_row() table.add_header("Description: ").set_attr('align','left') table.add_cell(description) new_search_type_div.add(table) new_search_type_div.add_style("display: none") #widget.add(new_search_type_div) # or use a pre-existing one search_type_select = SearchTypeSelectWdg("filter|search_type") search_type_select.add_empty_option("-- Select --") search_type_select.set_persist_on_submit() search_type_select.set_submit_onchange() widget.add(search_type_select) my.search_type = search_type_select.get_value() if my.search_type: sobj = SObjectFactory.create(my.search_type) required_columns = sobj.get_required_columns() widget.add(SpanWdg("Required Columns: ", css='med')) if not required_columns: required_columns = ['n/a'] widget.add(SpanWdg(', '.join(required_columns), css='med')) widget.add( HtmlElement.br(2) ) widget.add( "2. Upload a csv file: ") upload_wdg = HtmlElement.upload("uploaded_file") widget.add(upload_wdg) submit = IconSubmitWdg("Upload", IconWdg.UPLOAD, True) widget.add(submit) web = WebContainer.get_web() field_storage = web.get_form_value("uploaded_file") if field_storage != "": upload = FileUpload() upload.set_field_storage(field_storage) upload.set_create_icon(False) upload.execute() files = upload.get_files() if files: my.file_path = files[0] else: my.file_path = web.get_form_value("file_path") if my.file_path: hidden = HiddenWdg("file_path", my.file_path) widget.add(hidden) return widget
def get_upload_wdg(my): '''get search type select and upload wdg''' widget = DivWdg(css='spt_import_csv') widget.add_color('color','color') widget.add_color('background','background') widget.add_style('width: 600px') # get the search type title = DivWdg("<b>Select sType to import data into:</b> ") widget.add( title ) title.add_style("float: left") # handle new search_types new_search_type = CheckboxWdg("new_search_type_checkbox") new_search_type.add_event("onclick", "toggle_display('new_search_type_div')") #span = SpanWdg(css="med") #span.add(new_search_type) #span.add("Create new type") #span.add(" ... or ... ") #widget.add(span) new_search_type_div = DivWdg() new_search_type_div.set_id("new_search_type_div") name_input = TextWdg("asset_name") title = TextWdg("asset_title") description = TextAreaWdg("asset_description") key='csv_import' table = Table() table.set_id('csv_main_body') table.add_style("margin: 10px 10px") table.add_col().set_attr('width','140') table.add_col().set_attr('width','400') table.add_row() table.add_header("Search Type: ").set_attr('align','left') table.add_cell(name_input) table.add_row() table.add_header("Title: ").set_attr('align','left') table.add_cell(title) table.add_row() table.add_header("Description: ").set_attr('align','left') table.add_cell(description) new_search_type_div.add(table) new_search_type_div.add_style("display: none") #widget.add(new_search_type_div) div = DivWdg() search_type_select = SearchTypeSelectWdg("search_type_filter", mode=SearchTypeSelectWdg.ALL) search_type_select.add_empty_option("-- Select --") if not search_type_select.get_value(): search_type_select.set_value(my.search_type) search_type_select.set_persist_on_submit() div.add(search_type_select) widget.add(div) search_type_select.add_behavior( {'type': 'change', \ 'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': bvr.src_el.value});" %(Common.get_full_class_name(my)) } ) if my.search_type: sobj = None try: sobj = SObjectFactory.create(my.search_type) except ImportError: widget.add(HtmlElement.br()) widget.add(SpanWdg('WARNING: Import Error encountered. Please choose another search type.', css='warning')) return widget required_columns = sobj.get_required_columns() if required_columns: widget.add(HtmlElement.br()) req_span = SpanWdg("Required Columns: ", css='med') req_span.add_color('color','color') widget.add(req_span) #required_columns = ['n/a'] req_span.add(', '.join(required_columns)) widget.add( HtmlElement.br() ) if my.file_path: hidden = HiddenWdg("file_path", my.file_path) widget.add(hidden) if my.web_url: file_span = FloatDivWdg('URL: <i>%s</i> ' %my.web_url, css='med') else: file_span = FloatDivWdg('File uploaded: <i>%s</i> ' %os.path.basename(my.file_path), css='med') file_span.add_color('color','color') file_span.add_style('margin: 8px 0 0 10px') file_span.add_style('font-size: 14px') widget.add(file_span) button = ActionButtonWdg(title='Change') button.add_style('float','left') button.add_behavior( {'type': 'click_up', \ 'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': '%s'});" %(Common.get_full_class_name(my), my.search_type) } ) widget.add(button) widget.add("<br clear='all'/>") widget.add(HtmlElement.br()) return widget widget.add("<br/>") widget.add_style("overflow-y: auto") msg = DivWdg() widget.add(msg) msg.add( "<div style='float: left; padding-left: 100px; padding-top: 6px'><b>Upload a csv file: </b></div>") msg.add_border() msg.add_style("width: 400px") msg.add_color("background", "background3") msg.add_style("padding: 20px") msg.add_style("margin: 30 auto") msg.add_style("text-align: center") ticket = Environment.get_security().get_ticket_key() on_complete = '''var server = TacticServerStub.get(); var file = spt.html5upload.get_file(); if (file) { var file_name = file.name; // clean up the file name the way it is done in the server //file_name = spt.path.get_filesystem_name(file_name); var server = TacticServerStub.get(); var class_name = 'tactic.ui.widget.CsvImportWdg'; var values = spt.api.Utility.get_input_values('csv_import_main'); values['is_refresh'] = true; values['file_name'] = file_name; values['html5_ticket'] = '%s'; try { var info = spt.panel.load('csv_import_main', class_name, {}, values); spt.app_busy.hide(); } catch(e) { spt.alert(spt.exception.handler(e)); } } else { alert('Error: file object cannot be found.') } spt.app_busy.hide();'''%ticket from tactic.ui.input import UploadButtonWdg browse = UploadButtonWdg(name='new_csv_upload', title="Browse", tip="Click to choose a csv file",\ on_complete=on_complete, ticket=ticket) browse.add_style('float: left') msg.add(browse) # this is now only used in the copy and paste Upload button for backward-compatibility upload_wdg = SimpleUploadWdg(key=key, show_upload=False) upload_wdg.add_style('display: none') msg.add(upload_wdg) #widget.add(span) msg.add("<br/><br/>-- OR --</br/><br/>") msg.add("<b>Published URL: </b>") text = TextWdg("web_url") msg.add(text) msg.add("<br/><br/>-- OR --</br/><br/>") msg.add("<b>Copy and Paste from a Spreadsheet: </b>") text = TextAreaWdg("data") text.add_style('width: 33em') text.add_class("spt_import_cut_paste") msg.add(text) button = ActionButtonWdg(title="Parse") button.add_style("margin: 5px auto") msg.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_import_top"); var el = top.getElement(".spt_import_cut_paste"); var applet = spt.Applet.get(); var value = el.value; var csv = []; // convert to a csv file! lines = value.split("\\n"); for (var i = 0; i < lines.length; i++) { if (lines[i] == '') { continue; } var parts = lines[i].split("\\t"); var new_line = []; for (var j = 0; j < parts.length; j++) { if (parts[j] == '') { new_line.push(''); } else { new_line.push('"'+parts[j]+'"'); } } new_line = new_line.join(","); csv.push(new_line); } csv = csv.join("\\n") // FIXME: need to get a local temp directory var path = spt.browser.os_is_Windows() ? "C:/sthpw/copy_n_paste.csv" : "/tmp/sthpw/copy_n_paste.csv"; applet.create_file(path, csv); // upload the file applet.upload_file(path) applet.rmtree(path); var top = bvr.src_el.getParent(".spt_import_csv"); var hidden = top.getElement(".spt_upload_hidden"); hidden.value = path; var file_name = spt.path.get_basename(hidden.value); file_name = spt.path.get_filesystem_name(file_name); var class_name = 'tactic.ui.widget.CsvImportWdg'; var values = spt.api.Utility.get_input_values('csv_import_main'); values['is_refresh'] = true; values['file_name'] = file_name; var info = spt.panel.load('csv_import_main', class_name, {}, values); ''' } ) return widget