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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
= AnnouncementDateWidget =
This widget combines radio buttons and a DateTimeWidget. It allows you to
choose to publish an announcement immediately, at a predetermined date in the
future, or to manually publish it later.
>>> from zope.schema import Field
>>> from lp.testing.pages import extract_text
>>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest
>>> from lp.app.widgets.announcementdate import AnnouncementDateWidget
>>> field = Field(__name__='foo', title=u'Foo')
>>> widget = AnnouncementDateWidget(field, LaunchpadTestRequest())
>>> print extract_text(widget())
Publish this announcement:
Immediately
At some time in the future when I come back to authorize it
At this specific date and time:
in time zone: UTC
When you choose to publish at a specific date in the future, the widget will
return the date you specified.
>>> action_widget = widget.action_widget
>>> action_widget.request.form[action_widget.name] = 'specific'
>>> date_widget = widget.announcement_date_widget
>>> date_widget.request.form[date_widget.name] = '2005-07-23'
>>> print widget.getInputValue()
2005-07-23 00:00:00+00:00
When you choose to publish immediately, the widget will return the current
date and time.
>>> from datetime import datetime, timedelta
>>> import pytz
>>> action_widget.request.form[action_widget.name] = 'immediately'
>>> date_widget.request.form[date_widget.name] = ''
>>> now = datetime.now(pytz.utc)
>>> before = now - timedelta(1) # 1 day
>>> after = now + timedelta(1) # 1 day
>>> immediate_date = widget.getInputValue()
>>> print repr(immediate_date)
datetime.datetime(...)
>>> before < immediate_date < after
True
When you choose to publish manually at some time in the future, the widget
won't return a date.
>>> action_widget.request.form[action_widget.name] = 'sometime'
>>> date_widget.request.form[date_widget.name] = '2005-07-23'
>>> print widget.getInputValue()
None
If you choose to publish immediately, the date field must be empty.
>>> action_widget.request.form[action_widget.name] = 'immediately'
>>> date_widget.request.form[date_widget.name] = '2005-07-23'
>>> print widget.getInputValue()
Traceback (most recent call last):
...
WidgetInputError: ('field.foo', u'Foo',
LaunchpadValidationError(u'Please do not provide a date
if you want to publish
immediately.'))
If you choose to publish at a specific date in the future, the date field
must be filled.
>>> action_widget.request.form[action_widget.name] = 'specific'
>>> date_widget.request.form[date_widget.name] = ''
>>> print widget.getInputValue()
Traceback (most recent call last):
...
WidgetInputError: ('field.foo', u'Foo',
LaunchpadValidationError(u'Please provide a publication date.'))
|