def decide(self): """Decide the current agendaitem and move the meeting in the held state. """ self.require_editable() meeting_state = self.meeting.get_state() error_response = self._checkin_proposal_document_before_deciding() if error_response: return error_response self.agenda_item.decide() response = JSONResponse(self.request) response.info( _(u'agenda_item_decided', default=u'Agenda Item decided.')) if meeting_state != self.meeting.get_state(): response.redirect(self.context.absolute_url()) msg = _( u'agenda_item_meeting_held', default= u"Agendaitem has been decided and the meeting has been held.") api.portal.show_message(message=msg, request=self.request, type='info') return response.dump()
def __call__(self): transition = self.request.get('transition') response = JSONResponse(self.request) errors = self.get_transition_validation_errors(transition) if errors: map(response.error, errors) response.remain() elif not self.is_valid_transition(transition): raise BadRequest() else: self.execute_transition(transition) response.info( _('label_transition_executed', default='Transition ${transition} executed', mapping={ 'transition': self.model.workflow.transitions.get(transition).title })) response.redirect(self.model.get_url()) return response.dump()
class TestUnitJSONResponse(IntegrationTestCase): def setUp(self): super(TestUnitJSONResponse, self).setUp() self.response = JSONResponse(self.request) self.info_message = _('infomessage') self.warning_message = _('warningmessage') self.error_message = _('errormessage') def test_empty_jsonresponse(self): self.assertEqual(self.response.dump(), '{}') def test_info_message(self): self.assertEqual( self.response.info(self.info_message).dump(), json.dumps({ 'messages': [{ 'messageClass': 'info', 'messageTitle': 'Information', 'message': 'infomessage', }] })) def test_warning_message(self): self.assertEqual( self.response.warning(self.warning_message).dump(), json.dumps({ 'messages': [{ 'messageClass': 'warning', 'messageTitle': 'Warning', 'message': 'warningmessage', }] })) def test_error_message(self): self.assertEqual( self.response.error(self.error_message).dump(), json.dumps({ 'messages': [{ 'messageClass': 'error', 'messageTitle': 'Error', 'message': 'errormessage', }] })) def test_multiple_messages(self): self.assertEqual( self.response.error(self.error_message).info( self.info_message).error(self.error_message).dump(), json.dumps({ 'messages': [{ 'messageClass': 'error', 'messageTitle': 'Error', 'message': 'errormessage', }, { 'messageClass': 'info', 'messageTitle': 'Information', 'message': 'infomessage', }, { 'messageClass': 'error', 'messageTitle': 'Error', 'message': 'errormessage', }] })) def test_custom_data(self): self.assertEqual( self.response.data(name='peter').dump(), json.dumps({'name': 'peter'})) def test_multiple_custom_data(self): self.assertEqual( self.response.data(name='peter', foo=123, bar=None).dump(), json.dumps({ 'name': 'peter', 'foo': 123, 'bar': None })) def test_protected_data_throws_assertion_error(self): with self.assertRaises(AssertionError): self.response.data(messages='peter') with self.assertRaises(AssertionError): self.response.data(proceed='peter') def test_proceed(self): self.assertEqual(self.response.proceed().dump(), json.dumps({'proceed': True})) def test_remain(self): self.assertEqual(self.response.remain().dump(), json.dumps({'proceed': False})) def test_full_response(self): self.assertEqual( self.response.data(name='peter').info(self.info_message).error( self.error_message).proceed().dump(), json.dumps({ 'messages': [{ 'messageTitle': 'Information', 'message': 'infomessage', 'messageClass': 'info' }, { 'messageTitle': 'Error', 'message': 'errormessage', 'messageClass': 'error' }], 'name': 'peter', 'proceed': True })) def test_dump_disables_caching_by_default(self): # By default we disable chaing of all responses. # This is especially important for IE 11 support. self.response.remain().dump() self.assertEquals( { 'content-type': 'application/json', 'cache-control': 'no-store', 'pragma': 'no-cache', 'expires': '0' }, self.request.response.headers) def test_dump_without_disabling_caches(self): # Dump can optionally be told to not send no-caching headers. self.response.remain().dump(no_cache=False) self.assertEquals({'content-type': 'application/json'}, self.request.response.headers)