launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #29543
[Merge] ~cjwatson/launchpad:stormify-translationgroup into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:stormify-translationgroup into launchpad:master.
Commit message:
Convert TranslationGroup to Storm
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/435737
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-translationgroup into launchpad:master.
diff --git a/lib/lp/registry/model/distribution.py b/lib/lp/registry/model/distribution.py
index 5e0a7ff..af6ce95 100644
--- a/lib/lp/registry/model/distribution.py
+++ b/lib/lp/registry/model/distribution.py
@@ -308,12 +308,10 @@ class Distribution(
notNull=False,
default=None,
)
- translationgroup = ForeignKey(
- dbName="translationgroup",
- foreignKey="TranslationGroup",
- notNull=False,
- default=None,
+ translationgroup_id = Int(
+ name="translationgroup", allow_none=True, default=None
)
+ translationgroup = Reference(translationgroup_id, "TranslationGroup.id")
translationpermission = DBEnum(
name="translationpermission",
allow_none=False,
diff --git a/lib/lp/registry/model/product.py b/lib/lp/registry/model/product.py
index f905576..8a941d8 100644
--- a/lib/lp/registry/model/product.py
+++ b/lib/lp/registry/model/product.py
@@ -32,7 +32,7 @@ from storm.expr import (
Or,
Select,
)
-from storm.locals import Int, List, Store, Unicode
+from storm.locals import Int, List, Reference, Store, Unicode
from zope.component import getUtility
from zope.event import notify
from zope.interface import implementer
@@ -332,12 +332,10 @@ class Product(
)
downloadurl = StringCol(dbName="downloadurl", notNull=False, default=None)
lastdoap = StringCol(dbName="lastdoap", notNull=False, default=None)
- translationgroup = ForeignKey(
- dbName="translationgroup",
- foreignKey="TranslationGroup",
- notNull=False,
- default=None,
+ translationgroup_id = Int(
+ name="translationgroup", allow_none=True, default=None
)
+ translationgroup = Reference(translationgroup_id, "TranslationGroup.id")
translationpermission = DBEnum(
name="translationpermission",
allow_none=False,
diff --git a/lib/lp/registry/model/projectgroup.py b/lib/lp/registry/model/projectgroup.py
index f6f9966..135c433 100644
--- a/lib/lp/registry/model/projectgroup.py
+++ b/lib/lp/registry/model/projectgroup.py
@@ -11,6 +11,7 @@ __all__ = [
import six
from storm.expr import SQL, And, In, Join
+from storm.locals import Int, Reference
from storm.store import Store
from zope.component import getUtility
from zope.interface import implementer
@@ -151,12 +152,10 @@ class ProjectGroup(
)
freshmeatproject = None
lastdoap = StringCol(dbName="lastdoap", notNull=False, default=None)
- translationgroup = ForeignKey(
- dbName="translationgroup",
- foreignKey="TranslationGroup",
- notNull=False,
- default=None,
+ translationgroup_id = Int(
+ name="translationgroup", allow_none=True, default=None
)
+ translationgroup = Reference(translationgroup_id, "TranslationGroup.id")
translationpermission = DBEnum(
name="translationpermission",
allow_none=False,
diff --git a/lib/lp/testing/factory.py b/lib/lp/testing/factory.py
index 2e8dae2..9a672aa 100644
--- a/lib/lp/testing/factory.py
+++ b/lib/lp/testing/factory.py
@@ -894,14 +894,16 @@ class LaunchpadObjectFactory(ObjectFactory):
if owner is None:
owner = self.makePerson()
if name is None:
- name = self.getUniqueString("translationgroup")
+ name = self.getUniqueUnicode("translationgroup")
if title is None:
- title = self.getUniqueString("title")
+ title = self.getUniqueUnicode("title")
if summary is None:
- summary = self.getUniqueString("summary")
- return getUtility(ITranslationGroupSet).new(
+ summary = self.getUniqueUnicode("summary")
+ group = getUtility(ITranslationGroupSet).new(
name, title, summary, url, owner
)
+ IStore(group).flush()
+ return group
def makeTranslator(
self,
diff --git a/lib/lp/translations/model/translationgroup.py b/lib/lp/translations/model/translationgroup.py
index 8d59714..b0cea94 100644
--- a/lib/lp/translations/model/translationgroup.py
+++ b/lib/lp/translations/model/translationgroup.py
@@ -8,8 +8,10 @@ __all__ = [
import operator
+import pytz
from storm.expr import Desc, Join, LeftJoin
-from storm.references import ReferenceSet
+from storm.properties import DateTime, Int, Unicode
+from storm.references import Reference, ReferenceSet
from storm.store import Store
from zope.interface import implementer
@@ -19,16 +21,9 @@ from lp.registry.model.person import Person
from lp.registry.model.teammembership import TeamParticipation
from lp.services.database import bulk
from lp.services.database.constants import DEFAULT
-from lp.services.database.datetimecol import UtcDateTimeCol
from lp.services.database.decoratedresultset import DecoratedResultSet
from lp.services.database.interfaces import IStandbyStore, IStore
-from lp.services.database.sqlbase import SQLBase
-from lp.services.database.sqlobject import (
- ForeignKey,
- SQLMultipleJoin,
- SQLObjectNotFound,
- StringCol,
-)
+from lp.services.database.stormbase import StormBase
from lp.services.librarian.model import LibraryFileAlias, LibraryFileContent
from lp.services.worlddata.model.language import Language
from lp.translations.interfaces.translationgroup import (
@@ -39,38 +34,51 @@ from lp.translations.model.translator import Translator
@implementer(ITranslationGroup)
-class TranslationGroup(SQLBase):
+class TranslationGroup(StormBase):
"""A TranslationGroup."""
+ __storm_table__ = "TranslationGroup"
# default to listing alphabetically
- _defaultOrder = "name"
+ __storm_order__ = "name"
# db field names
- name = StringCol(unique=True, alternateID=True, notNull=True)
- title = StringCol(notNull=True)
- summary = StringCol(notNull=True)
- datecreated = UtcDateTimeCol(notNull=True, default=DEFAULT)
- owner = ForeignKey(
- dbName="owner",
- foreignKey="Person",
- storm_validator=validate_public_person,
- notNull=True,
+ id = Int(primary=True)
+ name = Unicode(allow_none=False)
+ title = Unicode(allow_none=False)
+ summary = Unicode(allow_none=False)
+ datecreated = DateTime(allow_none=False, default=DEFAULT, tzinfo=pytz.UTC)
+ owner_id = Int(
+ name="owner", validator=validate_public_person, allow_none=False
)
+ owner = Reference(owner_id, "Person.id")
# useful joins
- distributions = SQLMultipleJoin(
- "Distribution", joinColumn="translationgroup"
- )
+ distributions = ReferenceSet("id", "Distribution.translationgroup_id")
languages = ReferenceSet(
- "<primary key>",
+ "id",
"Translator.translationgroup_id",
"Translator.language_id",
"Language.id",
)
- translators = ReferenceSet(
- "<primary key>", "Translator.translationgroup_id"
- )
- translation_guide_url = StringCol(notNull=False, default=None)
+ translators = ReferenceSet("id", "Translator.translationgroup_id")
+ translation_guide_url = Unicode(allow_none=True, default=None)
+
+ def __init__(
+ self,
+ name,
+ title,
+ summary,
+ owner,
+ datecreated=DEFAULT,
+ translation_guide_url=None,
+ ):
+ super().__init__()
+ self.name = name
+ self.title = title
+ self.summary = summary
+ self.owner = owner
+ self.datecreated = datecreated
+ self.translation_guide_url = translation_guide_url
def __getitem__(self, language_code):
"""See `ITranslationGroup`."""
@@ -205,7 +213,7 @@ class TranslationGroup(SQLBase):
IStore(Product)
.find(
Product,
- Product.translationgroupID == self.id,
+ Product.translationgroup == self,
Product.active == True,
ProductSet.getProductPrivacyFilter(user),
)
@@ -241,7 +249,7 @@ class TranslationGroup(SQLBase):
.using(*using)
.find(
tables,
- ProjectGroup.translationgroupID == self.id,
+ ProjectGroup.translationgroup == self,
ProjectGroup.active == True,
)
.order_by(ProjectGroup.display_name)
@@ -272,7 +280,7 @@ class TranslationGroup(SQLBase):
distro_data = (
IStandbyStore(Distribution)
.using(*using)
- .find(tables, Distribution.translationgroupID == self.id)
+ .find(tables, Distribution.translationgroup == self)
.order_by(Distribution.display_name)
)
@@ -305,10 +313,12 @@ class TranslationGroupSet:
def getByName(self, name):
"""See ITranslationGroupSet."""
- try:
- return TranslationGroup.byName(name)
- except SQLObjectNotFound:
+ group = (
+ IStore(TranslationGroup).find(TranslationGroup, name=name).one()
+ )
+ if group is None:
raise NotFoundError(name)
+ return group
def _get(self):
return IStore(TranslationGroup).find(TranslationGroup)
diff --git a/lib/lp/translations/model/translationsperson.py b/lib/lp/translations/model/translationsperson.py
index 693eccb..6126a9f 100644
--- a/lib/lp/translations/model/translationsperson.py
+++ b/lib/lp/translations/model/translationsperson.py
@@ -321,7 +321,7 @@ class TranslationsPerson:
Join(
SQL("reviewable_groups"),
SQL("reviewable_groups.id")
- == Distribution.translationgroupID,
+ == Distribution.translationgroup_id,
),
],
),
@@ -348,7 +348,7 @@ class TranslationsPerson:
Join(
SQL("reviewable_groups"),
SQL("reviewable_groups.id")
- == Product.translationgroupID,
+ == Product.translationgroup_id,
),
],
),
@@ -421,9 +421,9 @@ class TranslationsPerson:
# Look up translation group.
groupjoin_conditions = Or(
- TranslationGroup.id == Product.translationgroupID,
- TranslationGroup.id == Distribution.translationgroupID,
- TranslationGroup.id == ProjectGroup.translationgroupID,
+ TranslationGroup.id == Product.translationgroup_id,
+ TranslationGroup.id == Distribution.translationgroup_id,
+ TranslationGroup.id == ProjectGroup.translationgroup_id,
)
if expect_reviewer_status:
GroupJoin = Join(TranslationGroup, groupjoin_conditions)
diff --git a/lib/lp/translations/vocabularies.py b/lib/lp/translations/vocabularies.py
index 3fa4d3b..501f89c 100644
--- a/lib/lp/translations/vocabularies.py
+++ b/lib/lp/translations/vocabularies.py
@@ -19,7 +19,7 @@ from zope.schema.vocabulary import SimpleTerm
from lp.registry.interfaces.distroseries import IDistroSeries
from lp.services.database.sqlobject import AND
from lp.services.webapp.vocabulary import (
- NamedSQLObjectVocabulary,
+ NamedStormVocabulary,
SQLObjectVocabularyBase,
StormVocabularyBase,
)
@@ -75,7 +75,7 @@ class TranslatableLanguageVocabulary(LanguageVocabulary):
return term
-class TranslationGroupVocabulary(NamedSQLObjectVocabulary):
+class TranslationGroupVocabulary(NamedStormVocabulary):
_table = TranslationGroup