本文整理汇总了Python中django.utils.datastructures.OrderedSet.add方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedSet.add方法的具体用法?Python OrderedSet.add怎么用?Python OrderedSet.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.datastructures.OrderedSet
的用法示例。
在下文中一共展示了OrderedSet.add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: navigation_event_ids_by_user
# 需要导入模块: from django.utils.datastructures import OrderedSet [as 别名]
# 或者: from django.utils.datastructures.OrderedSet import add [as 别名]
def navigation_event_ids_by_user(user, start_date=None, end_date=None):
database = NavigationEventAudit.get_db()
def _date_key(date):
return [date.year, date.month, date.day]
startkey = [user]
if start_date:
startkey.extend(_date_key(start_date))
endkey = [user]
if end_date:
end = end_date + timedelta(days=1)
endkey.extend(_date_key(end))
else:
endkey.append({})
ids = OrderedSet()
results = database.view(
'auditcare/urlpath_by_user_date',
startkey=startkey,
endkey=endkey,
reduce=False,
include_docs=False,
)
for row in results:
ids.add(row['id'])
return ids
示例2: test_len
# 需要导入模块: from django.utils.datastructures import OrderedSet [as 别名]
# 或者: from django.utils.datastructures.OrderedSet import add [as 别名]
def test_len(self):
s = OrderedSet()
self.assertEqual(len(s), 0)
s.add(1)
s.add(2)
s.add(2)
self.assertEqual(len(s), 2)
示例3: merge
# 需要导入模块: from django.utils.datastructures import OrderedSet [as 别名]
# 或者: from django.utils.datastructures.OrderedSet import add [as 别名]
def merge(*lists):
"""
Merge lists while trying to keep the relative order of the elements.
Warn if the lists have the same elements in a different relative order.
For static assets it can be important to have them included in the DOM
in a certain order. In JavaScript you may not be able to reference a
global or in CSS you might want to override a style.
"""
dependency_graph = defaultdict(set)
all_items = OrderedSet()
for list_ in filter(None, lists):
head = list_[0]
# The first items depend on nothing but have to be part of the
# dependency graph to be included in the result.
dependency_graph.setdefault(head, set())
for item in list_:
all_items.add(item)
# No self dependencies
if head != item:
dependency_graph[item].add(head)
head = item
try:
return stable_topological_sort(all_items, dependency_graph)
except CyclicDependencyError:
warnings.warn(
'Detected duplicate Media files in an opposite order: {}'.format(
', '.join(repr(l) for l in lists)
), MediaOrderConflictWarning,
)
return list(all_items)
示例4: get_parent_list
# 需要导入模块: from django.utils.datastructures import OrderedSet [as 别名]
# 或者: from django.utils.datastructures.OrderedSet import add [as 别名]
def get_parent_list(self):
"""
Return all the ancestors of this model as a list ordered by MRO.
Useful for determining if something is an ancestor, regardless of lineage.
"""
result = OrderedSet(self.parents)
for parent in self.parents:
for ancestor in parent._meta.get_parent_list():
result.add(ancestor)
return list(result)
示例5: test_bool
# 需要导入模块: from django.utils.datastructures import OrderedSet [as 别名]
# 或者: from django.utils.datastructures.OrderedSet import add [as 别名]
def test_bool(self):
# Refs #23664
s = OrderedSet()
self.assertFalse(s)
s.add(1)
self.assertTrue(s)