order categories by the translation (bug 620048)

This commit is contained in:
Andy McKay 2010-12-20 16:51:09 -08:00
Родитель 6a51c422f1
Коммит 789ad71788
4 изменённых файлов: 98 добавлений и 6 удалений

Просмотреть файл

@ -18,6 +18,7 @@ from translations.fields import TransField, TransTextarea
from translations.forms import TranslationFormMixin
from translations.models import Translation
from translations.widgets import TranslationTextInput
from translations.query import order_by_translation
from versions.compare import version_int
@ -60,9 +61,9 @@ class AddonFormBasic(AddonFormBase):
# TODO(gkoberger/help from chowse):
# Make it so the categories aren't hardcoded as Firefox only
self.fields['categories'].queryset = Category.objects.filter(
application=1,
type=self.instance.type)
self.fields['categories'].queryset = (order_by_translation(
Category.objects.filter(application=1, type=self.instance.type),
'name'))
def save(self, addon, commit=False):
tags_new = self.cleaned_data['tags']

Просмотреть файл

@ -9,7 +9,7 @@ import amo
class FormsTest(test_utils.TestCase):
fixtures = ('base/addon_3615',)
fixtures = ('base/addon_3615', 'base/addon_3615_categories')
def setUp(self):
self._redis = mock_redis()
@ -52,6 +52,13 @@ class FormsTest(test_utils.TestCase):
form = AddonFormDetails(request={})
eq_(form.fields['default_locale'].choices[0][0], 'af')
def test_category_order(self):
form = forms.AddonFormBasic(dict(name=self.existing_name),
request=None, instance=Addon.objects.get())
names = ['Bookmarks', 'Feeds', 'Social']
categories = form.fields['categories'].queryset
eq_(sorted(names), [str(f.name) for f in categories.all()])
class TestUpdate(test_utils.TestCase):
fixtures = ['base/addon_3615',

Просмотреть файл

@ -0,0 +1,83 @@
[
{
"pk": 22,
"model": "addons.category",
"fields": {
"count": 901,
"description": null,
"weight": 0,
"created": "2007-03-05 13:09:27",
"modified": "2010-02-23 19:17:32",
"application": 1,
"type": 1,
"slug": "bookmarks",
"name": 1
}
},
{
"pk": 24,
"model": "addons.category",
"fields": {
"count": 901,
"description": null,
"weight": 0,
"created": "2007-03-05 13:09:27",
"modified": "2010-02-23 19:17:32",
"application": 1,
"type": 1,
"slug": "social",
"name": 2
}
},
{
"pk": 23,
"model": "addons.category",
"fields": {
"count": 901,
"description": null,
"weight": 0,
"created": "2007-03-05 13:09:27",
"modified": "2010-02-23 19:17:32",
"application": 1,
"type": 1,
"slug": "feeds",
"name": 3
}
},
{
"pk": 700381,
"model": "translations.translation",
"fields": {
"localized_string_clean": null,
"created": "2010-12-20 16:18:56",
"locale": "en-us",
"modified": "2010-12-20 16:18:56",
"id": 1,
"localized_string": "Bookmarks"
}
},
{
"pk": 700382,
"model": "translations.translation",
"fields": {
"localized_string_clean": null,
"created": "2010-12-20 16:18:56",
"locale": "en-us",
"modified": "2010-12-20 16:18:56",
"id": 2,
"localized_string": "Social"
}
},
{
"pk": 700383,
"model": "translations.translation",
"fields": {
"localized_string_clean": null,
"created": "2010-12-20 16:18:56",
"locale": "en-us",
"modified": "2010-12-20 16:18:56",
"id": 3,
"localized_string": "Feeds"
}
}
]

Просмотреть файл

@ -886,7 +886,7 @@ class TestDelete(test_utils.TestCase):
class TestEdit(test_utils.TestCase):
fixtures = ('base/apps', 'base/users', 'base/addon_3615',
'base/addon_5579')
'base/addon_5579', 'base/addon_3615_categories')
def setUp(self):
super(TestEdit, self).setUp()
@ -2220,7 +2220,8 @@ class TestSubmitStep2(test_utils.TestCase):
class TestSubmitStep3(test_utils.TestCase):
fixtures = ['base/addon_3615', 'base/addon_5579', 'base/users']
fixtures = ['base/addon_3615', 'base/addon_3615_categories',
'base/addon_5579', 'base/users']
def setUp(self):
super(TestSubmitStep3, self).setUp()