def dump(my, field_storage=None): web = WebContainer.get_web() ticket = web.get_form_value("transaction_ticket") if not ticket: security = Environment.get_security() ticket = security.get_ticket_key() subdir = web.get_form_value("subdir") #print "subdir: ", subdir action = web.get_form_value("action") #field_storage = web.get_form_value("fileToUpload") file_name = '' if field_storage == "": # for swfupload field_storage = web.get_form_value("Filedata") if not field_storage: file_name = web.get_form_value("Filename") # set a default for now if not action: action = "create" # process and get the uploaded files upload = FileUpload() if action == "append": upload.set_append_mode(True) upload.set_create_icon(False) elif action == "create": upload.set_create_icon(False) elif not action: # this means that we are accessing from browser. return "Upload server" else: print("WARNING: Upload action '%s' not supported" % action) raise TacticException("Upload action '%s' not supported" % action) # set the field storage if field_storage: upload.set_field_storage(field_storage) # set the directory tmpdir = Environment.get_tmp_dir() if subdir: file_dir = "%s/%s/%s/%s" % (tmpdir, "upload", ticket, subdir) else: file_dir = "%s/%s/%s" % (tmpdir, "upload", ticket) #if file_name: # file_path = "%s/%s" % (file_dir, file_name) # upload.set_file_path(file_path) #else: # upload.set_file_dir(file_dir) #print "file_dir: ", file_dir upload.set_file_dir(file_dir) upload.execute() files = upload.get_files() return files
# for swfupload field_storage = web.get_form_value("Filedata") if not field_storage: file_name = web.get_form_value("Filename") # set a default for now action = web.get_form_value("action") if not action: action = "create" # process and get the uploaded files upload = FileUpload() if action == "append": upload.set_append_mode(True) upload.set_create_icon(False) elif action == "create": upload.set_create_icon(False) elif not action: # this means that we are accessing from browser. return "Upload server" else: print("WARNING: Upload action '%s' not supported" % action) raise TacticException("Upload action '%s' not supported" % action) # set the field storage if field_storage: upload.set_field_storage(field_storage, file_name) upload.set_file_dir(file_dir)
if field_storage == "": # for swfupload field_storage = web.get_form_value("Filedata") if not field_storage: file_name = web.get_form_value("Filename") # process and get the uploaded files upload = FileUpload() if action == "append": upload.set_append_mode(True) upload.set_create_icon(False) elif action == "create": upload.set_create_icon(False) elif not action: # this means that we are accessing from browser. return "Upload server" else: print("WARNING: Upload action '%s' not supported" % action) raise TacticException("Upload action '%s' not supported" % action) # set the field storage if field_storage: upload.set_field_storage(field_storage, file_name) upload.set_file_dir(file_dir)
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
def dump(my, field_storage, file_name): web = WebContainer.get_web() ticket = web.get_form_value("transaction_ticket") if not ticket: security = Environment.get_security() ticket = security.get_ticket_key() tmpdir = Environment.get_tmp_dir() subdir = web.get_form_value("subdir") if subdir: file_dir = "%s/%s/%s/%s" % (tmpdir, "upload", ticket, subdir) else: file_dir = "%s/%s/%s" % (tmpdir, "upload", ticket) # With some recent change done in cherrypy._cpreqbody line 294 # we can use the field storage directly and just move the file # without using FileUpload path = field_storage.get_path() if path and file_name: if not os.path.exists(file_dir): os.makedirs(file_dir) basename = os.path.basename(path) to_path = "%s/%s" % (file_dir, file_name) shutil.move(path, to_path) return [to_path] # This may be DEPRECATED raise Exception("Upload method is DEPRECATED") #file_name = '' if field_storage == "": # for swfupload field_storage = web.get_form_value("Filedata") if not field_storage: file_name = web.get_form_value("Filename") # set a default for now action = web.get_form_value("action") if not action: action = "create" # process and get the uploaded files upload = FileUpload() if action == "append": upload.set_append_mode(True) upload.set_create_icon(False) elif action == "create": upload.set_create_icon(False) elif not action: # this means that we are accessing from browser. return "Upload server" else: print("WARNING: Upload action '%s' not supported" % action) raise TacticException("Upload action '%s' not supported" % action) # set the field storage if field_storage: upload.set_field_storage(field_storage, file_name) upload.set_file_dir(file_dir) upload.execute() files = upload.get_files() return files
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