adding an amo compatiblity model and translation helpers
This commit is contained in:
Родитель
4af097c67e
Коммит
74808c425d
|
@ -1,3 +1,5 @@
|
|||
"""
|
||||
Miscellaneous helpers that make Django compatible with AMO.
|
||||
"""
|
||||
|
||||
from .models import LegacyModel, TranslatedField
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class LegacyModel(models.Model):
|
||||
"""Adds automatic created and modified fields to the model."""
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class TranslatedField(models.IntegerField):
|
||||
__metaclass__ = models.SubfieldBase
|
||||
|
||||
def to_python(self, value):
|
||||
locale = 'en-US'
|
||||
q = Translation.objects.filter(id=value, locale=locale)
|
||||
v = q.values_list('localized_string', flat=True)
|
||||
return v[0] if v else value
|
||||
|
||||
|
||||
# Putting Translation in here since TranslatedField depends on it.
|
||||
class Translation(LegacyModel):
|
||||
|
||||
autoid = models.AutoField(primary_key=True)
|
||||
id = models.IntegerField()
|
||||
locale = models.CharField(max_length=10)
|
||||
localized_string = models.TextField()
|
||||
|
||||
class Meta:
|
||||
db_table = 'translations'
|
|
@ -84,6 +84,8 @@ TEMPLATE_DIRS = (
|
|||
)
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'amo',
|
||||
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
|
|
Загрузка…
Ссылка в новой задаче