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


Python query.order_by_translation函数代码示例

本文整理汇总了Python中mkt.translations.query.order_by_translation函数的典型用法代码示例。如果您正苦于以下问题:Python order_by_translation函数的具体用法?Python order_by_translation怎么用?Python order_by_translation使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_sorting_mixed

    def test_sorting_mixed(self):
        translation.activate('de')
        q = TranslatedModel.objects.all()
        expected = [1, 4, 3]

        eq_(ids(order_by_translation(q, 'name')), expected)
        eq_(ids(order_by_translation(q, '-name')), list(reversed(expected)))
开发者ID:rachelhathaway,项目名称:zamboni,代码行数:7,代码来源:test_models.py

示例2: test_sorting_by_field

    def test_sorting_by_field(self):
        field = TranslatedModel._meta.get_field('default_locale')
        TranslatedModel.get_fallback = classmethod(lambda cls: field)

        translation.activate('de')
        q = TranslatedModel.objects.all()
        expected = [3, 1, 4]

        eq_(ids(order_by_translation(q, 'name')), expected)
        eq_(ids(order_by_translation(q, '-name')), list(reversed(expected)))

        del TranslatedModel.get_fallback
开发者ID:rachelhathaway,项目名称:zamboni,代码行数:12,代码来源:test_models.py

示例3: test_sorting_by_field

    def test_sorting_by_field(self):
        field = self.TranslatedModel._meta.get_field('default_locale')
        fallback = classmethod(lambda cls: field)
        with patch.object(self.TranslatedModel, 'get_fallback',
                          fallback, create=True):
            translation.activate('de')
            qs = self.TranslatedModel.objects.all()
            expected = [3, 1, 4]

            eq_(ids(order_by_translation(qs, 'name')), expected)
            eq_(ids(order_by_translation(qs, '-name')),
                list(reversed(expected)))
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:12,代码来源:test_models.py

示例4: _do_sort_queue_obj

    def _do_sort_queue_obj(self, qs, date_sort):
        """
        Column sorting logic based on request GET parameters.
        Deals with objects with joins on the Addon (e.g. RereviewQueue,
        Version). Returns qs of apps.
        """
        sort_type, order = clean_sort_param(self.request, date_sort=date_sort)
        sort_str = sort_type

        if sort_type not in [date_sort, 'name']:
            sort_str = 'addon__' + sort_type

        # sort_str includes possible joins when ordering.
        # sort_type is the name of the field to sort on without desc/asc
        # markers. order_by is the name of the field to sort on with desc/asc
        # markers.
        order_by = ('-' if order == 'desc' else '') + sort_str

        # Sort.
        if sort_type == 'name':
            # Sorting by name translation through an addon foreign key.
            return order_by_translation(
                Webapp.objects.filter(
                    id__in=qs.values_list('addon', flat=True)), order_by)

        # Convert sorted queue object queryset to sorted app queryset.
        sorted_app_ids = (qs.order_by('-addon__priority_review', order_by)
                            .values_list('addon', flat=True))
        qs = Webapp.objects.filter(id__in=sorted_app_ids)
        return manual_order(qs, sorted_app_ids, 'addons.id')
开发者ID:Jobava,项目名称:zamboni,代码行数:30,代码来源:utils.py

示例5: test_order_by_translations_query_uses_left_outer_join

 def test_order_by_translations_query_uses_left_outer_join(self):
     translation.activate('de')
     qs = self.TranslatedModel.objects.all()
     query = unicode(order_by_translation(qs, 'name').query)
     # There should be 2 LEFT OUTER JOIN to find translations matching
     # current language and fallback.
     joins = re.findall('LEFT OUTER JOIN `translations`', query)
     eq_(len(joins), 2)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:8,代码来源:test_models.py

示例6: addon_listing

def addon_listing(request):
    """Set up the queryset and filtering for addon listing for Dashboard."""
    qs = request.user.addons.all()
    sorting = 'name'
    if request.GET.get('sort') == 'created':
        sorting = 'created'
        qs = qs.order_by('-created')
    else:
        qs = order_by_translation(qs, 'name')
    return qs, sorting
开发者ID:kumar303,项目名称:zamboni,代码行数:10,代码来源:views.py

示例7: filter

 def filter(self, field):
     qs = self.base_queryset
     if field == 'purchased':
         # Id's are in created order, so let's invert them for this query.
         # According to my testing we don't actually need to dedupe this.
         ids = list(reversed(self.ids[0])) + self.ids[1]
         return manual_order(qs.filter(id__in=ids), ids)
     elif field == 'price':
         return (qs.filter(id__in=self.uids)
                   .order_by('addonpremium__price__price', 'id'))
     elif field == 'name':
         return order_by_translation(qs.filter(id__in=self.uids), 'name')
开发者ID:miltonpereira,项目名称:zamboni,代码行数:12,代码来源:utils.py

示例8: _do_sort_webapp

    def _do_sort_webapp(self, qs, date_sort):
        """
        Column sorting logic based on request GET parameters.
        """
        sort_type, order = clean_sort_param(self.request, date_sort=date_sort)
        order_by = ('-' if order == 'desc' else '') + sort_type

        # Sort.
        if sort_type == 'name':
            # Sorting by name translation.
            return order_by_translation(qs, order_by)

        else:
            return qs.order_by('-priority_review', order_by)
开发者ID:Jobava,项目名称:zamboni,代码行数:14,代码来源:utils.py

示例9: _do_sort_webapp

    def _do_sort_webapp(self, qs, date_sort):
        """
        Column sorting logic based on request GET parameters.
        """
        sort_type, order = clean_sort_param(self.request, date_sort=date_sort)
        order_by = ("-" if order == "desc" else "") + sort_type

        # Sort.
        if sort_type == "name":
            # Sorting by name translation.
            return order_by_translation(qs, order_by)

        else:
            return qs.order_by("-priority_review", order_by)
开发者ID:TwinkleChawla,项目名称:zamboni,代码行数:14,代码来源:utils.py

示例10: _do_sort_webapp

def _do_sort_webapp(request, qs, date_sort):
    """
    Column sorting logic based on request GET parameters.
    """
    sort_type, order = clean_sort_param(request, date_sort=date_sort)
    order_by = ('-' if order == 'desc' else '') + sort_type

    # Sort.
    if sort_type == 'name':
        # Sorting by name translation.
        return order_by_translation(qs, order_by)

    elif sort_type == 'num_abuse_reports':
        return (qs.annotate(num_abuse_reports=Count('abuse_reports'))
                .order_by(order_by))

    else:
        return qs.order_by('-priority_review', order_by)
开发者ID:petercpg,项目名称:zamboni,代码行数:18,代码来源:views.py

示例11: filter_name

 def filter_name(self):
     return order_by_translation(self.model.objects.all(), 'name')
开发者ID:andymckay,项目名称:zamboni,代码行数:2,代码来源:views.py

示例12: test_sorting_en

    def test_sorting_en(self):
        q = TranslatedModel.objects.all()
        expected = [4, 1, 3]

        eq_(ids(order_by_translation(q, 'name')), expected)
        eq_(ids(order_by_translation(q, '-name')), list(reversed(expected)))
开发者ID:rachelhathaway,项目名称:zamboni,代码行数:6,代码来源:test_models.py

示例13: my_apps

 def my_apps(self, n=8):
     """Returns n apps"""
     return order_by_translation(self.webapps.all(), 'name')[:n]
开发者ID:shahbaz17,项目名称:zamboni,代码行数:3,代码来源:models.py

示例14: my_apps

 def my_apps(self, n=8):
     """Returns n apps"""
     return order_by_translation(self.addons.all(), "name")[:n]
开发者ID:ujdhesa,项目名称:zamboni,代码行数:3,代码来源:models.py

示例15: my_apps

 def my_apps(self, n=8):
     """Returns n apps"""
     qs = self.addons.filter(type=amo.ADDON_WEBAPP)
     qs = order_by_translation(qs, 'name')
     return qs[:n]
开发者ID:MorrisJobke,项目名称:zamboni,代码行数:5,代码来源:models.py


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