Merge lp:~wgrant/launchpad/ageless into lp:launchpad

Proposed by William Grant
Status: Merged
Merged at revision: 17913
Proposed branch: lp:~wgrant/launchpad/ageless
Merge into: lp:launchpad
Diff against target: 328 lines (+18/-170)
7 files modified
lib/lp/app/configure.zcml (+1/-7)
lib/lp/app/doc/datehandling.txt (+0/-61)
lib/lp/app/interfaces/launchpad.py (+1/-20)
lib/lp/app/model/cdatetime.py (+0/-71)
lib/lp/blueprints/interfaces/specificationbranch.py (+7/-4)
lib/lp/bugs/interfaces/bugbranch.py (+7/-4)
lib/lp/bugs/interfaces/bugtask.py (+2/-3)
To merge this branch: bzr merge lp:~wgrant/launchpad/ageless
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
Launchpad code reviewers Pending
Review via email: mp+285150@code.launchpad.net

Commit message

Remove unused IAging, inline IHasDateCreated.

Description of the change

Remove unused IAging, inline IHasDateCreated.

To post a comment you must log in.
Revision history for this message
Celso Providelo (cprov) wrote :

Thanks for the cleanup.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/configure.zcml'
2--- lib/lp/app/configure.zcml 2012-04-17 04:28:15 +0000
3+++ lib/lp/app/configure.zcml 2016-02-05 06:46:47 +0000
4@@ -1,4 +1,4 @@
5-<!-- Copyright 2009-2011 Canonical Ltd. This software is licensed under the
6+<!-- Copyright 2009-2016 Canonical Ltd. This software is licensed under the
7 GNU Affero General Public License version 3 (see the file LICENSE).
8 -->
9
10@@ -36,12 +36,6 @@
11 provides="lp.app.interfaces.launchpad.ILaunchpadCelebrities">
12 </utility>
13
14- <!-- Configuration related to datetime classes in Launchpad. -->
15- <adapter
16- for="lp.app.interfaces.launchpad.IHasDateCreated"
17- provides="lp.app.interfaces.launchpad.IAging"
18- factory="lp.app.model.cdatetime.AgingAdapter" />
19-
20 <adapter
21 provides="lp.app.interfaces.launchpad.IPrivacy"
22 for="Exception"
23
24=== removed file 'lib/lp/app/doc/datehandling.txt'
25--- lib/lp/app/doc/datehandling.txt 2016-01-26 15:47:37 +0000
26+++ lib/lp/app/doc/datehandling.txt 1970-01-01 00:00:00 +0000
27@@ -1,61 +0,0 @@
28-Date Handling in Launchpad
29-==========================
30-
31-Time differences
32-----------------
33-
34-It's often useful to know how long ago something was created, or how long ago
35-something happened. So, let's demonstrate how this functionality can be
36-accessed in Launchpad, using the age of a bug task as an example. First, let's
37-pretend we're logged in as Sample Person:
38-
39- >>> from lp.testing import login
40- >>> login("testing@canonical.com")
41-
42-Then let's grab one of their bug tasks to work with:
43-
44- >>> from zope.component import getUtility
45- >>> from lp.bugs.interfaces.bugtask import IBugTaskSet
46- >>> bugtaskset = getUtility(IBugTaskSet)
47- >>> bt = bugtaskset.get(2)
48-
49-Then let's create a bunch of sample dates to work with:
50-
51- >>> from datetime import datetime, timedelta
52- >>> import pytz
53- >>> right_now = datetime.now(pytz.timezone('UTC'))
54- >>> one_minute_ago = right_now - timedelta(minutes = 1)
55- >>> four_hours_ago = right_now - timedelta(hours = 4)
56- >>> sixteen_days_ago = right_now - timedelta(days = 16)
57- >>> six_months_ago = right_now - timedelta(days = 180)
58- >>> one_year_ago = right_now - timedelta(days = 365)
59-
60-An IBugTask extends the interface IHasDateCreated. IHasDateCreated can be
61-adapted to IAging:
62-
63- >>> from lp.app.interfaces.launchpad import IAging
64- >>> bt.datecreated = one_minute_ago
65- >>> aging_bug = IAging(bt)
66-
67-IAging provides a method, currentApproximateAge, which returns a human-readable
68-approximation of the age of a something.
69-
70- >>> print aging_bug.currentApproximateAge()
71- 1 minute
72-
73-We're cheating a bit below (swapping in different values for datecreated, which
74-you should never do in user code) to demonstrate the various kinds of values
75-currentApproximateAge returns.
76-
77- >>> aging_bug.context.datecreated = four_hours_ago
78- >>> print aging_bug.currentApproximateAge()
79- 4 hours
80- >>> aging_bug.context.datecreated = sixteen_days_ago
81- >>> print aging_bug.currentApproximateAge()
82- 2 weeks
83- >>> aging_bug.context.datecreated = six_months_ago
84- >>> print aging_bug.currentApproximateAge()
85- 6 months
86- >>> aging_bug.context.datecreated = one_year_ago
87- >>> print aging_bug.currentApproximateAge()
88- 1 year
89
90=== modified file 'lib/lp/app/interfaces/launchpad.py'
91--- lib/lp/app/interfaces/launchpad.py 2015-11-26 15:46:38 +0000
92+++ lib/lp/app/interfaces/launchpad.py 2016-02-05 06:46:47 +0000
93@@ -1,4 +1,4 @@
94-# Copyright 2010-2012 Canonical Ltd. This software is licensed under the
95+# Copyright 2010-2016 Canonical Ltd. This software is licensed under the
96 # GNU Affero General Public License version 3 (see the file LICENSE).
97
98 """Interfaces for the Launchpad application.
99@@ -9,8 +9,6 @@
100 __metaclass__ = type
101
102 __all__ = [
103- 'IAging',
104- 'IHasDateCreated',
105 'IHasIcon',
106 'IHasLogo',
107 'IHasMugshot',
108@@ -159,17 +157,6 @@
109 mugshot = Attribute("The 192x192 mugshot.")
110
111
112-class IAging(Interface):
113- """Something that gets older as time passes."""
114-
115- def currentApproximateAge():
116- """Return a human-readable string of how old this thing is.
117-
118- Values returned are things like '2 minutes', '3 hours',
119- '1 month', etc.
120- """
121-
122-
123 class IPrivacy(Interface):
124 """Something that can be private."""
125
126@@ -180,12 +167,6 @@
127 "Private objects are visible to members or subscribers."))
128
129
130-class IHasDateCreated(Interface):
131- """Something created on a certain date."""
132-
133- datecreated = Attribute("The date on which I was created.")
134-
135-
136 class IHeadingContext(Interface):
137 """Something that appears in a page's header section.
138
139
140=== removed file 'lib/lp/app/model/cdatetime.py'
141--- lib/lp/app/model/cdatetime.py 2015-07-08 16:05:11 +0000
142+++ lib/lp/app/model/cdatetime.py 1970-01-01 00:00:00 +0000
143@@ -1,71 +0,0 @@
144-# Copyright 2009 Canonical Ltd. This software is licensed under the
145-# GNU Affero General Public License version 3 (see the file LICENSE).
146-
147-"""Date-related Launchpad components."""
148-
149-__metaclass__ = type
150-
151-from datetime import datetime
152-
153-import pytz
154-from zope.interface import implementer
155-
156-from lp.app.interfaces.launchpad import IAging
157-
158-
159-SECONDS_PER_HOUR = 3600
160-SECONDS_PER_MINUTE = 60
161-DAYS_PER_YEAR = 365
162-DAYS_PER_MONTH = 30
163-DAYS_PER_WEEK = 7
164-
165-
166-@implementer(IAging)
167-class AgingAdapter:
168- """Adapt an IHasDateCreated to an IAging."""
169-
170- def __init__(self, context):
171- self.context = context
172-
173- def currentApproximateAge(self):
174- """See `ITimeDelta`."""
175- age = ""
176- datecreated = self.context.datecreated
177- right_now = datetime.now(pytz.timezone('UTC'))
178- delta = right_now - datecreated
179- if not delta.days:
180- if delta.seconds < SECONDS_PER_HOUR:
181- # under an hour
182- minutes = delta.seconds / SECONDS_PER_MINUTE
183- age = "%d minute" % minutes
184- if minutes > 1:
185- age += "s"
186- else:
187- # over an hour
188- hours = delta.seconds / SECONDS_PER_HOUR
189- age = "%d hour" % hours
190- if hours > 1:
191- age += "s"
192- else:
193- # one or more days old
194- if delta.days >= DAYS_PER_YEAR:
195- # one or more years old
196- years = delta.days / DAYS_PER_YEAR
197- age = "%d year" % years
198- if years > 1:
199- age += "s"
200- else:
201- # under a year old
202- if delta.days > DAYS_PER_MONTH:
203- months = delta.days / DAYS_PER_MONTH
204- age = "%d month" % months
205- if months > 1:
206- age += "s"
207- else:
208- if delta.days > DAYS_PER_WEEK:
209- weeks = delta.days / DAYS_PER_WEEK
210- age = "%d week" % weeks
211- if weeks > 1:
212- age += "s"
213-
214- return age
215
216=== modified file 'lib/lp/blueprints/interfaces/specificationbranch.py'
217--- lib/lp/blueprints/interfaces/specificationbranch.py 2013-01-07 02:40:55 +0000
218+++ lib/lp/blueprints/interfaces/specificationbranch.py 2016-02-05 06:46:47 +0000
219@@ -1,4 +1,4 @@
220-# Copyright 2009 Canonical Ltd. This software is licensed under the
221+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
222 # GNU Affero General Public License version 3 (see the file LICENSE).
223
224 """Interfaces for linking Specifications and Branches."""
225@@ -21,17 +21,19 @@
226 Reference,
227 ReferenceChoice,
228 )
229-from zope.interface import Interface
230+from zope.interface import (
231+ Attribute,
232+ Interface,
233+ )
234 from zope.schema import Int
235
236 from lp import _
237-from lp.app.interfaces.launchpad import IHasDateCreated
238 from lp.blueprints.interfaces.specification import ISpecification
239 from lp.code.interfaces.branch import IBranch
240 from lp.registry.interfaces.person import IPerson
241
242
243-class ISpecificationBranch(IHasDateCreated):
244+class ISpecificationBranch(Interface):
245 """A branch linked to a specification."""
246
247 export_as_webservice_entry(as_of="beta")
248@@ -49,6 +51,7 @@
249 required=True,
250 schema=IBranch), as_of="beta")
251
252+ datecreated = Attribute("The date on which I was created.")
253 registrant = exported(
254 Reference(
255 schema=IPerson, readonly=True, required=True,
256
257=== modified file 'lib/lp/bugs/interfaces/bugbranch.py'
258--- lib/lp/bugs/interfaces/bugbranch.py 2013-01-07 02:40:55 +0000
259+++ lib/lp/bugs/interfaces/bugbranch.py 2016-02-05 06:46:47 +0000
260@@ -1,4 +1,4 @@
261-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
262+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
263 # GNU Affero General Public License version 3 (see the file LICENSE).
264
265 """Interfaces for linking BugTasks and Branches."""
266@@ -15,7 +15,10 @@
267 exported,
268 )
269 from lazr.restful.fields import ReferenceChoice
270-from zope.interface import Interface
271+from zope.interface import (
272+ Attribute,
273+ Interface,
274+ )
275 from zope.schema import (
276 Int,
277 Object,
278@@ -23,7 +26,6 @@
279 )
280
281 from lp import _
282-from lp.app.interfaces.launchpad import IHasDateCreated
283 from lp.bugs.interfaces.bugtask import IBugTask
284 from lp.bugs.interfaces.hasbug import IHasBug
285 from lp.code.interfaces.branch import IBranch
286@@ -32,7 +34,7 @@
287 from lp.services.fields import BugField
288
289
290-class IBugBranch(IHasDateCreated, IHasBug, IHasBranchTarget):
291+class IBugBranch(IHasBug, IHasBranchTarget):
292 """A branch linked to a bug."""
293
294 export_as_webservice_entry()
295@@ -57,6 +59,7 @@
296 "against the branch's product)."),
297 readonly=True)
298
299+ datecreated = Attribute("The date on which I was created.")
300 registrant = Object(
301 schema=IPerson, readonly=True, required=True,
302 title=_("The person who linked the bug to the branch"))
303
304=== modified file 'lib/lp/bugs/interfaces/bugtask.py'
305--- lib/lp/bugs/interfaces/bugtask.py 2016-01-26 15:47:37 +0000
306+++ lib/lp/bugs/interfaces/bugtask.py 2016-02-05 06:46:47 +0000
307@@ -1,4 +1,4 @@
308-# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
309+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
310 # GNU Affero General Public License version 3 (see the file LICENSE).
311
312 """Bug task interfaces."""
313@@ -79,7 +79,6 @@
314 from zope.security.interfaces import Unauthorized
315
316 from lp import _
317-from lp.app.interfaces.launchpad import IHasDateCreated
318 from lp.app.validators import LaunchpadValidationError
319 from lp.app.validators.name import name_validator
320 from lp.bugs.interfaces.bugwatch import (
321@@ -390,7 +389,7 @@
322 """
323
324
325-class IBugTask(IHasDateCreated, IHasBug, IBugTaskDelete):
326+class IBugTask(IHasBug, IBugTaskDelete):
327 """A bug needing fixing in a particular product or package."""
328 export_as_webservice_entry()
329