get collection translation fallbacks properly

This commit is contained in:
Jeff Balogh 2010-03-05 12:34:30 -08:00
Родитель 6f9e2e20f4
Коммит abef502de3
4 изменённых файлов: 80 добавлений и 8 удалений

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

@ -4,7 +4,6 @@ import time
from django.conf import settings
from django.db import models
from django.db.models import Q
from django.utils import translation
import caching.base
@ -217,15 +216,15 @@ class Addon(amo.models.ModelBase):
def reviews_url(self):
return reverse('reviews.list', args=(self.id,))
@classmethod
def get_fallback(cls):
return cls._meta.get_field('default_locale')
@property
def listed_authors(self):
return UserProfile.objects.filter(addons=self,
addonuser__listed=True).order_by('addonuser__position')
@classmethod
def get_fallback(cls):
return cls._meta.get_field('default_locale')
def fetch_translations(self, ids, lang):
return translations_with_fallback(ids, lang, self.default_locale)

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

@ -0,0 +1,50 @@
[
{
"pk": 1,
"model": "applications.application",
"fields": {
"guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
"modified": "2008-11-03 15:34:59",
"created": "2007-03-05 13:09:26"
}
},
{
"pk": 434742,
"model": "translations.translation",
"fields": {
"localized_string_clean": null,
"created": "2009-06-10 07:18:11",
"locale": "ru",
"modified": null,
"id": 395856,
"localized_string": "yay"
}
},
{
"pk": 512,
"model": "bandwagon.collection",
"fields": {
"rating": 0.0,
"downvotes": 0,
"password": "",
"uuid": "f94d08c7-794d-3ce4-4634-99caa09f9ef4",
"created": "2009-06-10 07:18:11",
"monthly_subscribers": 0,
"downloads": 238,
"weekly_subscribers": 0,
"modified": "2009-06-10 07:27:21",
"name": 395856,
"access": 0,
"application": 1,
"collection_type": 0,
"listed": 1,
"subscribers": 1,
"default_locale": "ru",
"upvotes": 0,
"icontype": "",
"nickname": null,
"addon_count": 4,
"description": null
}
}
]

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

@ -7,15 +7,18 @@ import amo.models
from addons.models import Addon, AddonCategory
from applications.models import Application
from users.models import UserProfile
from translations.fields import TranslatedField, LinkifiedField
from translations.fields import (TranslatedField, LinkifiedField,
translations_with_fallback)
class Collection(amo.models.ModelBase):
uuid = models.CharField(max_length=36, blank=True, unique=True)
name = TranslatedField()
nickname = models.CharField(max_length=30, blank=True, unique=True)
nickname = models.CharField(max_length=30, blank=True, unique=True,
null=True)
description = LinkifiedField()
defaultlocale = models.CharField(max_length=10, default='en-US')
default_locale = models.CharField(max_length=10, default='en-US',
db_column='defaultlocale')
collection_type = models.PositiveIntegerField(default=0)
icontype = models.CharField(max_length=25, blank=True)
@ -45,6 +48,13 @@ class Collection(amo.models.ModelBase):
# TODO(jbalogh): reverse
return '/collection/%s' % self.url_slug
def fetch_translations(self, ids, lang):
return translations_with_fallback(ids, lang, self.default_locale)
@classmethod
def get_fallback(cls):
return cls._meta.get_field('default_locale')
@property
def url_slug(self):
"""uuid or nickname if chosen"""

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

@ -0,0 +1,13 @@
from nose.tools import eq_
import test_utils
from bandwagon.models import Collection
class TestCollections(test_utils.TestCase):
fixtures = ['bandwagon/test_models']
def test_translation_default(self):
"""Make sure we're getting strings from the default locale."""
c = Collection.objects.get(pk=512)
eq_(unicode(c.name), 'yay')