def list_presentations_for_course(self, course_identifier, all=False): """List all presentations for a given course :param course_identifier: ID of the course :param all: (optional) list ALL presentations, by default only presentations that start in the future :return list of presentations """ q = {'fq': 'course_identifier:{id}'.format(id=course_identifier), 'sort': 'presentation_start asc'} if all: q['q'] = '*:*' else: q['q'] = 'NOT presentation_start:[* TO NOW]' results = searcher.search(q, start=0, count=1000) # Do not paginate if results.results: course = presentations_to_course_object(results.results) reference = course.presentations[0] # "augmenting" our results with "live" information from providers try: provider = self.get_provider(reference) except ProviderException: logger.debug('No single provider found for: %s' % reference.id) else: provider_information = provider.get_course(reference) if provider_information: pass # TODO augment data // or replace? else: return None
def search_courses(self, search, start, count, all=False): """Search for courses :param search: search query (FTS) :param all: (optional) all courses even starting in the past :return list of courses (titles and identifiers) """ # TODO search parameters for Solr. Should be made generic. Discuss. q = {'q': search, 'group': 'true', 'group.field': 'course_identifier', 'group.count': '1', 'group.ngroups': 'true', # 'fl': 'course_title,course_identifier,course_description', } if not all: q['q'] += ' AND NOT presentation_start:[* TO NOW]' try: results = searcher.search(q, start=start, count=count) except SearchServerException: raise ApplicationException() courses = [] for group in results.as_dict['grouped']['course_identifier']['groups']: courses.append(presentations_to_course_object(group['doclist']['docs'])) return courses, results.as_dict['grouped']['course_identifier']['ngroups']