def get(self, request, format=None): """ Get all the courses. """ param = { 'offset': int(request.GET.get('offset', 0)), 'limit': int(request.GET.get('limit', 10)), 'timestamp': int(request.GET.get('timestamp', 0)), 'with_category': request.GET.get('with_category', 1), 'categories': request.GET.get('categories', '') } screen = get_screen_size(request) thumbnail_size = get_thumbnail_size(screen, position='list') categories = [each for each in param['categories'].split(',') if each] verified_courses_id = CourseMode.get_verified_option_courses() query = Course.exclude_vpc().filter(status__gte=0, course_type=0).exclude(course_id__in=verified_courses_id) if param['timestamp']: query = query.filter( modified__gt=datetime.utcfromtimestamp(param['timestamp'])) if categories: query = query.filter(category__id__in=categories).distinct() total = query.count() courses = query[param['offset']:param['offset'] + param['limit']] result = { "courses": CourseWithCategorySerializer(thumbnail_size, courses, many=True).data if param['with_category'] else CourseSerializer(thumbnail_size, courses, many=True).data, "total": total, } return Response(result)
def get(self, request, format=None): response = { 'courses': [], 'status': 'success' } courses = Course.exclude_vpc() for course in courses: course_dict = {} course_dict['id'] = course.course_id course_dict['display_name'] = course.name response['courses'].append(course_dict) return Response(response)
def get(self, request, format=None): response = {} verified_courses_id = CourseMode.get_verified_option_courses() courses = Course.exclude_vpc().filter( status__gte=0, course_type=0).exclude(course_id__in=verified_courses_id).order_by('-status', '-id') response['data'] = fill_in_courses(courses, request.user) response['status'] = 'success' # Add selected for homepage courses and add knowledge_id for knowledge # map courses homepage_course_list = HomepageCourses.objects.order_by( "order")[0:8] selected_list = [] for homepage_course in homepage_course_list: course = homepage_course.course selected_list.append(course.course_id) for course in response['data']: if course['course_id'] in selected_list: course['selected'] = True else: course['selected'] = False knowledge_list = {} knowledge_map_list = CourseInKnowledgeMap.objects.all() for c in knowledge_map_list: knowledge_list[c.course_id.course_id] = { 'id': c.map_id_id, 'level': c.level, } for course in response['data']: if course['course_id'] in knowledge_list: course['knowledge_map'] = knowledge_list[course['course_id']] else: course['knowledge_map'] = {} return Response(response)
def get(self, request, format=None): """ Get all the recent courses. """ param = { 'offset': int(request.GET.get('offset', 0)), 'limit': int(request.GET.get('limit', 10)), } screen = get_screen_size(request) thumbnail_size = get_thumbnail_size(screen, position='detail') local_tz = pytz_timezone(settings.TIME_ZONE) now = datetime.now(local_tz) recent_time = datetime(now.year, now.month, now.day, tzinfo=local_tz) recent_utc_time = recent_time.astimezone(UTC) verified_courses_id = CourseMode.get_verified_option_courses() query = Course.exclude_vpc().filter( status__gte=0, start__gt=recent_utc_time, course_type=0).exclude(course_id__in=verified_courses_id).order_by('start') total = query.count() courses = query[param['offset']:param['offset'] + param['limit']] result = { "courses": CourseSerializer(thumbnail_size, courses, many=True).data, "total": total, } return Response(result)