# Path: core/models.py
# class Job(models.Model):
#     """
#     In [1]: languages = Language.objects.all()
# 
#     In [2]: packages = Package.objects.all()
# 
#     In [3]: for package in packages:
#         for language in languages:
#             (job, created) = Job.objects.get_or_create(language=language, package=package)
#        ....:         job.save()
#        ....:
# 
#     """
# 
#     last_updated = models.DateTimeField(auto_now_add=True, auto_now=True)
#     update_on = models.DateTimeField(blank=True, null=True)
#     active = models.BooleanField(default=False)
# 
#     language = models.ForeignKey(Language, db_index=True)
#     package = models.ForeignKey(Package, db_index=True)
# 
#     def save(self, *args, **kwargs):
#         super(Job, self).save(*args, **kwargs)
#         # Set update_on to end of queue
#         end_queue = Job.objects.latest("update_on")
#         if not end_queue or not end_queue.update_on:
#             end_of_line = self.last_updated
#         else:
#             end_of_line = end_queue.update_on
#         # Now, add 5 minutes to it!
#         from datetime import timedelta
#         five_minutes = timedelta(minutes=5)
# 
#         self.update_on = end_of_line + five_minutes
#         super(Job, self).save(*args, **kwargs)
# 
# class Language(models.Model):
# 
#     long_name = models.CharField(max_length=255, blank=True, null=True)
#     short_name = models.CharField(max_length=30)
# 
#     def __unicode__(self):
#         return "%s (%s)" % (self.long_name, self.short_name) if self.long_name else self.short_name
# 
# class Sentence(models.Model):
# 
#     msgid = models.TextField(max_length=1000)
#     translated = models.BooleanField()
#     length = models.IntegerField(blank=True, null=True)
#     flags = models.CharField(max_length=255, blank=True, null=True)
# 
# 
#     def __unicode__(self):
#         return self.msgid
# 
# class Translation(models.Model):
# 
#     msgstr = models.TextField(max_length=1000)
#     obsolete = models.BooleanField(default=False)
# 
#     #created = models.DateField(auto_now_add=True)
#     #last_modified = models.DateField(auto_now=True)
# 
#     language = models.ForeignKey(Language, db_index=True)
#     package = models.ForeignKey(Package, db_index=True)
#     sentence = models.ForeignKey(Sentence, db_index=True)
# 
#     def __unicode__(self):
#         return self.msgstr


    import json
    import simplejson as json
import tempfile
import logging
import os
from django.conf import settings
from django.db import transaction
from polib import pofile
from core.models import Job, Language, Sentence, Translation
from urllib import urlencode, urlopen
def add_translation(entry, language, package):

    (sentence, created) = Sentence.objects.get_or_create(msgid = entry.msgid)

    sentence.length = len(entry.msgid)
    sentence.save()

    (trans, created) = Translation.objects.get_or_create(msgstr=entry.msgstr, sentence=sentence, language=language, package=package)
    trans.save()

    if entry.msgid_plural:
        (sentence, created) = Sentence.objects.get_or_create(msgid = entry.msgid_plural)

        sentence.length = len(entry.msgid)
        sentence.save()

        (trans, created) = Translation.objects.get_or_create(msgstr=entry.msgstr_plural, sentence=sentence, language=language, package=package)
        trans.save()

def schedule_package(package):

    # Is this package already in the jobs table?
    jobs = Job.objects.filter(package = package)
    if jobs:
        logging.info("Package %s is already scheduled for updates." % package)
        return

    languages = Language.objects.all()

    for language in languages:

# Path: core/models.py
# class Job(models.Model):
#     """
#     In [1]: languages = Language.objects.all()
# 
#     In [2]: packages = Package.objects.all()
# 
#     In [3]: for package in packages:
#         for language in languages:
#             (job, created) = Job.objects.get_or_create(language=language, package=package)
#        ....:         job.save()
#        ....:
# 
#     """
# 
#     last_updated = models.DateTimeField(auto_now_add=True, auto_now=True)
#     update_on = models.DateTimeField(blank=True, null=True)
#     active = models.BooleanField(default=False)
# 
#     language = models.ForeignKey(Language, db_index=True)
#     package = models.ForeignKey(Package, db_index=True)
# 
#     def save(self, *args, **kwargs):
#         super(Job, self).save(*args, **kwargs)
#         # Set update_on to end of queue
#         end_queue = Job.objects.latest("update_on")
#         if not end_queue or not end_queue.update_on:
#             end_of_line = self.last_updated
#         else:
#             end_of_line = end_queue.update_on
#         # Now, add 5 minutes to it!
#         from datetime import timedelta
#         five_minutes = timedelta(minutes=5)
# 
#         self.update_on = end_of_line + five_minutes
#         super(Job, self).save(*args, **kwargs)
# 
# class Language(models.Model):
# 
#     long_name = models.CharField(max_length=255, blank=True, null=True)
#     short_name = models.CharField(max_length=30)
# 
#     def __unicode__(self):
#         return "%s (%s)" % (self.long_name, self.short_name) if self.long_name else self.short_name
# 
# class Sentence(models.Model):
# 
#     msgid = models.TextField(max_length=1000)
#     translated = models.BooleanField()
#     length = models.IntegerField(blank=True, null=True)
#     flags = models.CharField(max_length=255, blank=True, null=True)
# 
# 
#     def __unicode__(self):
#         return self.msgid
# 
# class Translation(models.Model):
# 
#     msgstr = models.TextField(max_length=1000)
#     obsolete = models.BooleanField(default=False)
# 
#     #created = models.DateField(auto_now_add=True)
#     #last_modified = models.DateField(auto_now=True)
# 
#     language = models.ForeignKey(Language, db_index=True)
#     package = models.ForeignKey(Package, db_index=True)
#     sentence = models.ForeignKey(Sentence, db_index=True)
# 
#     def __unicode__(self):
#         return self.msgstr


# Path: core/lib.py
    import json
    import simplejson as json
import tempfile
import logging
import os
from django.conf import settings
from django.db import transaction
from polib import pofile
from core.models import Job, Language, Sentence, Translation
from urllib import urlencode, urlopen

def add_translation(entry, language, package):

    (sentence, created) = Sentence.objects.get_or_create(msgid = entry.msgid)

    sentence.length = len(entry.msgid)
    sentence.save()

    (trans, created) = Translation.objects.get_or_create(msgstr=entry.msgstr, sentence=sentence, language=language, package=package)
    trans.save()

    if entry.msgid_plural:
        (sentence, created) = Sentence.objects.get_or_create(msgid = entry.msgid_plural)

        sentence.length = len(entry.msgid)
        sentence.save()

        (trans, created) = Translation.objects.get_or_create(msgstr=entry.msgstr_plural, sentence=sentence, language=language, package=package)
        trans.save()

def schedule_package(package):

    # Is this package already in the jobs table?
    jobs = Job.objects.filter(package = package)
    if jobs:
        logging.info("Package %s is already scheduled for updates." % package)
        return

    languages = Language.objects.all()

    for language in languages:

        job = Job(package=package, language=language)