Esempio n. 1
0
 def test_instance_to_key(self):
     foo = FakeModel(15)
     key = 'fjord.base.tests.test_utils:FakeModel:15'
     assert instance_to_key(foo) == key
Esempio n. 2
0
 def test_instance_to_key(self):
     foo = FakeModel(15)
     eq_(instance_to_key(foo), 'fjord.base.tests.test_utils:FakeModel:15')
Esempio n. 3
0
 def test_instance_to_key(self):
     foo = FakeModel(15)
     eq_(instance_to_key(foo), 'fjord.base.tests.test_utils:FakeModel:15')
Esempio n. 4
0
    def generate_translation_jobs(self, system=None):
        """Returns a list of tuples, one for each translation job

        If the locale of this response is English, then we just copy over
        the description and we're done.

        If the product of this response isn't set up for
        auto-translation and no translation system was specified in
        the arguments, then we're done.

        If we already have a response with this text that's
        translated, we copy the most recent translation over.

        Otherwise we generate a list of jobs to be done.

        """
        if self.translated_description:
            return []

        # If the text is coming from an English-speaking locale, we
        # assume it's also in English and just copy it over. We do
        # this regardless of whether auto-translation is enabled or
        # not for this product.
        if self.locale and self.locale.startswith('en'):
            self.translated_description = self.description
            self.save()
            return []

        if not system:
            try:
                prod = Product.objects.get(db_name=self.product)
                system = prod.translation_system
            except Product.DoesNotExist:
                # If the product doesn't exist, then I don't know
                # what's going on. Regardless, we shouldn't create any
                # translation jobs.
                return []

        if not system:
            # If this product isn't set up for translation, don't
            # translate it.
            return []

        try:
            # See if this text has been translated already--if so, use
            # the most recent translation.
            existing_translation = (
                Response.objects
                .filter(description=self.description)
                .filter(locale=self.locale)
                .exclude(translated_description__isnull=True)
                .exclude(translated_description=u'')
                .values_list('translated_description')
                .latest('id')
            )
            self.translated_description = existing_translation[0]
            self.save()
            statsd.incr('feedback.translation.used_existing')
            return []
        except Response.DoesNotExist:
            pass

        return [
            # key, system, src language, src field, dst language, dst field
            (instance_to_key(self), system, self.locale, 'description',
             u'en', 'translated_description')
        ]
Esempio n. 5
0
    def generate_translation_jobs(self, system=None):
        """Returns a list of tuples, one for each translation job

        If the locale of this response is English, then we just copy over
        the description and we're done.

        If the product of this response isn't set up for
        auto-translation and no translation system was specified in
        the arguments, then we're done.

        If we already have a response with this text that's
        translated, we copy the most recent translation over.

        Otherwise we generate a list of jobs to be done.

        """
        if self.translated_description:
            return []

        # If the text is coming from an English-speaking locale, we
        # assume it's also in English and just copy it over. We do
        # this regardless of whether auto-translation is enabled or
        # not for this product.
        if self.locale and self.locale.startswith('en'):
            self.translated_description = self.description
            self.save()
            return []

        if not system:
            try:
                prod = Product.objects.get(db_name=self.product)
                system = prod.translation_system
            except Product.DoesNotExist:
                # If the product doesn't exist, then I don't know
                # what's going on. Regardless, we shouldn't create any
                # translation jobs.
                return []

        if not system:
            # If this product isn't set up for translation, don't
            # translate it.
            return []

        try:
            # See if this text has been translated already--if so, use
            # the most recent translation.
            existing_translation = (Response.objects.filter(
                description=self.description).filter(
                    locale=self.locale).exclude(
                        translated_description__isnull=True).exclude(
                            translated_description=u'').values_list(
                                'translated_description').latest('id'))
            self.translated_description = existing_translation[0]
            self.save()
            statsd.incr('feedback.translation.used_existing')
            return []
        except Response.DoesNotExist:
            pass

        return [
            # key, system, src language, src field, dst language, dst field
            (instance_to_key(self), system, self.locale, 'description', u'en',
             'translated_description')
        ]
Esempio n. 6
0
 def generate_translation_jobs(self, system=None):
     """This always returns a fake translation job"""
     return [
         (instance_to_key(self), u'fake', self.locale, u'desc',
          u'en', u'trans_desc')
     ]
Esempio n. 7
0
 def generate_translation_jobs(self, system=None):
     """This always returns a fake translation job"""
     return [(instance_to_key(self), u'fake', self.locale, u'desc', u'en',
              u'trans_desc')]
Esempio n. 8
0
 def test_instance_to_key(self):
     foo = FakeModel(15)
     key = 'fjord.base.tests.test_utils:FakeModel:15'
     assert instance_to_key(foo) == key
Esempio n. 9
0
 def generate_translation_jobs(self, system=None):
     """This always returns a fake translation job"""
     return [(instance_to_key(self), u"fake", self.locale, u"desc", u"en", u"trans_desc")]