def email_new(self, action): data, errors = self.extractData() if errors: self.status = '\n'.join([error.error.__str__() for error in errors]) return context = aq_inner(self.context) new_attendees = utils.get_new_attendees(context, data) utils.save_attendees(context, data) utils.email_recipients(context, new_attendees) if new_attendees['internal_attendees'] or \ new_attendees['external_attendees']: addStatusMessage(self.request, "The new attendees have been added and notified.", type='info') self.request.response.redirect(self.context.REQUEST.get('URL'))
def test_get_new_attendees(self): """ """ portal = self.layer['portal'] app = self.layer['app'] z2.login(app['acl_users'], SITE_OWNER_NAME) self.register_users() event = self._create_event() data = { 'external_attendees': [ {'email': '*****@*****.**', 'name': 'Maxine Mustermann'}, {'email': '*****@*****.**', 'name': 'Jane Doe'} ], 'internal_attendees': [ 'Administrators', 'Site Administrators', 'andreas-ebersbacher', 'jan-keller', 'werner-wechsler' ] } new_attendees = utils.get_new_attendees(event, data) control_new_attendees = { 'internal_attendees': [ { 'name': 'Andreas Ebersbacher', 'email': '*****@*****.**' }, { 'name': 'Jan Keller', 'email': '*****@*****.**' }, { 'name': 'Werner Wechsler', 'email': '*****@*****.**' } ], 'groups': [ {'name': 'Administrators'}, {'name': 'Site Administrators'} ], 'external_attendees': [ {'email': '*****@*****.**', 'name': 'Maxine Mustermann'}, {'email': '*****@*****.**', 'name': 'Jane Doe'} ] } self.assertEqual(new_attendees, control_new_attendees) utils.save_attendees(event, data) new_attendees = utils.get_new_attendees(event, data) self.assertEqual(new_attendees, { 'internal_attendees': [], 'groups': [], 'external_attendees': []}) data = { 'external_attendees': [ {'email': '*****@*****.**', 'name': 'Piet Pompies'}, {'email': '*****@*****.**', 'name': 'Jane Doe'} ], 'internal_attendees': [ 'Reviewers', 'Site Administrators', 'max-musterman', 'jan-keller', ] } new_attendees = utils.get_new_attendees(event, data) control_new_attendees = { 'internal_attendees': [{'name': 'Max Musterman', 'email': '*****@*****.**'}], 'groups': [{'name': 'Reviewers'}], 'external_attendees': [{'email': '*****@*****.**', 'name': 'Piet Pompies'}]} self.assertEqual(new_attendees, control_new_attendees)