本文整理汇总了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)))
示例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
示例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)))
示例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')
示例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)
示例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
示例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')
示例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)
示例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)
示例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)
示例11: filter_name
def filter_name(self):
return order_by_translation(self.model.objects.all(), 'name')
示例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)))
示例13: my_apps
def my_apps(self, n=8):
"""Returns n apps"""
return order_by_translation(self.webapps.all(), 'name')[:n]
示例14: my_apps
def my_apps(self, n=8):
"""Returns n apps"""
return order_by_translation(self.addons.all(), "name")[:n]
示例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]