def withdraw(self, id, user_signer): """Withdraw the authenticated from a presentation they're enrolled on. This is quite convoluted but the best way to avoid exposing any implementation details to the user. We get the presentation they are trying to withdraw from, check to see they're actually enrolled on it and we have a provider for that presentation. Then we hand over to the provider to issue the withdrawal. :param id: unique identifier of the presentation :param user_signer: oAuth token of the user :return True if withdrawing from the course succeeded else False """ result = searcher.get_by_ids([id]) course = presentation_to_presentation_object(result.results[0]) presentation = course.presentations[0] user_courses = self.my_courses(user_signer) try: ucourse = filter(lambda c: c.id == course.id, user_courses)[0] upres = filter(lambda p: p.id == presentation.id, ucourse.presentations)[0] except IndexError: logger.warn("Attempt to withdraw from a course the user may not be registered on", extra={'presentation_id': id}) return False try: provider = self.get_provider(presentation) except ProviderException: logger.info("No provider found to withdraw presentation.", extra={'presentation_id': id}) return False else: return provider.withdraw(upres.booking_id, user_signer)
def get_event(self, uid): """Get an event by its unique identifier :param uid: identifier of the event :return: Event domain object or None if not found """ docs = searcher.get_by_ids([uid]) if docs.results: return Event.from_solr_dict(docs.results[0]) else: return None
def book_presentation(self, id, message, user_signer, supervisor_email=None): """Book a presentation :param id: unique identifier of the presentation :param message: message to book the presentation :param user_signer: oAuth token of the user :param supervisor_email: (optional) email of the supervisor :return True if booking succeeded else False """ result = searcher.get_by_ids([id]) course = presentation_to_presentation_object(result.results[0]) presentation = course.presentations[0] try: provider = self.get_provider(presentation) except ProviderException: logger.info("No provider found to book presentation.", extra={'presentation_id': id}) return False else: return provider.book(presentation, message, user_signer, supervisor_email)