Exemple #1
0
def read_csv_content_from_uploaded_file(ignore_encoding=False):
	if getattr(webnotes, "uploaded_file", None):
		with open(webnotes.uploaded_file, "r") as upfile:
			fcontent = upfile.read()
	else:
		from webnotes.utils.file_manager import get_uploaded_content
		fname, fcontent = get_uploaded_content()
	return read_csv_content(fcontent, ignore_encoding)
Exemple #2
0
def read_csv_content_from_uploaded_file(ignore_encoding=False):
    if getattr(webnotes, "uploaded_file", None):
        with open(webnotes.uploaded_file, "r") as upfile:
            fcontent = upfile.read()
    else:
        from webnotes.utils.file_manager import get_uploaded_content
        fname, fcontent = get_uploaded_content()
    return read_csv_content(fcontent, ignore_encoding)
def upload():
	"""upload data"""
	import csv
	global doctype_dl
	from webnotes.utils.file_manager import get_uploaded_content
	import webnotes.model.doctype
	from webnotes.model.doc import Document
	
	fname, fcontent = get_uploaded_content()
	overwrite = webnotes.form_dict.get('overwrite')

	ret, rows = [], []
	try:
		reader = csv.reader(fcontent.splitlines())
		# decode everything
		csvrows = [[val for val in row] for row in reader]
		
		for row in csvrows:
			newrow = []
			for val in row:
				if webnotes.form_dict.get('ignore_encoding_errors'):
					newrow.append(unicode(val.strip(), 'utf-8', errors='ignore'))
				else:
					try:
						newrow.append(unicode(val.strip(), 'utf-8'))
					except UnicodeDecodeError, e:
						raise Exception, """Some character(s) in row #%s, column #%s are
							not readable by utf-8. Ignoring them. If you are importing a non
							english language, please make sure your file is saved in the 'utf-8'
							encoding.""" % (csvrows.index(row)+1, row.index(val)+1)
					
			rows.append(newrow)
			
	except Exception, e:
		webnotes.msgprint("Not a valid Comma Separated Value (CSV File)")
		raise e
Exemple #4
0
def read_csv_content_from_uploaded_file():
    from webnotes.utils.file_manager import get_uploaded_content
    fname, fcontent = get_uploaded_content()
    return read_csv_content(fcontent)
Exemple #5
0
def read_csv_content_from_uploaded_file(ignore_encoding=False):
	from webnotes.utils.file_manager import get_uploaded_content
	fname, fcontent = get_uploaded_content()
	return read_csv_content(fcontent, ignore_encoding)
Exemple #6
0
def read_csv_content_from_uploaded_file(ignore_encoding=False):
	from webnotes.utils.file_manager import get_uploaded_content
	fname, fcontent = get_uploaded_content()
	return read_csv_content(fcontent, ignore_encoding)
def read_csv_content_from_uploaded_file():
	from webnotes.utils.file_manager import get_uploaded_content
	fname, fcontent = get_uploaded_content()
	return read_csv_content(fcontent)