Mostly cleanup.

This commit is contained in:
Peter Eschler 2009-02-21 02:18:06 +00:00
parent 70e8804a9d
commit e4a882abc8
3 changed files with 13 additions and 14 deletions

View file

@ -18,7 +18,7 @@ class TranslationAdmin(admin.ModelAdmin):
# Hide the original field by making it non-editable.
if db_field.name in trans_opts.fields:
db_field.editable = False
db_field.editable = False
# field.widget.attrs['readonly'] = "true"
# For every localized field copy the widget from the original field
@ -31,7 +31,7 @@ class TranslationAdmin(admin.ModelAdmin):
if db_field.language == settings.LANGUAGES[0][0] and orig_formfield.required:
orig_formfield.required = False
field.required = True
field.widget = deepcopy(orig_formfield.widget)

View file

@ -5,22 +5,21 @@ from django.core.management.base import BaseCommand, CommandError, NoArgsCommand
from modeltranslation.translator import translator
from modeltranslation.utils import build_localized_fieldname
class Command(BaseCommand):
class Command(NoArgsCommand):
help = 'Updates the default translation fields of all or the specified'\
'application using the value of the original field.'
args = '[app_name]'
'translated application using the value of the original field.'
# args = '[app_name]'
def handle(self, subscriber_list_slug, **options):
def handle(self, **options):
default_lang = settings.LANGUAGES[0][0]
print "Using default language:", default_lang
for model, trans_opts in translator._registry.items():
print model, trans_opts
# Get all the instances of the model
for obj in model.objects.all():
print obj
for model, trans_opts in translator._registry.items():
print "Updating data of model '%s'" % model
for obj in model.objects.all():
for fieldname in trans_opts.fields:
def_lang_fieldname = build_localized_fieldname(fieldname, default_lang)
print "setting %s from %s to %s." % (def_lang_fieldname, fieldname, obj.__dict__[fieldname])
# print "setting %s from %s to %s." % (def_lang_fieldname, fieldname, obj.__dict__[fieldname])
if not getattr(obj, def_lang_fieldname):
setattr(obj, def_lang_fieldname, obj.__dict__[fieldname])
obj.save()
obj.save()

View file

@ -143,7 +143,7 @@ class Translator(object):
translation_opts.localized_fieldnames_rev = rev_dict
print "Applying descriptor field for model %s" % model
# print "Applying descriptor field for model %s" % model
for field_name in translation_opts.fields:
setattr(model, field_name, TranslationFieldDescriptor(field_name))