Initial code for import
This commit is contained in:
parent
aff23f0c22
commit
07af4e87ad
17
trans/managers.py
Normal file
17
trans/managers.py
Normal 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
|
||||
|
@ -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})
|
||||
|
Loading…
Reference in New Issue
Block a user