← Back to team overview

launchpad-reviewers team mailing list archive

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

 

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

Commit message:
Convert TranslationRelicensingAgreement to Storm

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/424115
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-translationrelicensingagreement into launchpad:master.
diff --git a/lib/lp/translations/model/translationrelicensingagreement.py b/lib/lp/translations/model/translationrelicensingagreement.py
index 79263ef..4cab847 100644
--- a/lib/lp/translations/model/translationrelicensingagreement.py
+++ b/lib/lp/translations/model/translationrelicensingagreement.py
@@ -5,32 +5,42 @@ __all__ = [
     'TranslationRelicensingAgreement',
     ]
 
+import pytz
+from storm.locals import (
+    Bool,
+    DateTime,
+    Int,
+    Reference,
+    )
 from zope.interface import implementer
 
 from lp.registry.interfaces.person import validate_public_person
 from lp.services.database.constants import UTC_NOW
-from lp.services.database.datetimecol import UtcDateTimeCol
-from lp.services.database.sqlbase import SQLBase
-from lp.services.database.sqlobject import (
-    BoolCol,
-    ForeignKey,
-    )
+from lp.services.database.stormbase import StormBase
 from lp.translations.interfaces.translationrelicensingagreement import (
     ITranslationRelicensingAgreement,
     )
 
 
 @implementer(ITranslationRelicensingAgreement)
-class TranslationRelicensingAgreement(SQLBase):
+class TranslationRelicensingAgreement(StormBase):
+
+    __storm_table__ = "TranslationRelicensingAgreement"
+
+    id = Int(primary=True)
 
-    _table = 'TranslationRelicensingAgreement'
+    person_id = Int(
+        name="person", allow_none=False, validator=validate_public_person)
+    person = Reference(person_id, "Person.id")
 
-    person = ForeignKey(
-        foreignKey='Person', dbName='person', notNull=True,
-        storm_validator=validate_public_person)
+    allow_relicensing = Bool(
+        name="allow_relicensing", allow_none=False, default=True)
 
-    allow_relicensing = BoolCol(
-        dbName='allow_relicensing', notNull=True, default=True)
+    date_decided = DateTime(
+        name="date_decided", allow_none=False, default=UTC_NOW,
+        tzinfo=pytz.UTC)
 
-    date_decided = UtcDateTimeCol(
-        dbName='date_decided', notNull=True, default=UTC_NOW)
+    def __init__(self, person, allow_relicensing=True):
+        super().__init__()
+        self.person = person
+        self.allow_relicensing = allow_relicensing
diff --git a/lib/lp/translations/scripts/tests/test_remove_translations.py b/lib/lp/translations/scripts/tests/test_remove_translations.py
index 3a71ca2..db1733b 100644
--- a/lib/lp/translations/scripts/tests/test_remove_translations.py
+++ b/lib/lp/translations/scripts/tests/test_remove_translations.py
@@ -546,31 +546,22 @@ class TestRemoveTranslations(TestCase):
         # Removing translations whose submitters rejected our
         # translations licence does not affect translations by those who
         # agreed to license.
-        answer = TranslationRelicensingAgreement(
+        TranslationRelicensingAgreement(
             person=self.nl_message.submitter, allow_relicensing=True)
 
-        try:
-            self._removeMessages(reject_license=True)
-            self._checkInvariant()
-        finally:
-            # Clean up.
-            answer.destroySelf()
+        self._removeMessages(reject_license=True)
+        self._checkInvariant()
 
     def test_remove_unlicensed_restriction(self):
         # When removing unlicensed translations, other restrictions
         # still apply.
         self.nl_message.is_current_upstream = True
         self.de_message.is_current_upstream = True
-        answer = TranslationRelicensingAgreement(
+        TranslationRelicensingAgreement(
             person=self.nl_message.submitter, allow_relicensing=False)
 
-        try:
-            self._removeMessages(
-                reject_license=True, is_current_upstream=False)
-            self._checkInvariant()
-        finally:
-            # Clean up.
-            answer.destroySelf()
+        self._removeMessages(reject_license=True, is_current_upstream=False)
+        self._checkInvariant()
 
 
 class TestRemoveTranslationsUnmasking(TestCaseWithFactory):