misc: update to new CheckboxesWidget __init__ signature (#13386)

This commit is contained in:
Frédéric Péters 2016-10-02 17:51:52 +02:00
parent 08f8a5b6c2
commit d8827fced1
3 changed files with 68 additions and 7 deletions

View File

@ -236,16 +236,16 @@ class AgendaDirectory(Directory):
if tags and remote_calendars:
form.widgets.append(HtmlWidget('<table id="agenda-filter"><tr><td>'))
if tags:
form.add(CheckboxesWidget, 'tags', title = _('Tags'),
elements = [(x,x) for x in tags],
inline = False)
form.add(CheckboxesWidget, 'tags', title=_('Tags'),
options=[(x,x) for x in tags],
inline=False)
if tags and remote_calendars:
form.widgets.append(HtmlWidget('</td><td>'))
if remote_calendars:
remote_calendars.sort(lambda x,y: cmp(x.label, y.label))
form.add(CheckboxesWidget, 'calendars', title = _('Calendars'),
elements = [('local', _('Local'))] + [(x.id, x.label) for x in remote_calendars],
inline = False)
form.add(CheckboxesWidget, 'calendars', title=_('Calendars'),
options=[('local', _('Local'))] + [(x.id, x.label) for x in remote_calendars],
inline=False)
if tags and remote_calendars:
form.widgets.append(HtmlWidget('</td></tr></table>'))

View File

@ -707,7 +707,7 @@ class MyspaceDirectory(wcs.myspace.MyspaceDirectory):
form = Form(enctype = 'multipart/form-data')
form.add(CheckboxesWidget, 'themes', title=_('Announce Themes'),
value=enabled_themes, elements=options,
value=enabled_themes, options=[(x, x) for x in options],
inline=False, required=False)
form.add_submit('submit', _('Apply Changes'))

View File

@ -119,3 +119,64 @@ def test_myspace_with_user_forms():
resp = resp.follow(status=302)
resp.location.startswith('http://example.net/cat/test/?mt=')
resp = resp.follow(status=403)
def test_announces():
from modules.announces import Announce, AnnounceSubscription
if not 'misc' in pub.cfg:
pub.cfg['misc'] = {}
pub.cfg['misc']['announce_themes'] = ['Foo', 'Bar']
pub.write_cfg()
announce = Announce()
announce.title = 'Hello World'
announce.text = 'Lorem ipsum...'
announce.publication_time = time.gmtime(time.time()-100000)
announce.store()
user = create_user()
app = login(get_app(pub), username='user', password='user')
resp = app.get('/announces/', status=200)
resp = resp.click('Receiving those Announces')
resp = resp.click('Email')
assert 'You are logged in but there is no email address in your profile.' in resp.body
assert 'email' in resp.form.fields
user.email = 'foo@localhost'
user.store()
resp = app.get('/announces/email', status=200)
assert 'foo@localhost' in resp.body
assert not 'email' in resp.form.fields
resp = resp.form.submit()
assert AnnounceSubscription.count() == 1
resp = app.get('/myspace/', status=200)
resp = resp.click('Edit my Subscription to Announces')
assert resp.form['themes$elementFoo'].checked
assert resp.form['themes$elementBar'].checked
resp.form['themes$elementFoo'].checked = False
resp = resp.form.submit('submit')
assert AnnounceSubscription.count() == 1
resp = app.get('/myspace/announces', status=200)
assert not resp.form['themes$elementFoo'].checked
assert resp.form['themes$elementBar'].checked
def test_agenda():
from modules.events import Event, RemoteCalendar
remote_calendar = RemoteCalendar()
remote_calendar.label = 'Remote'
remote_calendar.store()
event = Event()
event.title = 'Hello World'
event.description = 'Lorem ipsum...'
event.date_start = time.strptime('2016-09-10', '%Y-%m-%d')
event.date_end = time.strptime('2016-09-12', '%Y-%m-%d')
event.store()
app = get_app(pub)
resp = app.get('/agenda/', status=200)
resp = app.get('/agenda/filter')
assert 'tags$elementAdults' in resp.form.fields
assert 'calendars$elementlocal' in resp.form.fields