def post(self, request, group_id): """ POST /api/groups/{group_id}/courses/ """ response_data = {} try: existing_group = Group.objects.get(id=group_id) except ObjectDoesNotExist: return Response({}, status.HTTP_404_NOT_FOUND) course_id = request.DATA['course_id'] base_uri = generate_base_uri(request) response_data['uri'] = '{}/{}'.format(base_uri, course_id) existing_course, course_key, course_content = get_course(request, request.user, course_id) # pylint: disable=W0612 if not existing_course: return Response({}, status.HTTP_404_NOT_FOUND) try: existing_relationship = CourseGroupRelationship.objects.get(course_id=course_id, group=existing_group) except ObjectDoesNotExist: existing_relationship = None if existing_relationship is None: new_relationship = CourseGroupRelationship.objects.create(course_id=course_id, group=existing_group) response_data['group_id'] = str(new_relationship.group_id) response_data['course_id'] = str(new_relationship.course_id) response_status = status.HTTP_201_CREATED else: response_data['message'] = "Relationship already exists." response_status = status.HTTP_409_CONFLICT return Response(response_data, status=response_status)
def handle(self, *args, **options): request_factory = RequestFactory() request = request_factory.get('/') request.user = User(email='*****@*****.**', username='******', password='******', is_active=True) projects = Project.objects.all() for project in projects: course_descriptor, course_key, course_content = get_course(request, request.user, project.course_id) project.course_id = unicode(course_key) try: project.content_id = course_key.make_usage_key_from_deprecated_string(project.content_id) except InvalidKeyError: log.warning( 'Unable to convert content_id "{}"'.format(project.content_id), exc_info=True ) pass # If the key conversion fails it was either a new-style key or junk data project.save() workgroup_reviews = WorkgroupReview.objects.all() for wr in workgroup_reviews: course_id = wr.workgroup.project.course_id course_descriptor, course_key, course_content = get_course(request, request.user, course_id) try: wr.content_id = course_key.make_usage_key_from_deprecated_string(wr.content_id) except InvalidKeyError: log.warning( 'Unable to convert content_id "{}"'.format(wr.content_id), exc_info=True ) pass # If the key conversion fails it was either a new-style key or junk data wr.save() workgroup_submission_reviews = WorkgroupSubmissionReview.objects.all() for wsr in workgroup_submission_reviews: course_id = wsr.submission.workgroup.project.course_id course_descriptor, course_key, course_content = get_course(request, request.user, course_id) try: wsr.content_id = course_key.make_usage_key_from_deprecated_string(wsr.content_id) except InvalidKeyError: log.warning( 'Unable to convert content_id "{}"'.format(wsr.content_id), exc_info=True ) pass # If the key conversion fails it was either a new-style key or junk data wsr.save()
def handle(self, *args, **options): request_factory = RequestFactory() request = request_factory.get('/') request.user = User(email='*****@*****.**', username='******', password='******', is_active=True) course_groups = api_models.CourseGroupRelationship.objects.all() for cg in course_groups: course_id = cg.course_id course_descriptor, course_key, course_content = get_course(request, request.user, course_id) cg.course_id = unicode(course_key) cg.save() course_content_groups = api_models.CourseContentGroupRelationship.objects.all() for ccg in course_content_groups: course_id = ccg.course_id course_descriptor, course_key, course_content = get_course(request, request.user, course_id) ccg.course_id = unicode(course_key) try: ccg.content_id = course_key.make_usage_key_from_deprecated_string(ccg.content_id) except InvalidKeyError: log.warning( 'Unable to convert content_id "{}"'.format(ccg.content_id), exc_info=True ) pass # If the key conversion fails it was either a new-style key or junk data ccg.save() course_module_completions = CourseModuleCompletion.objects.all() for cmc in course_module_completions: course_id = cmc.course_id course_descriptor, course_key, course_content = get_course(request, request.user, course_id) cmc.course_id = unicode(course_key) try: cmc.content_id = course_key.make_usage_key_from_deprecated_string(cmc.content_id) except InvalidKeyError: log.warning( 'Unable to convert content_id "{}"'.format(cmc.content_id), exc_info=True ) pass # If the key conversion fails it was either a new-style key or junk data cmc.save()
def get(self, request, group_id): """ GET /api/groups/{group_id}/courses/ """ response_data = {} try: existing_group = Group.objects.get(id=group_id) except ObjectDoesNotExist: return Response({}, status.HTTP_404_NOT_FOUND) members = CourseGroupRelationship.objects.filter(group=existing_group) response_data = [] for member in members: course, course_key, course_content = get_course(request, request.user, member.course_id) # pylint: disable=W0612 course_data = { 'course_id': member.course_id, 'display_name': course.display_name } response_data.append(course_data) response_status = status.HTTP_200_OK return Response(response_data, status=response_status)
def handle(self, *args, **options): request_factory = RequestFactory() request = request_factory.get('/') request.user = User(email='*****@*****.**', username='******', password='******', is_active=True) projects = project_models.Project.objects.all() for project in projects: course_descriptor, course_key, course_content = get_course(request, request.user, project.course_id) project.course_id = unicode(course_key) try: project.content_id = course_key.make_usage_key_from_deprecated_string(project.content_id) except InvalidKeyError: pass # If the key conversion fails it was either a new-style key or junk data project.save() workgroup_reviews = project_models.WorkgroupReview.objects.all() for wr in workgroup_reviews: course_id = wr.workgroup.project.course_id course_descriptor, course_key, course_content = get_course(request, request.user, course_id) try: wr.content_id = course_key.make_usage_key_from_deprecated_string(wr.content_id) except InvalidKeyError: pass # If the key conversion fails it was either a new-style key or junk data wr.save() workgroup_submission_reviews = project_models.WorkgroupSubmissionReview.objects.all() for wsr in workgroup_submission_reviews: course_id = wsr.submission.workgroup.project.course_id course_descriptor, course_key, course_content = get_course(request, request.user, course_id) try: wsr.content_id = course_key.make_usage_key_from_deprecated_string(wsr.content_id) except InvalidKeyError: pass # If the key conversion fails it was either a new-style key or junk data wsr.save() course_groups = api_models.CourseGroupRelationship.objects.all() for cg in course_groups: course_id = cg.course_id course_descriptor, course_key, course_content = get_course(request, request.user, course_id) cg.course_id = unicode(course_key) cg.save() course_content_groups = api_models.CourseContentGroupRelationship.objects.all() for ccg in course_content_groups: course_id = ccg.course_id course_descriptor, course_key, course_content = get_course(request, request.user, course_id) ccg.course_id = unicode(course_key) try: ccg.content_id = course_key.make_usage_key_from_deprecated_string(ccg.content_id) except InvalidKeyError: pass # If the key conversion fails it was either a new-style key or junk data ccg.save() course_module_completions = api_models.CourseModuleCompletion.objects.all() for cmc in course_module_completions: course_id = cmc.course_id course_descriptor, course_key, course_content = get_course(request, request.user, course_id) cmc.course_id = unicode(course_key) try: cmc.content_id = course_key.make_usage_key_from_deprecated_string(cmc.content_id) except InvalidKeyError: pass # If the key conversion fails it was either a new-style key or junk data cmc.save()