예제 #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)
예제 #2
0
파일: doc.py 프로젝트: appost/wnframework
def getchildren(name, childtype, field='', parenttype='', from_doctype=0, prefix='tab'):
	import webnotes
	from webnotes.model.doclist import DocList
	
	condition = ""
	values = []
	
	if field: 
		condition += ' and parentfield=%s '
		values.append(field)
	if parenttype:
		condition += ' and parenttype=%s '
		values.append(parenttype)

	dataset = webnotes.conn.sql("""select * from `%s%s` where parent=%s %s order by idx""" \
		% (prefix, childtype, "%s", condition), tuple([name]+values))
	desc = webnotes.conn.get_description()

	l = DocList()
	
	for i in dataset:
		d = Document()
		d.doctype = childtype
		d._load_values(i, desc)
		l.append(d)
	
	return l
예제 #3
0
def getchildren(name,
                childtype,
                field='',
                parenttype='',
                from_doctype=0,
                prefix='tab'):
    import webnotes
    from webnotes.model.doclist import DocList

    condition = ""
    values = []

    if field:
        condition += ' and parentfield=%s '
        values.append(field)
    if parenttype:
        condition += ' and parenttype=%s '
        values.append(parenttype)

    dataset = webnotes.conn.sql("""select * from `%s%s` where parent=%s %s order by idx""" \
     % (prefix, childtype, "%s", condition), tuple([name]+values))
    desc = webnotes.conn.get_description()

    l = DocList()

    for i in dataset:
        d = Document()
        d.doctype = childtype
        d._load_values(i, desc)
        l.append(d)

    return l
예제 #4
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)
예제 #5
0
def getchildren(name,
                childtype,
                field='',
                parenttype='',
                from_doctype=0,
                prefix='tab'):
    import webnotes
    from webnotes.model.doclist import DocList

    tmp = ''

    if field:
        tmp = ' and parentfield="%s" ' % field
    if parenttype:
        tmp = ' and parenttype="%s" ' % parenttype

    dataset = webnotes.conn.sql("select * from `%s%s` where parent='%s' %s order by idx" \
     % (prefix, childtype, name, tmp))
    desc = webnotes.conn.get_description()

    l = DocList()

    for i in dataset:
        d = Document()
        d.doctype = childtype
        d._load_values(i, desc)
        l.append(d)

    return l
예제 #6
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)
예제 #7
0
def getchildren(name, childtype, field='', parenttype='', from_doctype=0, prefix='tab'):
	import webnotes
	from webnotes.model.doclist import DocList
	
	tmp = ''
	
	if field: 
		tmp = ' and parentfield="%s" ' % field
	if parenttype:
		tmp = ' and parenttype="%s" ' % parenttype

	dataset = webnotes.conn.sql("select * from `%s%s` where parent='%s' %s order by idx" \
		% (prefix, childtype, name, tmp))
	desc = webnotes.conn.get_description()

	l = DocList()
	
	for i in dataset:
		d = Document()
		d.doctype = childtype
		d._load_values(i, desc)
		l.append(d)
	
	return l