Exemple #1
0
def sort_fields(doclist):
	"""sort on basis of previous_field"""
	from webnotes.model.doclist import DocList
	newlist = DocList([])
	pending = filter(lambda d: d.doctype=='DocField', doclist)
	
	maxloops = 20
	while (pending and maxloops>0):
		maxloops -= 1
		for d in pending[:]:
			if d.previous_field:
				# field already added
				for n in newlist:
					if n.fieldname==d.previous_field:
						newlist.insert(newlist.index(n)+1, d)
						pending.remove(d)
						break
			else:
				newlist.append(d)
				pending.remove(d)

	# recurring at end	
	if pending:
		newlist += pending

	# renum
	idx = 1
	for d in newlist:
		d.idx = idx
		idx += 1

	doclist.get({"doctype":["!=", "DocField"]}).extend(newlist)
Exemple #2
0
def sort_fields(doclist):
    """sort on basis of previous_field"""
    from webnotes.model.doclist import DocList
    newlist = DocList([])
    pending = filter(lambda d: d.doctype == 'DocField', doclist)

    maxloops = 20
    while (pending and maxloops > 0):
        maxloops -= 1
        for d in pending[:]:
            if d.previous_field:
                # field already added
                for n in newlist:
                    if n.fieldname == d.previous_field:
                        newlist.insert(newlist.index(n) + 1, d)
                        pending.remove(d)
                        break
            else:
                newlist.append(d)
                pending.remove(d)

    # recurring at end
    if pending:
        newlist += pending

    # renum
    idx = 1
    for d in newlist:
        d.idx = idx
        idx += 1

    doclist.get({"doctype": ["!=", "DocField"]}).extend(newlist)
Exemple #3
0
def add_precision(doctype, doclist):
    type_precision_map = {"Currency": 2, "Float": 6}
    for df in doclist.get({
            "doctype": "DocField",
            "fieldtype": ["in", type_precision_map.keys()]
    }):
        df.precision = type_precision_map[df.fieldtype]
Exemple #4
0
def add_search_fields(doclist):
	"""add search fields found in the doctypes indicated by link fields' options"""
	for lf in doclist.get({"fieldtype": "Link", "options":["!=", "[Select]"]}):
		if lf.options:
			search_fields = get(lf.options)[0].search_fields
			if search_fields:
				lf.search_fields = map(lambda sf: sf.strip(), search_fields.split(","))
Exemple #5
0
def add_precision(doctype, doclist):
	type_precision_map = {
		"Currency": 2,
		"Float": 6
	}
	for df in doclist.get({"doctype": "DocField", 
			"fieldtype": ["in", type_precision_map.keys()]}):
		df.precision = type_precision_map[df.fieldtype]
Exemple #6
0
def add_search_fields(doclist):
    """add search fields found in the doctypes indicated by link fields' options"""
    for lf in doclist.get({"fieldtype": "Link"}):
        if lf.options:
            search_fields = get(lf.options)[0].search_fields
            if search_fields:
                lf.search_fields = map(lambda sf: sf.strip(),
                                       search_fields.split(","))
Exemple #7
0
def sort_fields(doclist):
	"""sort on basis of previous_field"""

	from webnotes.model.doclist import DocList
	newlist = DocList([])
	pending = doclist.get({"doctype":"DocField"})

	if doclist[0].get("_idx"):
		for fieldname in json.loads(doclist[0].get("_idx")):
			d = doclist.get({"fieldname": fieldname})
			if d:
				newlist.append(d[0])
				pending.remove(d[0])
	else:
		maxloops = 20
		while (pending and maxloops>0):
			maxloops -= 1
			for d in pending[:]:
				if d.previous_field:
					# field already added
					for n in newlist:
						if n.fieldname==d.previous_field:
							newlist.insert(newlist.index(n)+1, d)
							pending.remove(d)
							break
				else:
					newlist.append(d)
					pending.remove(d)

	# recurring at end	
	if pending:
		newlist += pending

	# renum
	idx = 1
	for d in newlist:
		d.idx = idx
		idx += 1

	doclist.get({"doctype":["!=", "DocField"]}).extend(newlist)
Exemple #8
0
def add_workflows(doclist):
	from webnotes.model.workflow import get_workflow_name
	doctype = doclist[0].name
	
	# get active workflow
	workflow_name = get_workflow_name(doctype)

	if workflow_name and webnotes.conn.exists("Workflow", workflow_name):
		doclist += webnotes.get_doclist("Workflow", workflow_name)
		
		# add workflow states (for icons and style)
		for state in map(lambda d: d.state, doclist.get({"doctype":"Workflow Document State"})):
			doclist += webnotes.get_doclist("Workflow State", state)
Exemple #9
0
def add_workflows(doclist):
    from webnotes.model.workflow import get_workflow_name
    doctype = doclist[0].name

    # get active workflow
    workflow_name = get_workflow_name(doctype)

    if workflow_name and webnotes.conn.exists("Workflow", workflow_name):
        doclist += webnotes.get_doclist("Workflow", workflow_name)

        # add workflow states (for icons and style)
        for state in map(lambda d: d.state,
                         doclist.get({"doctype": "Workflow Document State"})):
            doclist += webnotes.get_doclist("Workflow State", state)