當前位置: 首頁>>代碼示例>>Python>>正文


Python datastructures.OrderedSet方法代碼示例

本文整理匯總了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 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:22,代碼來源:runner.py

示例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) 
開發者ID:nshafer,項目名稱:django-hashid-field,代碼行數:26,代碼來源:lookups.py

示例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 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:22,代碼來源:runner.py

示例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)) 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:24,代碼來源:graph.py

示例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. 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:14,代碼來源:graph.py

示例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'] 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:11,代碼來源:graph.py

示例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) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:12,代碼來源:options.py

示例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. 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:15,代碼來源:graph.py

示例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'] 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:12,代碼來源:graph.py

示例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))) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:11,代碼來源:graph.py

示例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) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:12,代碼來源:options.py

示例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) 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:29,代碼來源:lookups.py

示例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) 
開發者ID:GetTogetherComm,項目名稱:GetTogether,代碼行數:37,代碼來源:events.py

示例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 
開發者ID:grupyrn,項目名稱:jararaca,代碼行數:9,代碼來源:views.py

示例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)) 
開發者ID:grupyrn,項目名稱:jararaca,代碼行數:11,代碼來源:views.py


注:本文中的django.utils.datastructures.OrderedSet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。