def reclassify_member(request, course_prefix, course_suffix): """This view allows course admins to reclassify a course member as a student/ta/readonly-ta/instructor""" course = request.common_page_data['course'] username = request.POST.get('username') # will be one of "student", "instructor", "ta", "readonly_ta" to_group = request.POST.get('to_group') #validate username try: user = User.objects.get(username=username) except User.DoesNotExist: messages.add_message( request, messages.ERROR, 'Username "%s" does not correspond to a user in the system' % username) return HttpResponseRedirect( reverse('courses.member_management.views.listAll', args=[course_prefix, course_suffix]) + "#students") if not is_member_of_course(course, user): messages.add_message( request, messages.ERROR, 'User "%s" is not a member of this course!' % username) return HttpResponseRedirect( reverse('courses.member_management.views.listAll', args=[course_prefix, course_suffix]) + "#students") #validate to_group poss_groups = { "students": course.student_group, "instructors": course.instructor_group, "tas": course.tas_group, "readonly_tas": course.readonly_tas_group } if to_group not in poss_groups: messages.add_message( request, messages.ERROR, 'You have specified an invalid course role for this course member %s' % username) return HttpResponseRedirect( reverse('courses.member_management.views.listAll', args=[course_prefix, course_suffix]) + "#students") for desc, group in poss_groups.iteritems(): if to_group == desc: group.user_set.add(user) else: group.user_set.remove(user) messages.add_message( request, messages.INFO, 'Successfully made %s a %s for %s' % (username, to_group, course.title)) return HttpResponseRedirect( reverse('courses.member_management.views.listAll', args=[course_prefix, course_suffix]) + "#" + to_group)
def add_student_task(request, course, new_student_email, send_email, batched=False): """ This is a factored-out helper function that takes an email address of an invited student and determines whether to add the student to the course or send the student an email about creating an account, etc. This has been made into a celery task. Calling this task with using a dummy/stripped down request would be useful to reduce pickled datastructure size. The task should be called with batched=True and a request that only needs to be used for build_absolute_uri (has META['HTTP_HOST']) """ #First search for matching students new_students = User.objects.filter( Q(username__iexact=new_student_email) | Q(email__iexact=new_student_email)) if new_students.exists(): #this is the case where we don't need to create users for student in new_students: if not is_member_of_course(course, student): course.student_group.user_set.add(student) if send_email: email_existing_student_enrollment(request, course, student) if not batched: messages.add_message( request, messages.INFO, 'Successfully enrolled student %s in course' % student.username) else: if not batched: messages.add_message( request, messages.WARNING, 'Student %s is already a course member' % student.username) else: #this is the case where there is no existing user, so we send an invitation invite, created = StudentInvitation.objects.get_or_create( course=course, email=new_student_email) if created and not batched: messages.add_message(request, messages.INFO, 'Successfully invited student %s to create a Class2Go account for the course' \ % new_student_email) elif not batched: messages.add_message(request, messages.WARNING, '%s has already been invited to the course. An invitation email has been re-sent' \ % new_student_email) #in the case of an invitation to create a new account, we have to send email no matter the checkbox email_new_student_invite(request, invite)
def home(request): now = datetime.now() courses = Course.objects.filter(calendar_start__gt=now, mode="production") available_course_list = [] for course in courses: if is_member_of_course(course, request.user): course_student_member = 'True' else: course_student_member = 'False' viewable_handle = course.handle.replace('#$!', '/') available_course_list.append((course.title, course.handle, viewable_handle, course_student_member)) return render_to_response('courses/signup.html', {'request': request, 'available_course_list': available_course_list}, context_instance=RequestContext(request))
def home(request): #try: # common_page_data = get_common_page_data(request, course_prefix, course_suffix) #except: raise Http404 now = datetime.now() courses = Course.objects.filter(calendar_start__gt=now, mode="ready") available_course_list = [] for course in courses: if is_member_of_course(course, request.user): course_student_member = 'True' else: course_student_member = 'False' viewable_handle = course.handle.replace('--', '/') available_course_list.append((course.title, course.handle, viewable_handle, course_student_member)) return render_to_response('courses/signup.html', {'request': request, 'available_course_list': available_course_list}, context_instance=RequestContext(request))
def add_student_task(request, course, new_student_email, send_email, batched=False): """ This is a factored-out helper function that takes an email address of an invited student and determines whether to add the student to the course or send the student an email about creating an account, etc. This has been made into a celery task. Calling this task with using a dummy/stripped down request would be useful to reduce pickled datastructure size. The task should be called with batched=True and a request that only needs to be used for build_absolute_uri (has META['HTTP_HOST']) """ #First search for matching students new_students = User.objects.filter(Q(username__iexact=new_student_email) | Q(email__iexact=new_student_email)) if new_students.exists(): #this is the case where we don't need to create users for student in new_students: if not is_member_of_course(course, student): course.student_group.user_set.add(student) if send_email: email_existing_student_enrollment(request, course, student) if not batched: messages.add_message(request, messages.INFO, 'Successfully enrolled student %s in course' % student.username) else: if not batched: messages.add_message(request, messages.WARNING, 'Student %s is already a course member' % student.username) else: #this is the case where there is no existing user, so we send an invitation invite, created = StudentInvitation.objects.get_or_create(course=course, email=new_student_email) if created and not batched: messages.add_message(request, messages.INFO, 'Successfully invited student %s to create a Class2Go account for the course' \ % new_student_email) elif not batched: messages.add_message(request, messages.WARNING, '%s has already been invited to the course. An invitation email has been re-sent' \ % new_student_email) #in the case of an invitation to create a new account, we have to send email no matter the checkbox email_new_student_invite(request,invite)
def home(request): #try: # common_page_data = get_common_page_data(request, course_prefix, course_suffix) #except: raise Http404 now = datetime.now() courses = Course.objects.filter(calendar_start__gt=now, mode="ready") available_course_list = [] for course in courses: if is_member_of_course(course, request.user): course_student_member = 'True' else: course_student_member = 'False' viewable_handle = course.handle.replace('--', '/') available_course_list.append((course.title, course.handle, viewable_handle, course_student_member)) return render_to_response('courses/signup.html', { 'request': request, 'available_course_list': available_course_list }, context_instance=RequestContext(request))
def reclassify_member(request, course_prefix, course_suffix): """This view allows course admins to reclassify a course member as a student/ta/readonly-ta/instructor""" course = request.common_page_data['course'] username = request.POST.get('username') # will be one of "student", "instructor", "ta", "readonly_ta" to_group = request.POST.get('to_group') #validate username try: user = User.objects.get(username=username) except User.DoesNotExist: messages.add_message(request, messages.ERROR, 'Username "%s" does not correspond to a user in the system' % username) return HttpResponseRedirect(reverse('courses.member_management.views.listAll', args=[course_prefix, course_suffix]) + "#students") if not is_member_of_course(course, user): messages.add_message(request, messages.ERROR, 'User "%s" is not a member of this course!' % username) return HttpResponseRedirect(reverse('courses.member_management.views.listAll', args=[course_prefix, course_suffix]) + "#students") #validate to_group poss_groups = { "students" : course.student_group, "instructors" : course.instructor_group, "tas" : course.tas_group, "readonly_tas" : course.readonly_tas_group } if to_group not in poss_groups: messages.add_message(request, messages.ERROR, 'You have specified an invalid course role for this course member %s' % username) return HttpResponseRedirect(reverse('courses.member_management.views.listAll', args=[course_prefix, course_suffix]) + "#students") for desc, group in poss_groups.iteritems(): if to_group == desc: group.user_set.add(user) else: group.user_set.remove(user) messages.add_message(request, messages.INFO, 'Successfully made %s a %s for %s' % (username, to_group, course.title)) return HttpResponseRedirect(reverse('courses.member_management.views.listAll', args=[course_prefix, course_suffix]) + "#" + to_group)