← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:stormify-pofiletranslator into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:stormify-pofiletranslator into launchpad:master.

Commit message:
Convert POFileTranslator to Storm

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/435888
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-pofiletranslator into launchpad:master.
diff --git a/lib/lp/registry/model/distroseries.py b/lib/lp/registry/model/distroseries.py
index 68f102f..31df52d 100644
--- a/lib/lp/registry/model/distroseries.py
+++ b/lib/lp/registry/model/distroseries.py
@@ -1534,8 +1534,8 @@ class DistroSeries(
 
         contributors = IStore(Person).find(
             Person,
-            POFileTranslator.personID == Person.id,
-            POFile.id == POFileTranslator.pofileID,
+            POFileTranslator.person_id == Person.id,
+            POFile.id == POFileTranslator.pofile_id,
             POFile.language == language,
             POTemplate.id == POFile.potemplateID,
             POTemplate.distroseries == self,
diff --git a/lib/lp/translations/doc/translationmessage-destroy.rst b/lib/lp/translations/doc/translationmessage-destroy.rst
index 9bba5b5..0841544 100644
--- a/lib/lp/translations/doc/translationmessage-destroy.rst
+++ b/lib/lp/translations/doc/translationmessage-destroy.rst
@@ -63,7 +63,7 @@ translation, we get two POFileTranslator records for each of the POFiles.
     ...     IStore(POFileTranslator)
     ...     .find(
     ...         POFileTranslator,
-    ...         POFileTranslator.pofileID.is_in(
+    ...         POFileTranslator.pofile_id.is_in(
     ...             (devel_sr_pofile.id, stable_sr_pofile.id)
     ...         ),
     ...     )
diff --git a/lib/lp/translations/interfaces/pofiletranslator.py b/lib/lp/translations/interfaces/pofiletranslator.py
index 64331c8..a5d05eb 100644
--- a/lib/lp/translations/interfaces/pofiletranslator.py
+++ b/lib/lp/translations/interfaces/pofiletranslator.py
@@ -40,6 +40,9 @@ class IPOFileTranslator(Interface):
         readonly=True,
     )
 
+    def destroySelf():
+        """Delete this record."""
+
 
 class IPOFileTranslatorSet(Interface):
     """Interface representing the set of `IPOFileTranslator`records.
diff --git a/lib/lp/translations/model/pofiletranslator.py b/lib/lp/translations/model/pofiletranslator.py
index 772b8a9..260c5d8 100644
--- a/lib/lp/translations/model/pofiletranslator.py
+++ b/lib/lp/translations/model/pofiletranslator.py
@@ -8,7 +8,9 @@ __all__ = [
 
 from operator import itemgetter
 
+import pytz
 from storm.expr import And, Join, LeftJoin
+from storm.locals import DateTime, Int, Reference
 from storm.store import Store
 from zope.interface import implementer
 
@@ -17,11 +19,9 @@ from lp.registry.model.distroseries import DistroSeries
 from lp.registry.model.product import Product
 from lp.registry.model.productseries import ProductSeries
 from lp.registry.model.sourcepackagename import SourcePackageName
-from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.decoratedresultset import DecoratedResultSet
 from lp.services.database.interfaces import IStore
-from lp.services.database.sqlbase import SQLBase
-from lp.services.database.sqlobject import ForeignKey
+from lp.services.database.stormbase import StormBase
 from lp.translations.interfaces.pofiletranslator import (
     IPOFileTranslator,
     IPOFileTranslatorSet,
@@ -31,20 +31,37 @@ from lp.translations.model.potemplate import POTemplate
 
 
 @implementer(IPOFileTranslator)
-class POFileTranslator(SQLBase):
+class POFileTranslator(StormBase):
     """See `IPOFileTranslator`."""
 
-    pofile = ForeignKey(foreignKey="POFile", dbName="pofile", notNull=True)
-    person = ForeignKey(
-        dbName="person",
-        foreignKey="Person",
-        storm_validator=validate_public_person,
-        notNull=True,
+    __storm_table__ = "POFileTranslator"
+
+    id = Int(primary=True)
+    pofile_id = Int(name="pofile", allow_none=False)
+    pofile = Reference(pofile_id, "POFile.id")
+    person_id = Int(
+        name="person", validator=validate_public_person, allow_none=False
     )
-    date_last_touched = UtcDateTimeCol(
-        dbName="date_last_touched", notNull=False, default=None
+    person = Reference(person_id, "Person.id")
+    date_last_touched = DateTime(
+        name="date_last_touched",
+        allow_none=True,
+        default=None,
+        tzinfo=pytz.UTC,
     )
 
+    def __init__(self, pofile, person_id, date_last_touched=None):
+        super().__init__()
+        self.pofile = pofile
+        # Taking `Person.ID` rather than `Person` is unusual, but it fits
+        # better with how `lp.translators.scripts.scrub_pofiletranslator` is
+        # designed.
+        self.person_id = person_id
+        self.date_last_touched = date_last_touched
+
+    def destroySelf(self):
+        IStore(self).remove(self)
+
 
 @implementer(IPOFileTranslatorSet)
 class POFileTranslatorSet:
@@ -107,6 +124,6 @@ class POFileTranslatorSet:
         """See `IPOFileTranslatorSet`."""
         return Store.of(potemplate).find(
             POFileTranslator,
-            POFileTranslator.pofileID == POFile.id,
+            POFileTranslator.pofile_id == POFile.id,
             POFile.potemplateID == potemplate.id,
         )
diff --git a/lib/lp/translations/model/translationsperson.py b/lib/lp/translations/model/translationsperson.py
index 6126a9f..d978f90 100644
--- a/lib/lp/translations/model/translationsperson.py
+++ b/lib/lp/translations/model/translationsperson.py
@@ -189,8 +189,8 @@ class TranslationsPerson:
         tables = self._composePOFileReviewerJoins(expect_reviewer_status=False)
 
         join_condition = And(
-            POFileTranslator.personID == self.person.id,
-            POFileTranslator.pofileID == POFile.id,
+            POFileTranslator.person == self.person,
+            POFileTranslator.pofile_id == POFile.id,
             POFile.language != getUtility(ILaunchpadCelebrities).english,
         )
 
@@ -261,7 +261,7 @@ class TranslationsPerson:
         Returns a list of Storm CTEs, much the same as
         _composePOFileReviewerJoins."""
         clause = [
-            POFileTranslator.personID == self.person.id,
+            POFileTranslator.person == self.person,
             POFile.language != getUtility(ILaunchpadCelebrities).english,
         ]
         if no_older_than:
diff --git a/lib/lp/translations/scripts/scrub_pofiletranslator.py b/lib/lp/translations/scripts/scrub_pofiletranslator.py
index debbb2f..fbf8add 100644
--- a/lib/lp/translations/scripts/scrub_pofiletranslator.py
+++ b/lib/lp/translations/scripts/scrub_pofiletranslator.py
@@ -135,8 +135,8 @@ def get_pofiletranslators(pofile_ids):
     store = IStore(POFileTranslator)
     pofts = {pofile_id: set() for pofile_id in pofile_ids}
     for pofile_id, person_id in store.find(
-        (POFileTranslator.pofileID, POFileTranslator.personID),
-        POFileTranslator.pofileID.is_in(pofile_ids),
+        (POFileTranslator.pofile_id, POFileTranslator.person_id),
+        POFileTranslator.pofile_id.is_in(pofile_ids),
     ):
         pofts[pofile_id].add(person_id)
     return pofts
@@ -152,8 +152,8 @@ def remove_pofiletranslators(logger, pofile, person_ids):
     store = IStore(pofile)
     pofts = store.find(
         POFileTranslator,
-        POFileTranslator.pofileID == pofile.id,
-        POFileTranslator.personID.is_in(person_ids),
+        POFileTranslator.pofile == pofile,
+        POFileTranslator.person_id.is_in(person_ids),
     )
     pofts.remove()
 
@@ -178,7 +178,7 @@ def create_missing_pofiletranslators(logger, pofile, pofts, contribs):
         store.add(
             POFileTranslator(
                 pofile=pofile,
-                personID=missing_contributor,
+                person_id=missing_contributor,
                 date_last_touched=contribs[missing_contributor],
             )
         )
diff --git a/lib/lp/translations/scripts/tests/test_scrub_pofiletranslator.py b/lib/lp/translations/scripts/tests/test_scrub_pofiletranslator.py
index f753106..f1db5d1 100644
--- a/lib/lp/translations/scripts/tests/test_scrub_pofiletranslator.py
+++ b/lib/lp/translations/scripts/tests/test_scrub_pofiletranslator.py
@@ -73,7 +73,7 @@ class TestScrubPOFileTranslator(TestCaseWithFactory):
             pofile = self.factory.makePOFile()
         poft = POFileTranslator(
             pofile=pofile,
-            person=self.factory.makePerson(),
+            person_id=self.factory.makePerson().id,
             date_last_touched=UTC_NOW,
         )
         IStore(poft.pofile).add(poft)