Initial code for import

This commit is contained in:
Michal Čihař 2012-02-27 16:09:31 +01:00
parent aff23f0c22
commit 07af4e87ad
2 changed files with 34 additions and 6 deletions

17
trans/managers.py Normal file
View File

@ -0,0 +1,17 @@
from django.db import models
from lang.models import Language
class TranslationManager(models.Manager):
def update_from_blob(self, subproject, code, path, blob):
'''
Parses translation meta info and creates/updates translation object.
'''
print code
lang = Language.objects.get(code = code)
trans, created = self.get_or_create(
language = lang,
subproject = subproject,
filename = path)
print trans

View File

@ -6,6 +6,8 @@ import os
import os.path
import git
from trans.managers import TranslationManager
PLURAL_SEPARATOR = '\x00\x00'
class Project(models.Model):
@ -117,15 +119,22 @@ class SubProject(models.Model):
files = [f.replace(prefix, '') for f in files]
# Get blobs for files
return [tree[f] for f in files]
return [(self.get_lang_code(f), f, tree[f]) for f in files]
def create_translations(self):
'''
Loads translations from git.
'''
blobs = self.get_translation_blobs()
for blob in blobs:
Translation.objects.update_from_blob(self, blob)
for code, path, blob in blobs:
Translation.objects.update_from_blob(self, code, path, blob)
def get_lang_code(self, path):
'''
Parses language code from path.
'''
parts = self.filemask.split('*')
return path[len(parts[0]):-len(parts[1])]
def save(self, *args, **kwargs):
self.configure_repo()
@ -138,11 +147,13 @@ class SubProject(models.Model):
class Translation(models.Model):
subproject = models.ForeignKey(SubProject)
language = models.ForeignKey(Language)
translated = models.FloatField()
fuzzy = models.FloatField()
revision = models.CharField(max_length = 40)
translated = models.FloatField(default = 0)
fuzzy = models.FloatField(default = 0)
revision = models.CharField(max_length = 40, default = '', blank = True)
filename = models.CharField(max_length = 200)
objects = TranslationManager()
@models.permalink
def get_absolute_url(self):
return ('trans.views.show_translation', (), {'project': self.subproject.slug, 'subproject': self.subproject.slug, 'lang': self.language.code})