Commit a49c108a authored by Laurent Bachelier's avatar Laurent Bachelier

Enhancements on the event confirm/decline actions

We now use the DELETE and PUT methods to distinguish the actions.
The action does not depend anymore on the name of the submit button.
The tests are much better.

closes #576
closes #622
parent c0481871
......@@ -248,7 +248,7 @@ class EventCmd(Command):
event.add_user(added)
class EventAction(ViewAction):
def get(self):
def get(self, state=None):
user_state = None
error_message = None
confirm_message = None
......@@ -260,13 +260,9 @@ class EventAction(ViewAction):
error_message = unicode(e)
if self.ctx.user.has_perms(event.f, event.f.PERM_WRITE) and \
self.ctx.user.name in event.users:
form_action = self.ctx.req.str_POST.get('action')
if form_action:
if form_action == "Confirm":
event.users[self.ctx.user.name] = event.USER_CONFIRMED
elif form_action == "Decline":
event.users[self.ctx.user.name] = event.USER_DECLINED
self.ctx.user.name in event.users:
if state is not None:
event.users[self.ctx.user.name] = state
try:
event.save()
......@@ -285,8 +281,11 @@ class EventAction(ViewAction):
self.ctx.template_vars['stylesheets'].append('event.css')
self.ctx.res.body = self.ctx.render('event.html')
def post(self):
self.get()
def delete(self):
self.get(Event.USER_DECLINED)
def put(self):
self.get(Event.USER_CONFIRMED)
class EventsPlugin(Plugin):
def init(self):
......
......@@ -5,3 +5,15 @@ article.event ul.users li span.state {
article.event ul.users li.waiting span.state {
color: gray;
}
form.change-status {
display: inline;
}
form.accept button {
color: green;
}
form.decline button {
color: red;
}
......@@ -57,14 +57,18 @@ event_classes = {
<strong>declined</strong>.
% endif
</p>
<form method="post" action="${url | n,U,h}">
% if user_state != event.USER_CONFIRMED:
<input name="action" type="submit" value="Confirm"/>
<form class="change-status accept" method="post" action="${url | n,U,h}">
<input name="_method" type="hidden" value="PUT" />
<button type="submit">Confirm</button>
</form>
% endif
% if user_state != event.USER_DECLINED:
<input name="action" type="submit" value="Decline"/>
<form class="change-status decline" method="post" action="${url | n,U,h}">
<input name="_method" type="hidden" value="DELETE" />
<button type="submit">Decline</button>
</form>
% endif
</form>
</section>
% endif
......
......@@ -59,7 +59,9 @@ Attendees:
def test_viewEvent(self):
res = self.app.get('/event1.txt', status=200)
assert '<h3>Place</h3>' in res.body
assert 'Decline' not in res.body
assert 'Your current status' not in res.body
assert 'Accept</button>' not in res.body
assert 'Decline</button>' not in res.body
res = self.app.get('/?action=login', status=200)
form = res.form
......@@ -71,4 +73,31 @@ Attendees:
res = self.app.get('/event1.txt', status=200)
assert '<h3>Place</h3>' in res.body
assert '<strong>waiting</strong>' in res.body
assert 'Decline' in res.body
assert 'Confirm</button>' in res.body
assert 'Decline</button>' in res.body
# decline then accept ('REST' style)
res = self.app.delete('/event1.txt', status=200)
assert '<h3>Place</h3>' in res.body
assert '<strong>declined</strong>' in res.body
assert 'Confirm</button>' in res.body
assert 'Decline</button>' not in res.body
res = self.app.put('/event1.txt', status=200)
assert '<h3>Place</h3>' in res.body
assert '<strong>confirmed</strong>' in res.body
assert 'Confirm</button>' not in res.body
assert 'Decline</button>' in res.body
# same but for browsers
res = self.app.post('/event1.txt', {'_method': 'DELETE'}, status=200)
assert '<h3>Place</h3>' in res.body
assert '<strong>declined</strong>' in res.body
assert 'Confirm</button>' in res.body
assert 'Decline</button>' not in res.body
res = self.app.put('/event1.txt', {'_method': 'PUT'}, status=200)
assert '<h3>Place</h3>' in res.body
assert '<strong>confirmed</strong>' in res.body
assert 'Confirm</button>' not in res.body
assert 'Decline</button>' in res.body
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment