def migrate(request): if not request.course.is_faculty(request.user): return HttpResponseForbidden("forbidden") if request.method == "GET": # Only show courses for which the user is an instructor available_courses = available_courses_query(request.user) courses = [] if request.user.is_superuser: courses = available_courses else: for c in available_courses: if c.is_faculty(request.user): courses.append(c) if request.method == "GET": return { "available_courses": courses, "help_migrate_materials": False } elif request.method == "POST": # maps old ids to new objects object_map = {'assets': {}, 'notes': {}, 'projects': {}} if 'asset_set' in request.POST: asset_set = simplejson.loads(request.POST.get('asset_set')) object_map = Asset.objects.migrate(asset_set, request.course, request.user, object_map) if 'project_set' in request.POST: project_set = simplejson.loads(request.POST.get('project_set')) object_map = Project.objects.migrate(project_set, request.course, request.user, object_map) json_stream = simplejson.dumps({ 'success': True, 'asset_count': len(object_map['assets']), 'project_count': len(object_map['projects']), 'note_count': len(object_map['notes'])}) return HttpResponse(json_stream, mimetype='application/json')
def get_context_data(self, **kwargs): # Only show courses for which the user is an instructor available_courses = available_courses_query(self.request.user) courses = [] if self.request.user.is_superuser: courses = available_courses else: for course in available_courses: if cached_course_is_faculty(course, self.request.user): courses.append(course) # Only send down the real faculty. Not all us staff members faculty = [] for user in self.request.course.faculty.all(): faculty.append(user) return { "current_course_faculty": faculty, "available_courses": courses }
def migrate(request): if request.method == "GET": # Only show courses for which the user is an instructor available_courses = available_courses_query(request.user) courses = [] if request.user.is_superuser: courses = available_courses else: for c in available_courses: if c.is_faculty(request.user): courses.append(c) # Only send down the real faculty. Not all us staff members faculty = [] for u in request.course.faculty.all(): if u in request.course.members: faculty.append(u) return { "current_course_faculty": faculty, "available_courses": courses, "help_migrate_materials": False } elif request.method == "POST": # maps old ids to new objects object_map = {'assets': {}, 'notes': {}, 'note_count': 0, 'projects': {}} owner = request.user if 'on_behalf_of' in request.POST: owner = User.objects.get(id=request.POST.get('on_behalf_of')) if (not in_course(owner.username, request.course) or not request.course.is_faculty(owner)): json_stream = simplejson.dumps({ 'success': False, 'message': '%s is not a course member or faculty member'}) return HttpResponse(json_stream, mimetype='application/json') if 'asset_set' in request.POST: asset_set = simplejson.loads(request.POST.get('asset_set')) object_map = Asset.objects.migrate(asset_set, request.course, owner, object_map) if 'project_set' in request.POST: project_set = simplejson.loads(request.POST.get('project_set')) object_map = Project.objects.migrate(project_set, request.course, owner, object_map) json_stream = simplejson.dumps({ 'success': True, 'asset_count': len(object_map['assets']), 'project_count': len(object_map['projects']), 'note_count': object_map['note_count']}) return HttpResponse(json_stream, mimetype='application/json')
def migrate(request): if request.method == "GET": # Only show courses for which the user is an instructor available_courses = available_courses_query(request.user) courses = [] if request.user.is_superuser: courses = available_courses else: for course in available_courses: if course.is_faculty(request.user): courses.append(course) # Only send down the real faculty. Not all us staff members faculty = [] for user in request.course.faculty.all(): if user in request.course.members: faculty.append(user) # Only send down the real faculty. Not all us staff members faculty = [] for fac in request.course.faculty.all(): if fac in request.course.members: faculty.append(fac) return { "current_course_faculty": faculty, "available_courses": courses, "help_migrate_materials": False } elif request.method == "POST": # maps old ids to new objects object_map = {'assets': {}, 'notes': {}, 'note_count': 0, 'projects': {}} owner = request.user if 'on_behalf_of' in request.POST: owner = User.objects.get(id=request.POST.get('on_behalf_of')) if (not in_course(owner.username, request.course) or not request.course.is_faculty(owner)): json_stream = simplejson.dumps({ 'success': False, 'message': '%s is not a course member or faculty member'}) return HttpResponse(json_stream, mimetype='application/json') if 'asset_set' in request.POST: asset_set = simplejson.loads(request.POST.get('asset_set')) object_map = Asset.objects.migrate(asset_set, request.course, owner, object_map) if 'project_set' in request.POST: project_set = simplejson.loads(request.POST.get('project_set')) object_map = Project.objects.migrate(project_set, request.course, owner, object_map) json_stream = simplejson.dumps({ 'success': True, 'asset_count': len(object_map['assets']), 'project_count': len(object_map['projects']), 'note_count': object_map['note_count']}) return HttpResponse(json_stream, mimetype='application/json')