Пример #1
0
def upload(select_doctype=None, rows=None):
	from webnotes.utils.datautils import read_csv_content_from_uploaded_file
	from webnotes.modules import scrub
	from webnotes.model.rename_doc import rename_doc

	if not select_doctype:
		select_doctype = webnotes.form_dict.select_doctype

	if not rows:
		rows = read_csv_content_from_uploaded_file()
	if not rows:
		webnotes.msgprint(_("Please select a valid csv file with data."))
		raise Exception
		
	if len(rows) > 500:
		webnotes.msgprint(_("Max 500 rows only."))
		raise Exception
	
	rename_log = []
	for row in rows:
		if len(row) > 2:
			try:
				if rename_doc(select_doctype, row[0], row[1]):
					rename_log.append(_("Successful: ") + row[0] + " -> " + row[1])
					webnotes.conn.commit()
				else:
					rename_log.append(_("Ignored: ") + row[0] + " -> " + row[1])
			except Exception, e:
				rename_log.append("<span style='color: RED'>" + \
					_("Failed: ") + row[0] + " -> " + row[1] + "</span>")
				rename_log.append("<span style='margin-left: 20px;'>" + repr(e) + "</span>")
Пример #2
0
def upload():
    from webnotes.utils.datautils import read_csv_content_from_uploaded_file
    from webnotes.modules import scrub

    rows = read_csv_content_from_uploaded_file()
    if not rows:
        msg = [_("Please select a csv file")]
        return {"messages": msg, "error": msg}
    columns = [scrub(f) for f in rows[4]]
    columns[0] = "name"
    columns[3] = "att_date"
    ret = []
    error = False

    from webnotes.utils.datautils import check_record, import_doc

    doctype_dl = webnotes.get_doctype("Attendance")

    for i, row in enumerate(rows[5:]):
        if not row:
            continue
        row_idx = i + 5
        d = webnotes._dict(zip(columns, row))
        d["doctype"] = "Attendance"
        if d.name:
            d["docstatus"] = webnotes.conn.get_value("Attendance", d.name, "docstatus")

        try:
            check_record(d, doctype_dl=doctype_dl)
            ret.append(import_doc(d, "Attendance", 1, row_idx, submit=True))
        except Exception, e:
            error = True
            ret.append("Error for row (#%d) %s : %s" % (row_idx, len(row) > 1 and row[1] or "", cstr(e)))
            webnotes.errprint(webnotes.getTraceback())
Пример #3
0
def upload(select_doctype=None, rows=None):
    from webnotes.utils.datautils import read_csv_content_from_uploaded_file
    from webnotes.modules import scrub
    from webnotes.model.rename_doc import rename_doc

    if not select_doctype:
        select_doctype = webnotes.form_dict.select_doctype

    if not rows:
        rows = read_csv_content_from_uploaded_file()
    if not rows:
        webnotes.msgprint(_("Please select a valid csv file with data."))
        raise Exception

    if len(rows) > 500:
        webnotes.msgprint(_("Max 500 rows only."))
        raise Exception

    rename_log = []
    for row in rows:
        # if row has some content
        if len(row) > 1 and row[0] and row[1]:
            try:
                if rename_doc(select_doctype, row[0], row[1]):
                    rename_log.append(
                        _("Successful: ") + row[0] + " -> " + row[1])
                    webnotes.conn.commit()
                else:
                    rename_log.append(
                        _("Ignored: ") + row[0] + " -> " + row[1])
            except Exception, e:
                rename_log.append("<span style='color: RED'>" + \
                 _("Failed: ") + row[0] + " -> " + row[1] + "</span>")
                rename_log.append("<span style='margin-left: 20px;'>" +
                                  repr(e) + "</span>")
Пример #4
0
def upload():
    from webnotes.utils.datautils import read_csv_content_from_uploaded_file
    from webnotes.modules import scrub

    rows = read_csv_content_from_uploaded_file()
    if not rows:
        msg = [_("Please select a csv file")]
        return {"messages": msg, "error": msg}
    columns = [scrub(f) for f in rows[4]]
    columns[0] = "name"
    columns[3] = "att_date"
    ret = []
    error = False

    from webnotes.utils.datautils import check_record, import_doc
    doctype_dl = webnotes.get_doctype("Attendance")

    for i, row in enumerate(rows[5:]):
        if not row: continue
        row_idx = i + 5
        d = webnotes._dict(zip(columns, row))
        d["doctype"] = "Attendance"
        if d.name:
            d["docstatus"] = webnotes.conn.get_value("Attendance", d.name,
                                                     "docstatus")

        try:
            check_record(d, doctype_dl=doctype_dl)
            ret.append(import_doc(d, "Attendance", 1, row_idx, submit=True))
        except Exception, e:
            error = True
            ret.append('Error for row (#%d) %s : %s' %
                       (row_idx, len(row) > 1 and row[1] or "", cstr(e)))
            webnotes.errprint(webnotes.getTraceback())
Пример #5
0
def upload():
	from webnotes.utils.datautils import read_csv_content_from_uploaded_file
	rows = read_csv_content_from_uploaded_file()

	common_values = get_common_values(rows)
	company_abbr = webnotes.conn.get_value("Company", common_values.company, "abbr")
	data, start_idx = get_data(rows, company_abbr)
	
	return import_vouchers(common_values, data, start_idx, rows[0][0])
Пример #6
0
def upload():
    from webnotes.utils.datautils import read_csv_content_from_uploaded_file
    rows = read_csv_content_from_uploaded_file()

    common_values = get_common_values(rows)
    company_abbr = webnotes.conn.get_value("Company", common_values.company,
                                           "abbr")
    data, start_idx = get_data(rows, company_abbr)

    return import_vouchers(common_values, data, start_idx, rows[0][0])
Пример #7
0
def upload():
	messages = []
	try:
		from webnotes.utils.datautils import read_csv_content_from_uploaded_file
		rows = read_csv_content_from_uploaded_file()
	
		common_values = get_common_values(rows)
		company_abbr = webnotes.conn.get_value("Company", common_values.company, "abbr")
		
		if not company_abbr:
			webnotes.msgprint(_("Company is missing or entered incorrect value"), raise_exception=1)
		
		data, start_idx = get_data(rows, company_abbr, rows[0][0])
	except Exception, e:
		err_msg = webnotes.local.message_log and "<br>".join(webnotes.local.message_log) or cstr(e)
		messages.append("""<p style='color: red'>%s</p>""" % (err_msg or "No message"))
		webnotes.errprint(webnotes.getTraceback())
		webnotes.local.message_log = []
		return messages
Пример #8
0
def upload():
	messages = []
	try:
		from webnotes.utils.datautils import read_csv_content_from_uploaded_file
		rows = read_csv_content_from_uploaded_file()
	
		common_values = get_common_values(rows)
		company_abbr = webnotes.conn.get_value("Company", common_values.company, "abbr")
		
		if not company_abbr:
			webnotes.msgprint(_("Company is missing or entered incorrect value"), raise_exception=1)
		
		data, start_idx = get_data(rows, company_abbr, rows[0][0])
	except Exception, e:
		err_msg = webnotes.message_log and "<br>".join(webnotes.message_log) or cstr(e)
		messages.append("""<p style='color: red'>%s</p>""" % (err_msg or "No message"))
		webnotes.errprint(webnotes.getTraceback())
		webnotes.message_log = []
		return messages
Пример #9
0
def upload():
        webnotes.errprint("hello")
        from webnotes.utils.file_manager import get_uploaded_content
        """upload data"""
        global doctype_dl

        #webnotes.mute_emails = True
        from webnotes.utils.datautils import read_csv_content_from_uploaded_file

        # extra input params
        import json
        params = json.loads(webnotes.form_dict.get("params") or '{}')

        # header
        rows = read_csv_content_from_uploaded_file()
        i=0
        for r in rows:
                if i>1:
				#webnotes.errprint(r[2])
				
                                aa=datetime.datetime.strptime(r[2], '%d-%b-%y').date().strftime('%Y-%m-%d')
                                bb=Document('Attendance')
                                bb.employee=r[0]
                                webnotes.errprint(r[0])
                                dd="select employee_name from tabEmployee where name='"+r[0]+"'"
                                #webnotes.errprint(dd)
                                cc=webnotes.conn.sql(dd)
                                bb.employee_name=cc and cc[0][0] or ''
                                #webnotes.errprint(cc)
                                bb.status='Present'
                                bb.att_date=aa
                                bb.company='MedSynaptic'
				bb.fiscal_year='2014-2015'
                                bb.save(new=1)
                                webnotes.conn.commit()
                                #webnotes.errprint(bb)  
                i+=1

        return "Attendace successfully Uploaded..!"
Пример #10
0
def upload():
	"""upload data"""
	global doctype_dl
	
	webnotes.mute_emails = True
	
	from webnotes.utils.datautils import read_csv_content_from_uploaded_file
	
	def bad_template():
		webnotes.msgprint("Please do not change the rows above '%s'" % data_keys.data_separator,
			raise_exception=1)
			
	def check_data_length():
		max_rows = 500
		if not data:
			webnotes.msgprint("No data found", raise_exception=True)
		elif len(data) > max_rows:
			webnotes.msgprint("Please upload only upto %d %ss at a time" % \
				(max_rows, doctype), raise_exception=True)
	
	def get_start_row():
		for i, row in enumerate(rows):
			if row and row[0]==data_keys.data_separator:
				return i+1
		bad_template()
				
	def get_header_row(key):
		for i, row in enumerate(header):
			if row and row[0]==key:
				return row
		return []
		
	# header
	rows = read_csv_content_from_uploaded_file()
	start_row = get_start_row()
	header = rows[:start_row]
	data = rows[start_row:]
	doctype = get_header_row(data_keys.main_table)[1]
	columns = get_header_row(data_keys.columns)[1:]
	parenttype = get_header_row(data_keys.parent_table)
	
	if len(parenttype) > 1:
		parenttype = parenttype[1]
		parentfield = get_parent_field(doctype, parenttype)
		
	# allow limit rows to be uploaded
	check_data_length()
	
	webnotes.conn.begin()
	
	overwrite = webnotes.form_dict.get('overwrite')
	doctype_dl = webnotes.model.doctype.get(doctype)
	
	# delete child rows (if parenttype)
	if parenttype and overwrite:
		delete_child_rows(data, doctype)

	ret = []
	error = False
	for i, row in enumerate(data):
		# bypass empty rows
		if not row: continue
		
		row_idx = (i + 1) + start_row
		
		d = dict(zip(columns, row[1:]))
		d['doctype'] = doctype
				
		try:
			check_record(d, parenttype)
			if parenttype:
				# child doc
				doc = Document(doctype)
				doc.fields.update(d)
				if parenttype:
					doc.parenttype = parenttype
					doc.parentfield = parentfield
				doc.save()
				ret.append('Inserted row for %s at #%s' % (getlink(parenttype,
					doc.parent), unicode(doc.idx)))
			else:
				ret.append(import_doc(d, doctype, overwrite, row_idx))
		except Exception, e:
			error = True
			ret.append('Error for row (#%d) %s : %s' % (row_idx, 
				len(row)>1 and row[1] or "", cstr(e)))
			webnotes.errprint(webnotes.getTraceback())
Пример #11
0
def upload(select_doctype=None, rows=None):
	from webnotes.utils.datautils import read_csv_content_from_uploaded_file
	from webnotes.modules import scrub
	from webnotes.model.rename_doc import rename_doc
	
        sele = webnotes.form_dict.nam1
	sele1= webnotes.form_dict.nam2
	rows = read_csv_content_from_uploaded_file()
	flag1='true'
        fla='true'
        z0=0
        kk=0
        sd1=''
        sd=''
        rr=0
        i1=0
        s=[]
        t=[]
        s1=[]
        t1=[]
        zw=0
	i2=0
	i3=0
	i4=0
      

        if cstr(sele1)=='':
          res=sql("select name from `tabContact List` where name not in('All Contact','All Customer Contact','All Employee (Active)','All Lead (Open)','All Sales Partner Contact','All Sales Person','All Supplier Contact') and name='"+sele+"'")
          res1=res and res[0][0] or ''
          if res1:
            if res1 not in ('All Customer Contact', 'All Supplier Contact', 'All Sales Partner Contact','All Lead (Open)','All Employee (Active)','All Contact','All Sales Person'):
              ss=sql("delete from `tabSub Contact` where parent='"+sele+"'")
	      ss1=sql("delete from `tabContact List` where name='"+sele+"'")
          for r7 in rows:
            s1.append(r7[0])
            t1.append(r7[0])
            i3=i3+1
          lengt1=len(s1)-1
          gg1=s1[lengt1]
         
          for z4 in range(1,lengt1-1):
            if(gg1.lower()==s1[z4].lower()):
              return "Duplicate Subscriber found for "+s[z4]+""

          for z5 in range(1,lengt1):
            sd1=s1[z5]
            for z6 in range(z5+1,len(s1)):
              if(sd1.lower()==t1[z6].lower()):
                return "Duplicate subscriber found for "+s[z5]+""
          sm=Document('Contact List')
          sm.name=sele
          sm.save(new=1)
          for r1 in rows:
            if(i4!=0):
              sms=Document('Sub Contact')
              sms.cont_name=r1[0]
              sms.ph_no=r1[1]
              sms.parent=sele
              sms.save(new=1)
            i4=i4+1
          return ""+cstr(sele)+" is Updated Successfully.!"
        else:
          re1=sql("select name from `tabContact List` where name not in('All Contact','All Customer Contact','All Employee (Active)','All Lead (Open)','All Sales Partner Contact','All Sales Person','All Supplier Contact') and name='"+sele1+"'")
          re2=re1 and re1[0][0] or ''
          if re2:
            return ""+cstr(sele1)+" is Already Exist." 
          for r3 in rows:
            s.append(r3[0])
            t.append(r3[0])
            i1=i1+1
          lengt=len(s)-1
          gg=s[lengt]

          for z2 in range(1,lengt-1):
            if(gg.lower()==s[z2].lower()):
              return "Duplicate Subscriber found for "+s[z2]+""

          for z1 in range(1,lengt):
            sd1=s[z1]
            for z3 in range(z1+1,len(s)):
              if(sd1.lower()==t[z3].lower()):
                return "Duplicate subscriber found for "+s[z1]+""
	  sm1=Document('Contact List')
	  sm1.name=sele1
	  sm1.save(new=1)	
	  for r2 in rows:
	    if(i2!=0):
	      sms1=Document('Sub Contact')
	      sms1.cont_name=r2[0]
	      sms1.ph_no=r2[1]
	      sms1.parent=sele1
	      sms1.save(new=1)    
	    i2=i2+1  
	  return ""+cstr(sele1)+" is created Successfully.!"
Пример #12
0
							doclist.append(d)
				else:
					break
				
			return doclist
		else:
			d = webnotes._dict(zip(columns, rows[start_idx][1:]))
			d['doctype'] = doctype
			return [d]

	def main_doc_empty(row):
		return not (row and ((len(row) > 1 and row[1]) or (len(row) > 2 and row[2])))
		
	# header
	if not rows:
		rows = read_csv_content_from_uploaded_file(ignore_encoding_errors)
	start_row = get_start_row()
	header = rows[:start_row]
	data = rows[start_row:]
	doctype = get_header_row(data_keys.main_table)[1]
	columns = filter_empty_columns(get_header_row(data_keys.columns)[1:])
	doctypes = []
	doctype_parentfield = {}
	column_idx_to_fieldname = {}
	column_idx_to_fieldtype = {}
	
	if submit_after_import and not cint(webnotes.conn.get_value("DocType", 
			doctype, "is_submittable")):
		submit_after_import = False

	parenttype = get_header_row(data_keys.parent_table)
Пример #13
0
def upload():
	from webnotes.utils.datautils import read_csv_content_from_uploaded_file
	return read_csv_content_from_uploaded_file()
Пример #14
0
                else:
                    break

            return doclist
        else:
            d = webnotes._dict(zip(columns, rows[start_idx][1:]))
            d['doctype'] = doctype
            return [d]

    def main_doc_empty(row):
        return not (row and ((len(row) > 1 and row[1]) or
                             (len(row) > 2 and row[2])))

    # header
    if not rows:
        rows = read_csv_content_from_uploaded_file(ignore_encoding_errors)
    start_row = get_start_row()
    header = rows[:start_row]
    data = rows[start_row:]
    doctype = get_header_row(data_keys.main_table)[1]
    columns = filter_empty_columns(get_header_row(data_keys.columns)[1:])
    doctypes = []
    doctype_parentfield = {}
    column_idx_to_fieldname = {}
    column_idx_to_fieldtype = {}

    if submit_after_import and not cint(
            webnotes.conn.get_value("DocType", doctype, "is_submittable")):
        submit_after_import = False

    parenttype = get_header_row(data_keys.parent_table)
Пример #15
0
        else:
            d = webnotes._dict(zip(columns, rows[start_idx][1:]))
            d["doctype"] = doctype
            return [d]

    def main_doc_empty(row):
        return not (row and len(row) > 2 and (row[1] or row[2]))

        # extra input params

    import json

    params = json.loads(webnotes.form_dict.get("params") or "{}")

    # header
    rows = read_csv_content_from_uploaded_file(params.get("ignore_encoding_errors"))
    start_row = get_start_row()
    header = rows[:start_row]
    data = rows[start_row:]
    doctype = get_header_row(data_keys.main_table)[1]
    columns = filter_empty_columns(get_header_row(data_keys.columns)[1:])
    doctypes = []
    doctype_parentfield = {}
    column_idx_to_fieldname = {}
    column_idx_to_fieldtype = {}

    parenttype = get_header_row(data_keys.parent_table)

    if len(parenttype) > 1:
        parenttype = parenttype[1]
        parentfield = get_parent_field(doctype, parenttype)
Пример #16
0
def upload():
	"""upload data"""
	webnotes.mute_emails = True
	
	from webnotes.utils.datautils import read_csv_content_from_uploaded_file
	
	def bad_template():
		webnotes.msgprint("Please do not change the rows above '%s'" % data_keys.data_separator,
			raise_exception=1)
			
	def check_data_length():
		max_rows = 5000
		if not data:
			webnotes.msgprint("No data found", raise_exception=True)
		elif len(data) > max_rows:
			webnotes.msgprint("Please upload only upto %d %ss at a time" % \
				(max_rows, doctype), raise_exception=True)
	
	def get_start_row():
		for i, row in enumerate(rows):
			if row and row[0]==data_keys.data_separator:
				return i+1
		bad_template()
				
	def get_header_row(key):
		for i, row in enumerate(header):
			if row and row[0]==key:
				return row
		return []
		
	def filter_empty_columns(columns):
		empty_cols = filter(lambda x: x in ("", None), columns)
		
		if empty_cols:
			if columns[-1*len(empty_cols):] == empty_cols:
				# filter empty columns if they exist at the end
				columns = columns[:-1*len(empty_cols)]
			else:
				webnotes.msgprint(_("Please make sure that there are no empty columns in the file."),
					raise_exception=1)
		
		return columns
		
	# extra input params
	import json
	params = json.loads(webnotes.form_dict.get("params") or '{}')
	
	# header
	rows = read_csv_content_from_uploaded_file(params.get("ignore_encoding_errors"))
	start_row = get_start_row()
	header = rows[:start_row]
	data = rows[start_row:]
	doctype = get_header_row(data_keys.main_table)[1]
	columns = filter_empty_columns(get_header_row(data_keys.columns)[1:])

	parenttype = get_header_row(data_keys.parent_table)
	
	if len(parenttype) > 1:
		parenttype = parenttype[1]
		parentfield = get_parent_field(doctype, parenttype)
		
	# allow limit rows to be uploaded
	check_data_length()
	
	webnotes.conn.begin()
	
	overwrite = params.get('overwrite')
	doctype_dl = webnotes.model.doctype.get(doctype)
	
	# delete child rows (if parenttype)
	if parenttype and overwrite:
		delete_child_rows(data, doctype)

	ret = []
	error = False
	parent_list = []
	for i, row in enumerate(data):
		# bypass empty rows
		if not row: continue
		
		row_idx = (i + 1) + start_row
		
		d = webnotes._dict(zip(columns, row[1:]))
		d['doctype'] = doctype
		
		try:
			check_record(d, parenttype, doctype_dl)
			if parenttype:
				# child doc
				doc = Document(doctype)
				doc.fields.update(d)
				if parenttype:
					doc.parenttype = parenttype
					doc.parentfield = parentfield
				doc.save()
				ret.append('Inserted row for %s at #%s' % (getlink(parenttype,
					doc.parent), unicode(doc.idx)))
				parent_list.append(doc.parent)
			else:
				ret.append(import_doc(d, doctype, overwrite, row_idx, params.get("_submit")))
		except Exception, e:
			error = True
			err_msg = webnotes.message_log and "<br>".join(webnotes.message_log) or cstr(e)
			ret.append('Error for row (#%d) %s : %s' % (row_idx, 
				len(row)>1 and row[1] or "", err_msg))
			webnotes.errprint(webnotes.getTraceback())
			webnotes.message_log = []
Пример #17
0
            return doclist
        else:
            d = webnotes._dict(zip(columns, rows[start_idx][1:]))
            d['doctype'] = doctype
            return [d]

    def main_doc_empty(row):
        return not (row and len(row) > 2 and (row[1] or row[2]))

    # extra input params
    import json
    params = json.loads(webnotes.form_dict.get("params") or '{}')

    # header
    rows = read_csv_content_from_uploaded_file(
        params.get("ignore_encoding_errors"))
    start_row = get_start_row()
    header = rows[:start_row]
    data = rows[start_row:]
    doctype = get_header_row(data_keys.main_table)[1]
    columns = filter_empty_columns(get_header_row(data_keys.columns)[1:])
    doctypes = []
    doctype_parentfield = {}
    column_idx_to_fieldname = {}
    column_idx_to_fieldtype = {}

    parenttype = get_header_row(data_keys.parent_table)

    if len(parenttype) > 1:
        parenttype = parenttype[1]
        parentfield = get_parent_field(doctype, parenttype)
Пример #18
0
def upload():
    from webnotes.utils.datautils import read_csv_content_from_uploaded_file
    rows = read_csv_content_from_uploaded_file()
    fi = webnotes.form_dict.select_doctype
    msgprint(fi)
Пример #19
0
def upload():
        from webnotes.utils.datautils import read_csv_content_from_uploaded_file
        rows = read_csv_content_from_uploaded_file()
	fi = webnotes.form_dict.select_doctype
	msgprint(fi)
Пример #20
0
def upload(select_doctype=None, rows=None):
    from webnotes.utils.datautils import read_csv_content_from_uploaded_file
    from webnotes.modules import scrub
    from webnotes.model.rename_doc import rename_doc

    sele = webnotes.form_dict.nam1
    sele1 = webnotes.form_dict.nam2
    rows = read_csv_content_from_uploaded_file()
    flag1 = 'true'
    fla = 'true'
    z0 = 0
    kk = 0
    sd1 = ''
    sd = ''
    rr = 0
    i1 = 0
    s = []
    t = []
    s1 = []
    t1 = []
    zw = 0
    i2 = 0
    i3 = 0
    i4 = 0

    if cstr(sele1) == '':
        res = sql(
            "select name from `tabContact List` where name not in('All Contact','All Customer Contact','All Employee (Active)','All Lead (Open)','All Sales Partner Contact','All Sales Person','All Supplier Contact') and name='"
            + sele + "'")
        res1 = res and res[0][0] or ''
        if res1:
            if res1 not in ('All Customer Contact', 'All Supplier Contact',
                            'All Sales Partner Contact', 'All Lead (Open)',
                            'All Employee (Active)', 'All Contact',
                            'All Sales Person'):
                ss = sql("delete from `tabSub Contact` where parent='" + sele +
                         "'")
                ss1 = sql("delete from `tabContact List` where name='" + sele +
                          "'")
        for r7 in rows:
            s1.append(r7[0])
            t1.append(r7[0])
            i3 = i3 + 1
        lengt1 = len(s1) - 1
        gg1 = s1[lengt1]

        for z4 in range(1, lengt1 - 1):
            if (gg1.lower() == s1[z4].lower()):
                webnotes.msgprint("Duplicate subscriber found for " + s[z4] +
                                  "")
                return "Duplicate Subscriber found for " + s[z4] + ""

        for z5 in range(1, lengt1):
            sd1 = s1[z5]
            for z6 in range(z5 + 1, len(s1)):
                if (sd1.lower() == t1[z6].lower()):
                    webnotes.msgprint("Duplicate subscriber found for " +
                                      s[z5] + "")
                    return "Duplicate subscriber found for " + s[z5] + ""
        sm = Document('Contact List')
        sm.name = sele
        sm.save(new=1)
        for r1 in rows:
            if (i4 != 0):
                sms = Document('Sub Contact')
                sms.cont_name = r1[0]
                sms.ph_no = r1[1]
                sms.parent = sele
                sms.save(new=1)
            i4 = i4 + 1
        webnotes.msgprint("" + cstr(sele) + " is Updated Successfully.!")
        return "" + cstr(sele) + " is Updated Successfully.!"
    else:
        re1 = sql(
            "select name from `tabContact List` where name not in('All Contact','All Customer Contact','All Employee (Active)','All Lead (Open)','All Sales Partner Contact','All Sales Person','All Supplier Contact') and name='"
            + sele1 + "'")
        re2 = re1 and re1[0][0] or ''
        if re2:
            webnotes.msgprint("" + cstr(sele1) + " is Already Exist.")
            return "" + cstr(sele1) + " is Already Exist."
        for r3 in rows:
            s.append(r3[0])
            t.append(r3[0])
            i1 = i1 + 1
        lengt = len(s) - 1
        gg = s[lengt]

        for z2 in range(1, lengt - 1):
            if (gg.lower() == s[z2].lower()):
                webnotes.msgprint("Duplicate subscriber found for " + s[z2] +
                                  "")
                return "Duplicate Subscriber found for " + s[z2] + ""

        for z1 in range(1, lengt):
            sd1 = s[z1]
            for z3 in range(z1 + 1, len(s)):
                if (sd1.lower() == t[z3].lower()):
                    webnotes.msgprint("Duplicate subscriber found for " +
                                      s[z1] + "")
                    return "Duplicate subscriber found for " + s[z1] + ""
        sm1 = Document('Contact List')
        sm1.name = sele1
        sm1.save(new=1)
        for r2 in rows:
            if (i2 != 0):
                sms1 = Document('Sub Contact')
                sms1.cont_name = r2[0]
                sms1.ph_no = r2[1]
                sms1.parent = sele1
                sms1.save(new=1)
            i2 = i2 + 1
        webnotes.msgprint("" + cstr(sele1) + " is Uploaded Successfully.!")
        return "Done"
Пример #21
0
def upload(select_doctype=None, rows=None):
    from webnotes.utils.datautils import read_csv_content_from_uploaded_file
    from webnotes.modules import scrub
    from webnotes.model.rename_doc import rename_doc
    sele = webnotes.form_dict.nam
    rows = read_csv_content_from_uploaded_file()
    flag1 = 'true'
    fla = 'true'
    z0 = 0
    kk = 0
    sd1 = ''
    sd = ''
    rr = 0
    i1 = 0
    s = []
    t = []
    zw = 0
    i2 = 0
    res = sql(
        "select name from `tabContact List` where name not in('All Contact','All Customer Contact','All Employee (Active)','All Lead (Open)','All Sales Partner Contact','All Sales Person','All Supplier Contact') and name='"
        + sele + "'")
    res1 = res and res[0][0] or ''
    if res1:
        if res1 not in ('All Customer Contact', 'All Supplier Contact',
                        'All Sales Partner Contact', 'All Lead (Open)',
                        'All Employee (Active)', 'All Contact',
                        'All Sales Person'):
            ss = sql("delete from `tabSub Contact` where parent='" + sele +
                     "'")
            ss1 = sql("delete from `tabContact List` where name='" + sele +
                      "'")
        if res1 in ('All Customer Contact', 'All Supplier Contact',
                    'All Sales Partner Contact', 'All Lead (Open)',
                    'All Employee (Active)', 'All Contact',
                    'All Sales Person'):
            return "Upload permission is allowed only for user created list"
    for r3 in rows:
        s.append(r3[0])
        t.append(r3[0])
        i1 = i1 + 1
    lengt = len(s) - 1
    gg = s[lengt]

    for z2 in range(1, lengt - 1):
        if (gg.lower() == s[z2].lower()):
            return "Duplicate Subscriber found for " + s[z2] + ""

    for z1 in range(1, lengt):
        sd1 = s[z1]
        for z3 in range(z1 + 1, len(s)):
            if (sd1.lower() == t[z3].lower()):
                return "Duplicate subscriber found for " + s[z1] + ""
    sm = Document('Contact List')
    sm.name = sele
    sm.save(new=1)
    for r1 in rows:
        if (i2 != 0):
            sms = Document('Sub Contact')
            sms.cont_name = r1[0]
            sms.adr = r1[1]
            sms.ph_no = r1[2]
            sms.parent = sele
            sms.save(new=1)
        i2 = i2 + 1
    return "Done"
Пример #22
0
def upload():
    """upload data"""
    webnotes.mute_emails = True

    from webnotes.utils.datautils import read_csv_content_from_uploaded_file

    def bad_template():
        webnotes.msgprint("Please do not change the rows above '%s'" %
                          data_keys.data_separator,
                          raise_exception=1)

    def check_data_length():
        max_rows = 5000
        if not data:
            webnotes.msgprint("No data found", raise_exception=True)
        elif len(data) > max_rows:
            webnotes.msgprint("Please upload only upto %d %ss at a time" % \
             (max_rows, doctype), raise_exception=True)

    def get_start_row():
        for i, row in enumerate(rows):
            if row and row[0] == data_keys.data_separator:
                return i + 1
        bad_template()

    def get_header_row(key):
        for i, row in enumerate(header):
            if row and row[0] == key:
                return row
        return []

    def filter_empty_columns(columns):
        empty_cols = filter(lambda x: x in ("", None), columns)

        if empty_cols:
            if columns[-1 * len(empty_cols):] == empty_cols:
                # filter empty columns if they exist at the end
                columns = columns[:-1 * len(empty_cols)]
            else:
                webnotes.msgprint(_(
                    "Please make sure that there are no empty columns in the file."
                ),
                                  raise_exception=1)

        return columns

    # extra input params
    import json
    params = json.loads(webnotes.form_dict.get("params") or '{}')

    # header
    rows = read_csv_content_from_uploaded_file(
        params.get("ignore_encoding_errors"))
    start_row = get_start_row()
    header = rows[:start_row]
    data = rows[start_row:]
    doctype = get_header_row(data_keys.main_table)[1]
    columns = filter_empty_columns(get_header_row(data_keys.columns)[1:])

    parenttype = get_header_row(data_keys.parent_table)

    if len(parenttype) > 1:
        parenttype = parenttype[1]
        parentfield = get_parent_field(doctype, parenttype)

    # allow limit rows to be uploaded
    check_data_length()

    webnotes.conn.begin()

    overwrite = params.get('overwrite')
    doctype_dl = webnotes.model.doctype.get(doctype)

    # delete child rows (if parenttype)
    if parenttype and overwrite:
        delete_child_rows(data, doctype)

    ret = []
    error = False
    parent_list = []
    for i, row in enumerate(data):
        # bypass empty rows
        if not row: continue

        row_idx = (i + 1) + start_row

        d = webnotes._dict(zip(columns, row[1:]))
        d['doctype'] = doctype

        try:
            check_record(d, parenttype, doctype_dl)
            if parenttype:
                # child doc
                doc = Document(doctype)
                doc.fields.update(d)
                if parenttype:
                    doc.parenttype = parenttype
                    doc.parentfield = parentfield
                doc.save()
                ret.append('Inserted row for %s at #%s' %
                           (getlink(parenttype, doc.parent), unicode(doc.idx)))
                parent_list.append(doc.parent)
            else:
                ret.append(
                    import_doc(d, doctype, overwrite, row_idx,
                               params.get("_submit")))
        except Exception, e:
            error = True
            err_msg = webnotes.message_log and "<br>".join(
                webnotes.message_log) or cstr(e)
            ret.append('Error for row (#%d) %s : %s' %
                       (row_idx, len(row) > 1 and row[1] or "", err_msg))
            webnotes.errprint(webnotes.getTraceback())
            webnotes.message_log = []
Пример #23
0
def upload():
	from webnotes.utils.datautils import read_csv_content_from_uploaded_file
	return read_csv_content_from_uploaded_file()
Пример #24
0
def upload():
    """upload data"""
    global doctype_dl
    from webnotes.utils.datautils import read_csv_content_from_uploaded_file

    def bad_template():
        webnotes.msgprint("Please do not change the rows above '%s'" %
                          data_keys.data_separator,
                          raise_exception=1)

    def check_data_length():
        max_rows = 500
        if not data:
            webnotes.msgprint("No data found", raise_exception=True)
        elif len(data) > max_rows:
            webnotes.msgprint("Please upload only upto %d %ss at a time" % \
             (max_rows, doctype), raise_exception=True)

    def get_start_row():
        for i, row in enumerate(rows):
            if row[0] == data_keys.data_separator:
                return i + 1
        bad_template()

    def get_header_row(key):
        for i, row in enumerate(header):
            if row[0] == key:
                return row
        return []

    # header
    rows = read_csv_content_from_uploaded_file()
    start_row = get_start_row()
    header = rows[:start_row]
    data = rows[start_row:]
    doctype = get_header_row(data_keys.main_table)[1]
    columns = get_header_row(data_keys.columns)[1:]
    parenttype = get_header_row(data_keys.parent_table)

    if len(parenttype) > 1:
        parenttype = parenttype[1]
        parentfield = get_parent_field(doctype, parenttype)

    # allow limit rows to be uploaded
    check_data_length()

    webnotes.conn.begin()

    overwrite = webnotes.form_dict.get('overwrite')
    doctype_dl = webnotes.model.doctype.get(doctype)

    # delete child rows (if parenttype)
    if parenttype and overwrite:
        delete_child_rows(data, doctype)

    ret = []
    error = False
    for i, row in enumerate(data):
        # bypass empty rows
        if not row: continue

        row_idx = (i + 1) + start_row

        d = dict(zip(columns, row[1:]))
        d['doctype'] = doctype

        try:
            check_record(d, parenttype)
            if parenttype:
                # child doc
                doc = Document(doctype)
                doc.fields.update(d)
                if parenttype:
                    doc.parenttype = parenttype
                    doc.parentfield = parentfield
                doc.save()
                ret.append('Inserted row for %s at #%s' %
                           (getlink(parenttype, doc.parent), unicode(doc.idx)))
            else:
                ret.append(import_doc(d, doctype, overwrite, row_idx))
        except Exception, e:
            error = True
            ret.append('Error for row (#%d) %s : %s' %
                       (row_idx, len(row) > 1 and row[1] or "", cstr(e)))
            webnotes.errprint(webnotes.getTraceback())