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


Python datastructures.OrderedSet類代碼示例

本文整理匯總了Python中django.utils.datastructures.OrderedSet的典型用法代碼示例。如果您正苦於以下問題:Python OrderedSet類的具體用法?Python OrderedSet怎麽用?Python OrderedSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了OrderedSet類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_len

 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)
開發者ID:velis74,項目名稱:django,代碼行數:7,代碼來源:test_datastructures.py

示例2: navigation_event_ids_by_user

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
開發者ID:dimagi,項目名稱:commcare-hq,代碼行數:28,代碼來源:export.py

示例3: merge

    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)
開發者ID:MattBlack85,項目名稱:django,代碼行數:31,代碼來源:widgets.py

示例4: get_parent_list

 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:agmond,項目名稱:django,代碼行數:10,代碼來源:options.py

示例5: fields_for_document

def fields_for_document(document, fields=None, exclude=None, widgets=None,
                        formfield_callback=None,
                        field_generator=MongoFormFieldGenerator):
    """
    Returns a ``OrderedSet`` containing form fields for the given model.

    ``fields`` is an optional list of field names. If provided, only the named
    fields will be included in the returned fields.

    ``exclude`` is an optional list of field names. If provided, the named
    fields will be excluded from the returned fields, even if they are listed
    in the ``fields`` argument.
    """
    field_list = []
    ignored = []
    if isinstance(field_generator, type):
        field_generator = field_generator()

    sorted_fields = sorted(document._fields.values(),
                           key=lambda field: field.creation_counter)

    for f in sorted_fields:
        if isinstance(f, ObjectIdField):
            continue
        if isinstance(f, ListField) and not (f.field.choices or isinstance(f.field, ReferenceField)):
            continue
        if fields is not None and not f.name in fields:
            continue
        if exclude and f.name in exclude:
            continue
        if widgets and f.name in widgets:
            kwargs = {'widget': widgets[f.name]}
        else:
            kwargs = {}

        if formfield_callback is None:
            form_field = field_generator.generate(f, **kwargs)
        elif not callable(formfield_callback):
            raise TypeError('formfield_callback must be a function or callable')
        else:
            form_field = formfield_callback(f, **kwargs)

        if form_field:
            field_list.append((f.name, form_field))
        else:
            ignored.append(f.name)

    field_dict = OrderedSet(field_list)
    if fields:
        field_dict = OrderedSet(
            [(f, field_dict.get(f)) for f in fields
                if ((not exclude) or (exclude and f not in exclude)) and (f not in ignored)]
        )
    return field_dict
開發者ID:ebar0n,項目名稱:django-mongoengine,代碼行數:54,代碼來源:documents.py

示例6: test_bool

 def test_bool(self):
     # Refs #23664
     s = OrderedSet()
     self.assertFalse(s)
     s.add(1)
     self.assertTrue(s)
開發者ID:carlio,項目名稱:django,代碼行數:6,代碼來源:test_datastructures.py


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