launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24858
[Merge] ~cjwatson/launchpad:stormify-poexportrequest into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:stormify-poexportrequest into launchpad:master.
Commit message:
Convert POExportRequest to Storm
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/385556
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-poexportrequest into launchpad:master.
diff --git a/lib/lp/translations/doc/poexport-request.txt b/lib/lp/translations/doc/poexport-request.txt
index c87ec82..cf6d13f 100644
--- a/lib/lp/translations/doc/poexport-request.txt
+++ b/lib/lp/translations/doc/poexport-request.txt
@@ -102,6 +102,7 @@ Let's download it and make sure the contents look ok.
On another occasion, the user requests just Catalan translation. The
queue is initially empty.
+ >>> from lp.services.database.interfaces import IStore
>>> def render_request(request):
... if request.pofile is None:
... return request.potemplate.name
@@ -113,7 +114,7 @@ queue is initially empty.
>>> def print_queue():
... requests = [
... render_request(request)
- ... for request in POExportRequest.select()]
+ ... for request in IStore(POExportRequest).find(POExportRequest)]
... for request in sorted(requests):
... print(request)
>>> print_queue()
@@ -161,7 +162,7 @@ Only the Spanish request is new, and that goes into the queue.
pmount:es
>>> # Clean up the queue again.
- >>> for request in POExportRequest.select():
+ >>> for request in IStore(POExportRequest).find(POExportRequest):
... request.destroySelf()
diff --git a/lib/lp/translations/model/poexportrequest.py b/lib/lp/translations/model/poexportrequest.py
index 30f6ee6..fe3e9d5 100644
--- a/lib/lp/translations/model/poexportrequest.py
+++ b/lib/lp/translations/model/poexportrequest.py
@@ -8,23 +8,25 @@ __all__ = [
'POExportRequestSet',
]
-from sqlobject import ForeignKey
+import pytz
+from storm.locals import (
+ DateTime,
+ Int,
+ Reference,
+ Store,
+ )
from zope.interface import implementer
from lp.registry.interfaces.person import validate_public_person
from lp.services.database.constants import DEFAULT
-from lp.services.database.datetimecol import UtcDateTimeCol
-from lp.services.database.enumcol import EnumCol
+from lp.services.database.enumcol import DBEnum
from lp.services.database.interfaces import (
IMasterStore,
ISlaveStore,
IStore,
)
-from lp.services.database.sqlbase import (
- quote,
- SQLBase,
- sqlvalues,
- )
+from lp.services.database.sqlbase import quote
+from lp.services.database.stormbase import StormBase
from lp.translations.interfaces.poexportrequest import (
IPOExportRequest,
IPOExportRequestSet,
@@ -158,7 +160,7 @@ class POExportRequestSet:
POExportRequest.person == head.person,
POExportRequest.format == head.format,
POExportRequest.date_created == head.date_created).order_by(
- POExportRequest.potemplateID)
+ POExportRequest.potemplate_id)
summary = [
(request.id, request.pofile or request.potemplate)
@@ -172,27 +174,35 @@ class POExportRequestSet:
def removeRequest(self, request_ids):
"""See `IPOExportRequestSet`."""
- if len(request_ids) > 0:
- # Storm 0.15 does not have direct support for deleting based
- # on is_in expressions and such, so do it the hard way.
- ids_string = ', '.join(sqlvalues(*request_ids))
- IMasterStore(POExportRequest).execute("""
- DELETE FROM POExportRequest
- WHERE id in (%s)
- """ % ids_string)
+ if request_ids:
+ IMasterStore(POExportRequest).find(
+ POExportRequest,
+ POExportRequest.id.is_in(request_ids)).remove()
@implementer(IPOExportRequest)
-class POExportRequest(SQLBase):
-
- _table = 'POExportRequest'
-
- person = ForeignKey(
- dbName='person', foreignKey='Person',
- storm_validator=validate_public_person, notNull=True)
- date_created = UtcDateTimeCol(dbName='date_created', default=DEFAULT)
- potemplate = ForeignKey(dbName='potemplate', foreignKey='POTemplate',
- notNull=True)
- pofile = ForeignKey(dbName='pofile', foreignKey='POFile')
- format = EnumCol(dbName='format', schema=TranslationFileFormat,
- default=TranslationFileFormat.PO, notNull=True)
+class POExportRequest(StormBase):
+
+ __storm_table__ = 'POExportRequest'
+
+ id = Int(primary=True)
+
+ person_id = Int(
+ name='person', allow_none=False, validator=validate_public_person)
+ person = Reference(person_id, 'Person.id')
+
+ date_created = DateTime(
+ tzinfo=pytz.UTC, name='date_created', default=DEFAULT)
+
+ potemplate_id = Int(name='potemplate', allow_none=False)
+ potemplate = Reference(potemplate_id, 'POTemplate.id')
+
+ pofile_id = Int(name='pofile', allow_none=True)
+ pofile = Reference(pofile_id, 'POFile.id')
+
+ format = DBEnum(
+ name='format', enum=TranslationFileFormat,
+ default=TranslationFileFormat.PO, allow_none=False)
+
+ def destroySelf(self):
+ Store.of(self).remove(self)