1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Implementation classes for a CommercialSubscription."""
__metaclass__ = type
__all__ = ['CommercialSubscription']
import datetime
import pytz
from sqlobject import (
ForeignKey,
StringCol,
)
from zope.interface import implements
from lp.registry.interfaces.commercialsubscription import (
ICommercialSubscription,
)
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
class CommercialSubscription(SQLBase):
implements(ICommercialSubscription)
product = ForeignKey(
dbName='product', foreignKey='Product', notNull=True)
date_created = UtcDateTimeCol(notNull=True, default=UTC_NOW)
date_last_modified = UtcDateTimeCol(notNull=True, default=UTC_NOW)
date_starts = UtcDateTimeCol(notNull=True, default=UTC_NOW)
date_expires = UtcDateTimeCol(notNull=True, default=UTC_NOW)
registrant = ForeignKey(
dbName='registrant', foreignKey='Person', default=None,
storm_validator=validate_public_person)
purchaser = ForeignKey(
dbName='purchaser', foreignKey='Person', default=None,
storm_validator=validate_public_person)
sales_system_id = StringCol(notNull=True)
whiteboard = StringCol(default=None)
@property
def is_active(self):
now = datetime.datetime.now(pytz.timezone('UTC'))
return self.date_starts < now < self.date_expires
|