当前位置: 首页>>代码示例>>Python>>正文


Python DocList.insert方法代码示例

本文整理汇总了Python中webnotes.model.doclist.DocList.insert方法的典型用法代码示例。如果您正苦于以下问题:Python DocList.insert方法的具体用法?Python DocList.insert怎么用?Python DocList.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webnotes.model.doclist.DocList的用法示例。


在下文中一共展示了DocList.insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sort_fields

# 需要导入模块: from webnotes.model.doclist import DocList [as 别名]
# 或者: from webnotes.model.doclist.DocList import insert [as 别名]
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)
开发者ID:ricardomomm,项目名称:wnframework,代码行数:34,代码来源:doctype.py

示例2: sort_fields

# 需要导入模块: from webnotes.model.doclist import DocList [as 别名]
# 或者: from webnotes.model.doclist.DocList import insert [as 别名]
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)
开发者ID:bindscha,项目名称:wnframework_old,代码行数:42,代码来源:doctype.py


注:本文中的webnotes.model.doclist.DocList.insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。