def create_event(): body = util.remove_non_usable_characters( util.remove_xml_header(request.data.decode("utf-8"))) content_type = request.content_type validator_factory = factory_selector.get_factory(content_type) validator = validator_factory.create_event_request_validator() validator.validate(body) event = Event.deserialize(content_type, body) #validate the authorization to create it if log.isEnabledFor(logging.DEBUG): log.debug ("create_event(): location - " + str(event.location)) authorization(event.location) manager = CalendarSynchronizer() new_event = manager.register_event(event) response_body = new_event.serialize(request.accept_mimetypes) #Notify when a new event is created _contextbroker = ContextBrokerNotificator() _contextbroker.notify_event(new_event, _contextbroker.NEW_EVENT) return Response(response_body, status=201, mimetype=request.accept_mimetypes[0][0])
def create_event(): body = util.remove_non_usable_characters( util.remove_xml_header(request.data.decode("utf-8"))) content_type = request.content_type validator_factory = factory_selector.get_factory(content_type) validator = validator_factory.create_event_request_validator() validator.validate(body) event = Event.deserialize(content_type, body) #validate the authorization to create it if log.isEnabledFor(logging.DEBUG): log.debug("create_event(): location - " + str(event.location)) authorization(event.location) manager = CalendarSynchronizer() new_event = manager.register_event(event) response_body = new_event.serialize(request.accept_mimetypes) #Notify when a new event is created _contextbroker = ContextBrokerNotificator() _contextbroker.notify_event(new_event, _contextbroker.NEW_EVENT) return Response(response_body, status=201, mimetype=request.accept_mimetypes[0][0])
def delete_event(event_id): manager = CalendarSynchronizer() #before to remoe it, we need to collect the event to know the location, we don't want to delegate this action to the CalendarSynchronizer #if we didn't want to create two calls to the calendar, we will need to translate this validation to the CalendarSynchronizer event = manager.get_event(event_id) if event is None: return Response('Not Found Event', status=404) #validate the authorization to delete it authorization(event.location) status = manager.remove_event(event_id) if status: #Notify when a new event is created _contextbroker = ContextBrokerNotificator() _contextbroker.notify_event(event, _contextbroker.DELETED_EVENT) return Response(status=204) else: return Response('Not Found Event', status=404)