def postprocess(self): sobject = self.sobject texture_snapshot = Snapshot.get_latest_by_sobject(sobject) web = WebContainer.get_web() source_search_key = web.get_form_value("predefined_source") if source_search_key and texture_snapshot: source = Search.get_by_search_key(source_search_key) source_snapshot = Snapshot.get_latest_by_sobject(source) xml = texture_snapshot.get_xml_value("snapshot") builder = SnapshotBuilder(xml) builder.add_ref_by_snapshot(source_snapshot) texture_snapshot.set_value("snapshot", builder.to_string()) texture_snapshot.commit() return # if no files have been uploaded, don't do anything field_storage = web.get_form_value("add_source") if field_storage == "": return # process and get the uploaded files upload = FileUpload() upload.set_field_storage(field_storage) upload.execute() files = upload.get_files() if not files: return file_types = upload.get_file_types() asset_code = sobject.get_value("asset_code") # checkin this as a new source import os source_code = os.path.basename(files[0]) source_description = "Referred to %s" % self.sobject.get_code() source_category = "default" source = TextureSource.create(asset_code, source_code, \ source_category, source_description) # add the file as a snapshot to this source checkin = FileCheckin(source, files, file_types) checkin.execute() source_snapshot = Snapshot.get_latest_by_sobject(source) xml = source_snapshot.get_xml_value("snapshot") builder = SnapshotBuilder(xml) builder.add_fref_by_snapshot(texture_snapshot) source_snapshot.set_value("snapshot", builder.to_string()) source_snapshot.commit() # Modify the snapshot in the original texture to reference this # source. This assumes that the other uploaded snapshot has # already been dealt with. source_snapshot = checkin.get_snapshot() # FIXME: what if no texture was uploaded??? xml = texture_snapshot.get_xml_value("snapshot") builder = SnapshotBuilder(xml) builder.add_ref_by_snapshot(source_snapshot) texture_snapshot.set_value("snapshot", builder.to_string()) texture_snapshot.commit()
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 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
# 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 postprocess(my): sobject = my.sobject texture_snapshot = Snapshot.get_latest_by_sobject(sobject) web = WebContainer.get_web() source_search_key = web.get_form_value("predefined_source") if source_search_key and texture_snapshot: source = Search.get_by_search_key(source_search_key) source_snapshot = Snapshot.get_latest_by_sobject(source) xml = texture_snapshot.get_xml_value("snapshot") builder = SnapshotBuilder(xml) builder.add_ref_by_snapshot(source_snapshot) texture_snapshot.set_value("snapshot", builder.to_string() ) texture_snapshot.commit() return # if no files have been uploaded, don't do anything field_storage = web.get_form_value("add_source") if field_storage == "": return # process and get the uploaded files upload = FileUpload() upload.set_field_storage(field_storage) upload.execute() files = upload.get_files() if not files: return file_types = upload.get_file_types() asset_code = sobject.get_value("asset_code") # checkin this as a new source import os source_code = os.path.basename(files[0]) source_description = "Referred to %s" % my.sobject.get_code() source_category = "default" source = TextureSource.create(asset_code, source_code, \ source_category, source_description) # add the file as a snapshot to this source checkin = FileCheckin(source, files, file_types ) checkin.execute() source_snapshot = Snapshot.get_latest_by_sobject(source) xml = source_snapshot.get_xml_value("snapshot") builder = SnapshotBuilder(xml) builder.add_fref_by_snapshot(texture_snapshot) source_snapshot.set_value("snapshot", builder.to_string() ) source_snapshot.commit() # Modify the snapshot in the original texture to reference this # source. This assumes that the other uploaded snapshot has # already been dealt with. source_snapshot = checkin.get_snapshot() # FIXME: what if no texture was uploaded??? xml = texture_snapshot.get_xml_value("snapshot") builder = SnapshotBuilder(xml) builder.add_ref_by_snapshot(source_snapshot) texture_snapshot.set_value("snapshot", builder.to_string() ) texture_snapshot.commit()
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