<commit_before>from __future__ import unicode_literals

import csv, cStringIO
import webnotes
import webnotes
import webnotes.model.doc
import webnotes.model.doctype
from webnotes.model.doc import Document
from webnotes.utils import encode
from webnotes.utils import cstr

data_keys = webnotes.DictObj({
	"data_separator": '----Start entering data below this line----',
	"main_table": "Table:",
	"parent_table": "Parent Table:",
	"columns": "Column Name:"
})

doctype_dl = None

@webnotes.whitelist()
def get_doctypes():
    return [r[0] for r in webnotes.conn.sql("""select name from `tabDocType` 
		where document_type = 'Master'""")]	
		
@webnotes.whitelist()
def get_doctype_options():
	doctype = webnotes.form_dict['doctype']
	return [doctype] + filter(None, map(lambda d: \
		d.doctype=='DocField' and d.fieldtype=='Table' and d.options or None, 
		webnotes.model.doctype.get(doctype, form=0)))

@webnotes.whitelist(allow_roles=['System Manager', 'Administrator'])
def get_template():
	global doctype_dl

	doctype = webnotes.form_dict['doctype']
	parenttype = webnotes.form_dict.get('parent_doctype')
	
	doctype_dl = webnotes.model.doctype.get(doctype)
	tablecolumns = [f[0] for f in webnotes.conn.sql('desc `tab%s`' % doctype)]
	
	def getinforow(docfield):
		"""make info comment"""
		if docfield.fieldtype == 'Select':
			if not docfield.options:
				return ''
			elif docfield.options.startswith('link:'):
				return 'Valid %s' % docfield.options[5:]
			else:
				return 'One of: %s' % ', '.join(filter(None, docfield.options.split('\n')))
		if docfield.fieldtype == 'Link':
			return 'Valid %s' % docfield.options
		if docfield.fieldtype in ('Int'):
			return 'Integer'
		else:
			return ''
			
	w = UnicodeWriter()
	key = 'name'

	w.writerow(['Data Import Template'])	
	w.writerow([data_keys.main_table, doctype])
	
	if parenttype != doctype:
		w.writerow([data_keys.parent_table, parenttype])
		key = 'parent'
	else:
		w.writerow([''])
	
	w.writerow(['----'])
	w.writerow(['Notes:'])
	w.writerow(['- Please do not change the template headings.'])
	w.writerow(['- First data column must be blank.'])
	w.writerow(['- Only mandatory fields are necessary for new records. You can delete non-mandatory columns if you wish.'])
	w.writerow(['- For updating, you can update only selective columns.'])
	w.writerow(['- If you are uploading new records, leave the "name" (ID) column blank.'])
	w.writerow(['- If you are uploading new records, "Naming Series" becomes mandatory, if present.'])
	w.writerow(['- You can only upload 500 records in one go.'])
	if key == "parent":
		w.writerow(['- "Parent" signifies the parent table in which this row must be added'])
		w.writerow(['- If you are updating, please select "Overwrite" else existing rows will not be deleted.'])
	w.writerow(['----'])
	labelrow = ["Column Labels", "ID"]
	fieldrow = [data_keys.columns, key]<commit_msg>replaced - in -- in Notes section of import template<commit_after>from __future__ import unicode_literals

import csv, cStringIO
import webnotes
import webnotes
import webnotes.model.doc
import webnotes.model.doctype
from webnotes.model.doc import Document
from webnotes.utils import encode
from webnotes.utils import cstr

data_keys = webnotes.DictObj({
	"data_separator": '----Start entering data below this line----',
	"main_table": "Table:",
	"parent_table": "Parent Table:",
	"columns": "Column Name:"
})

doctype_dl = None

@webnotes.whitelist()
def get_doctypes():
    return [r[0] for r in webnotes.conn.sql("""select name from `tabDocType` 
		where document_type = 'Master'""")]	
		
@webnotes.whitelist()
def get_doctype_options():
	doctype = webnotes.form_dict['doctype']
	return [doctype] + filter(None, map(lambda d: \
		d.doctype=='DocField' and d.fieldtype=='Table' and d.options or None, 
		webnotes.model.doctype.get(doctype, form=0)))

@webnotes.whitelist(allow_roles=['System Manager', 'Administrator'])
def get_template():
	global doctype_dl

	doctype = webnotes.form_dict['doctype']
	parenttype = webnotes.form_dict.get('parent_doctype')
	
	doctype_dl = webnotes.model.doctype.get(doctype)
	tablecolumns = [f[0] for f in webnotes.conn.sql('desc `tab%s`' % doctype)]
	
	def getinforow(docfield):
		"""make info comment"""
		if docfield.fieldtype == 'Select':
			if not docfield.options:
				return ''
			elif docfield.options.startswith('link:'):
				return 'Valid %s' % docfield.options[5:]
			else:
				return 'One of: %s' % ', '.join(filter(None, docfield.options.split('\n')))
		if docfield.fieldtype == 'Link':
			return 'Valid %s' % docfield.options
		if docfield.fieldtype in ('Int'):
			return 'Integer'
		else:
			return ''
			
	w = UnicodeWriter()
	key = 'name'

	w.writerow(['Data Import Template'])	
	w.writerow([data_keys.main_table, doctype])
	
	if parenttype != doctype:
		w.writerow([data_keys.parent_table, parenttype])
		key = 'parent'
	else:
		w.writerow([''])
	
	w.writerow(['----'])
	w.writerow(['Notes:'])
	w.writerow(['-- Please do not change the template headings.'])
	w.writerow(['-- First data column must be blank.'])
	w.writerow(['-- Only mandatory fields are necessary for new records. You can delete non-mandatory columns if you wish.'])
	w.writerow(['-- For updating, you can update only selective columns.'])
	w.writerow(['-- If you are uploading new records, leave the "name" (ID) column blank.'])
	w.writerow(['-- If you are uploading new records, "Naming Series" becomes mandatory, if present.'])
	w.writerow(['-- You can only upload 500 records in one go.'])
	if key == "parent":
		w.writerow(['-- "Parent" signifies the parent table in which this row must be added'])
		w.writerow(['-- If you are updating, please select "Overwrite" else existing rows will not be deleted.'])
	w.writerow(['----'])
	labelrow = ["Column Labels", "ID"]
	fieldrow = [data_keys.columns, key]
{'fraction_non_alphanumeric': 0.1519641626464507, 'fraction_numerical': 0.002412129565816678, 'mean_word_length': 4.507590132827325, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '125650', 'n_tokens_mistral': 2063, 'n_tokens_neox': 1895, 'n_words': 560}