本文整理汇总了Python中django.utils.datastructures.OrderedSet方法的典型用法代码示例。如果您正苦于以下问题:Python datastructures.OrderedSet方法的具体用法?Python datastructures.OrderedSet怎么用?Python datastructures.OrderedSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.datastructures
的用法示例。
在下文中一共展示了datastructures.OrderedSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reorder_suite
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def reorder_suite(suite, classes, reverse=False):
"""
Reorders a test suite by test type.
`classes` is a sequence of types
All tests of type classes[0] are placed first, then tests of type
classes[1], etc. Tests with no match in classes are placed last.
If `reverse` is True, tests within classes are sorted in opposite order,
but test classes are not reversed.
"""
class_count = len(classes)
suite_class = type(suite)
bins = [OrderedSet() for i in range(class_count + 1)]
partition_suite(suite, classes, bins, reverse=reverse)
reordered_suite = suite_class()
for i in range(class_count + 1):
reordered_suite.addTests(bins[i])
return reordered_suite
示例2: process_rhs
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def process_rhs(self, compiler, connection):
db_rhs = getattr(self.rhs, '_db', None)
if db_rhs is not None and db_rhs != connection.alias:
raise ValueError(
"Subqueries aren't allowed across different databases. Force "
"the inner query to be evaluated using `list(inner_query)`."
)
if self.rhs_is_direct_value():
try:
rhs = OrderedSet(self.rhs)
except TypeError: # Unhashable items in self.rhs
rhs = self.rhs
if not rhs:
raise EmptyResultSet
# rhs should be an iterable; use batch_process_rhs() to
# prepare/transform those values.
sqls, sqls_params = self.batch_process_rhs(compiler, connection, rhs)
placeholder = '(' + ', '.join(sqls) + ')'
return (placeholder, sqls_params)
else:
return super().process_rhs(compiler, connection)
示例3: reorder_suite
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def reorder_suite(suite, classes, reverse=False):
"""
Reorder a test suite by test type.
`classes` is a sequence of types
All tests of type classes[0] are placed first, then tests of type
classes[1], etc. Tests with no match in classes are placed last.
If `reverse` is True, sort tests within classes in opposite order but
don't reverse test classes.
"""
class_count = len(classes)
suite_class = type(suite)
bins = [OrderedSet() for i in range(class_count + 1)]
partition_suite_by_type(suite, classes, bins, reverse=reverse)
reordered_suite = suite_class()
for i in range(class_count + 1):
reordered_suite.addTests(bins[i])
return reordered_suite
示例4: iterative_dfs
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def iterative_dfs(self, start, forwards=True):
"""
Iterative depth first search, for finding dependencies.
"""
visited = deque()
visited.append(start)
if forwards:
stack = deque(sorted(start.parents))
else:
stack = deque(sorted(start.children))
while stack:
node = stack.popleft()
visited.appendleft(node)
if forwards:
children = sorted(node.parents, reverse=True)
else:
children = sorted(node.children, reverse=True)
# reverse sorting is needed because prepending using deque.extendleft
# also effectively reverses values
stack.extendleft(children)
return list(OrderedSet(visited))
示例5: ancestors
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def ancestors(self):
# Use self.key instead of self to speed up the frequent hashing
# when constructing an OrderedSet.
if '_ancestors' not in self.__dict__:
ancestors = deque([self.key])
for parent in sorted(self.parents):
ancestors.extendleft(reversed(parent.ancestors()))
self.__dict__['_ancestors'] = list(OrderedSet(ancestors))
return self.__dict__['_ancestors']
# Use manual caching, @cached_property effectively doubles the
# recursion depth for each recursion.
示例6: descendants
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def descendants(self):
# Use self.key instead of self to speed up the frequent hashing
# when constructing an OrderedSet.
if '_descendants' not in self.__dict__:
descendants = deque([self.key])
for child in sorted(self.children):
descendants.extendleft(reversed(child.descendants()))
self.__dict__['_descendants'] = list(OrderedSet(descendants))
return self.__dict__['_descendants']
示例7: get_parent_list
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def get_parent_list(self):
"""
Returns 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)
示例8: ancestors
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def ancestors(self):
# Use self.key instead of self to speed up the frequent hashing
# when constructing an OrderedSet.
if '_ancestors' not in self.__dict__:
ancestors = []
for parent in sorted(self.parents, reverse=True):
ancestors += parent.ancestors()
ancestors.append(self.key)
self.__dict__['_ancestors'] = list(OrderedSet(ancestors))
return self.__dict__['_ancestors']
# Use manual caching, @cached_property effectively doubles the
# recursion depth for each recursion.
示例9: descendants
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def descendants(self):
# Use self.key instead of self to speed up the frequent hashing
# when constructing an OrderedSet.
if '_descendants' not in self.__dict__:
descendants = []
for child in sorted(self.children, reverse=True):
descendants += child.descendants()
descendants.append(self.key)
self.__dict__['_descendants'] = list(OrderedSet(descendants))
return self.__dict__['_descendants']
示例10: iterative_dfs
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def iterative_dfs(self, start, forwards=True):
"""Iterative depth-first search for finding dependencies."""
visited = []
stack = [start]
while stack:
node = stack.pop()
visited.append(node)
stack += sorted(node.parents if forwards else node.children)
return list(OrderedSet(reversed(visited)))
示例11: get_parent_list
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [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)
示例12: process_rhs
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def process_rhs(self, compiler, connection):
db_rhs = getattr(self.rhs, '_db', None)
if db_rhs is not None and db_rhs != connection.alias:
raise ValueError(
"Subqueries aren't allowed across different databases. Force "
"the inner query to be evaluated using `list(inner_query)`."
)
if self.rhs_is_direct_value():
try:
rhs = OrderedSet(self.rhs)
except TypeError: # Unhashable items in self.rhs
rhs = self.rhs
if not rhs:
raise EmptyResultSet
# rhs should be an iterable; use batch_process_rhs() to
# prepare/transform those values.
sqls, sqls_params = self.batch_process_rhs(compiler, connection, rhs)
placeholder = '(' + ', '.join(sqls) + ')'
return (placeholder, sqls_params)
else:
if not getattr(self.rhs, 'has_select_fields', True):
self.rhs.clear_select_clause()
self.rhs.add_fields(['pk'])
return super().process_rhs(compiler, connection)
示例13: manage_event_sponsors
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def manage_event_sponsors(request, event_id):
event = get_object_or_404(Event, id=event_id)
if not request.user.profile.can_edit_event(event):
messages.add_message(
request,
messages.WARNING,
message=_("You can not manage this event's sponsorss."),
)
return redirect(event.get_absolute_url())
team_sponsors = list(event.team.sponsors.all())
events_sponsors = list(Sponsor.objects.filter(events__team=event.team))
if request.method == "POST":
sponsor_form = SponsorForm(request.POST, request.FILES)
if sponsor_form.is_valid():
new_sponsor = sponsor_form.save()
event.sponsors.add(new_sponsor)
event.team.sponsors.add(new_sponsor)
messages.add_message(
request,
messages.SUCCESS,
message=_("Your sponsor has been added to this event."),
)
return redirect("manage-event-sponsors", event.id)
else:
sponsor_form = SponsorForm()
context = {
"event": event,
"sponsors": OrderedSet(events_sponsors + team_sponsors),
"sponsor_form": sponsor_form,
"can_edit_event": request.user.profile.can_edit_event(event),
}
return render(request, "get_together/events/manage_event_sponsors.html", context)
示例14: get_context_data
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['future_events'] = OrderedSet(Event.objects.filter(eventday__date__gte=date.today()).order_by(
'eventday__date'))
context['past_events'] = OrderedSet(Event.objects.filter(eventday__date__lte=date.today()).order_by(
'-eventday__date'))
return context
示例15: get
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import OrderedSet [as 别名]
def get(self, request, *args, **kwargs):
event = OrderedSet(Event.objects.filter(slug=kwargs['event'], eventday__date__gte=date.today(),
closed_registration=False))
if not len(event):
raise Http404
event = list(event)[0]
return self.render_to_response(self.get_context_data(event=event))