launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #28719
[Merge] ~cjwatson/launchpad:stormify-translator into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:stormify-translator into launchpad:master.
Commit message:
Convert Translator to Storm
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/426186
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-translator into launchpad:master.
diff --git a/lib/lp/services/worlddata/model/language.py b/lib/lp/services/worlddata/model/language.py
index fc72fab..8bd7707 100644
--- a/lib/lp/services/worlddata/model/language.py
+++ b/lib/lp/services/worlddata/model/language.py
@@ -16,6 +16,7 @@ from storm.expr import (
LeftJoin,
Or,
)
+from storm.references import ReferenceSet
from zope.interface import implementer
from lp.app.errors import NotFoundError
@@ -64,9 +65,9 @@ class Language(SQLBase):
name='direction', allow_none=False, enum=TextDirection,
default=TextDirection.LTR)
- translation_teams = SQLRelatedJoin(
- 'Person', joinColumn="language",
- intermediateTable='Translator', otherColumn='translator')
+ translation_teams = ReferenceSet(
+ "<primary key>", "Translator.language_id", "Translator.translator_id",
+ "Person.id")
_countries = SQLRelatedJoin(
'Country', joinColumn='language',
diff --git a/lib/lp/translations/model/translationgroup.py b/lib/lp/translations/model/translationgroup.py
index c274697..b0f174f 100644
--- a/lib/lp/translations/model/translationgroup.py
+++ b/lib/lp/translations/model/translationgroup.py
@@ -13,6 +13,7 @@ from storm.expr import (
Join,
LeftJoin,
)
+from storm.references import ReferenceSet
from storm.store import Store
from zope.interface import implementer
@@ -33,7 +34,6 @@ from lp.services.database.sqlobject import (
ForeignKey,
SQLMultipleJoin,
SQLObjectNotFound,
- SQLRelatedJoin,
StringCol,
)
from lp.services.librarian.model import (
@@ -67,10 +67,11 @@ class TranslationGroup(SQLBase):
# useful joins
distributions = SQLMultipleJoin('Distribution',
joinColumn='translationgroup')
- languages = SQLRelatedJoin('Language', joinColumn='translationgroup',
- intermediateTable='Translator', otherColumn='language')
- translators = SQLMultipleJoin('Translator',
- joinColumn='translationgroup')
+ languages = ReferenceSet(
+ "<primary key>", "Translator.translationgroup_id",
+ "Translator.language_id", "Language.id")
+ translators = ReferenceSet(
+ "<primary key>", "Translator.translationgroup_id")
translation_guide_url = StringCol(notNull=False, default=None)
def __getitem__(self, language_code):
@@ -78,7 +79,7 @@ class TranslationGroup(SQLBase):
query = Store.of(self).find(
Translator,
Translator.translationgroup == self,
- Translator.languageID == Language.id,
+ Translator.language_id == Language.id,
Language.code == language_code)
translator = query.one()
@@ -95,7 +96,7 @@ class TranslationGroup(SQLBase):
# adding and removing translators
def remove_translator(self, translator):
"""See ITranslationGroup."""
- Translator.delete(translator.id)
+ IStore(Translator).find(Translator, id=translator.id).remove()
# get a translator by language or code
def query_translator(self, language):
@@ -176,8 +177,8 @@ class TranslationGroup(SQLBase):
translator_data = Store.of(self).using(*using).find(
tables,
Translator.translationgroup == self,
- Language.id == Translator.languageID,
- Person.id == Translator.translatorID)
+ Language.id == Translator.language_id,
+ Person.id == Translator.translator_id)
translator_data = translator_data.order_by(Language.englishname)
mapper = lambda row: row[slice(0, 3)]
return DecoratedResultSet(translator_data, mapper)
@@ -296,9 +297,9 @@ class TranslationGroupSet:
origin = [
TranslationGroup,
Join(Translator,
- Translator.translationgroupID == TranslationGroup.id),
+ Translator.translationgroup_id == TranslationGroup.id),
Join(TeamParticipation,
- TeamParticipation.teamID == Translator.translatorID),
+ TeamParticipation.teamID == Translator.translator_id),
]
result = store.using(*origin).find(
TranslationGroup, TeamParticipation.person == person)
diff --git a/lib/lp/translations/model/translationpolicy.py b/lib/lp/translations/model/translationpolicy.py
index 366617e..43f22f7 100644
--- a/lib/lp/translations/model/translationpolicy.py
+++ b/lib/lp/translations/model/translationpolicy.py
@@ -91,10 +91,10 @@ class TranslationPolicyMixin:
def _getTranslator(self, translationgroup, language, store):
"""Retrieve one (TranslationGroup, Translator, Person) tuple."""
translator_join = LeftJoin(Translator, And(
- Translator.translationgroupID == TranslationGroup.id,
- Translator.languageID == language.id))
+ Translator.translationgroup_id == TranslationGroup.id,
+ Translator.language_id == language.id))
person_join = LeftJoin(
- Person, Person.id == Translator.translatorID)
+ Person, Person.id == Translator.translator_id)
source = store.using(TranslationGroup, translator_join, person_join)
return source.find(
diff --git a/lib/lp/translations/model/translationsperson.py b/lib/lp/translations/model/translationsperson.py
index 8c9cde9..3419891 100644
--- a/lib/lp/translations/model/translationsperson.py
+++ b/lib/lp/translations/model/translationsperson.py
@@ -252,17 +252,17 @@ class TranslationsPerson:
where=And(*clause)))
ReviewableGroups = With("reviewable_groups",
Select(
- (TranslationGroup.id, Translator.languageID),
+ (TranslationGroup.id, Translator.language_id),
tables=[
TranslationGroup,
Join(
Translator,
- Translator.translationgroupID == TranslationGroup.id),
+ Translator.translationgroup_id == TranslationGroup.id),
Join(
TeamParticipation,
And(
TeamParticipation.teamID ==
- Translator.translatorID,
+ Translator.translator_id,
TeamParticipation.personID == self.person.id))]))
TranslatableDistroSeries = With("translatable_distroseries",
Select(
@@ -362,8 +362,8 @@ class TranslationsPerson:
# Look up translation team.
translatorjoin_conditions = And(
- Translator.translationgroupID == TranslationGroup.id,
- Translator.languageID == POFile.languageID)
+ Translator.translationgroup_id == TranslationGroup.id,
+ Translator.language_id == POFile.languageID)
if expect_reviewer_status:
TranslatorJoin = Join(Translator, translatorjoin_conditions)
else:
@@ -375,7 +375,7 @@ class TranslationsPerson:
# query won't be interested in its actual contents anyway.
Reviewership = ClassAlias(TeamParticipation, 'Reviewership')
reviewerjoin_condition = And(
- Reviewership.teamID == Translator.translatorID,
+ Reviewership.teamID == Translator.translator_id,
Reviewership.personID == self.person.id)
if expect_reviewer_status:
TranslationTeamJoin = Join(Reviewership, reviewerjoin_condition)
diff --git a/lib/lp/translations/model/translator.py b/lib/lp/translations/model/translator.py
index c27821e..6facd48 100644
--- a/lib/lp/translations/model/translator.py
+++ b/lib/lp/translations/model/translator.py
@@ -3,19 +3,21 @@
__all__ = ['Translator', 'TranslatorSet']
-from storm.expr import Join
-from storm.store import Store
+import pytz
+from storm.locals import (
+ DateTime,
+ Int,
+ Join,
+ Reference,
+ Store,
+ Unicode,
+ )
from zope.interface import implementer
from lp.registry.interfaces.person import validate_public_person
from lp.registry.model.teammembership import TeamParticipation
from lp.services.database.constants import DEFAULT
-from lp.services.database.datetimecol import UtcDateTimeCol
-from lp.services.database.sqlbase import SQLBase
-from lp.services.database.sqlobject import (
- ForeignKey,
- StringCol,
- )
+from lp.services.database.stormbase import StormBase
from lp.translations.interfaces.translator import (
ITranslator,
ITranslatorSet,
@@ -23,22 +25,32 @@ from lp.translations.interfaces.translator import (
@implementer(ITranslator)
-class Translator(SQLBase):
+class Translator(StormBase):
"""A Translator in a TranslationGroup."""
+ __storm_table__ = "Translator"
# default to listing newest first
- _defaultOrder = '-id'
+ __storm_order__ = "-id"
+
+ id = Int(primary=True)
+
+ translationgroup_id = Int(name="translationgroup", allow_none=False)
+ translationgroup = Reference(translationgroup_id, "TranslationGroup.id")
+ language_id = Int(name="language", allow_none=False)
+ language = Reference(language_id, "Language.id")
+ translator_id = Int(
+ name="translator", validator=validate_public_person, allow_none=False)
+ translator = Reference(translator_id, "Person.id")
+ datecreated = DateTime(allow_none=False, default=DEFAULT, tzinfo=pytz.UTC)
+ style_guide_url = Unicode(allow_none=True, default=None)
- # db field names
- translationgroup = ForeignKey(dbName='translationgroup',
- foreignKey='TranslationGroup', notNull=True)
- language = ForeignKey(dbName='language',
- foreignKey='Language', notNull=True)
- translator = ForeignKey(
- dbName='translator', foreignKey='Person',
- storm_validator=validate_public_person, notNull=True)
- datecreated = UtcDateTimeCol(notNull=True, default=DEFAULT)
- style_guide_url = StringCol(notNull=False, default=None)
+ def __init__(self, translationgroup, language, translator,
+ style_guide_url=None):
+ super().__init__()
+ self.translationgroup = translationgroup
+ self.language = language
+ self.translator = translator
+ self.style_guide_url = style_guide_url
@implementer(ITranslatorSet)
@@ -61,7 +73,7 @@ class TranslatorSet:
origin = [
Translator,
Join(TeamParticipation,
- TeamParticipation.teamID == Translator.translatorID),
+ TeamParticipation.teamID == Translator.translator_id),
Join("TranslationGroup",
on="TranslationGroup.id = Translator.translationgroup")
]