def write_lab_hour_assignment_data(csv_writer, semester): semester_has_assigned_lab_hours = False year, semester_code = get_year_and_semester_code(semester) lab_hour_assignments = Semester.objects.get( year=year, semester_code=semester_code).lab_hour_assignments for idx, row in enumerate(lab_hour_assignments): row_to_write = [] for eagle_id in row: if eagle_id: semester_has_assigned_lab_hours = True name = Profile.objects.get(eagle_id=eagle_id).full_name row_to_write.append(name) else: row_to_write.append('-') if is_hour(idx): hour_string = get_hour_string(idx) row_to_write.append(hour_string) else: row_to_write.append('') csv_writer.writerow(row_to_write) if not semester_has_assigned_lab_hours: raise ValueError( f'The semester ({get_verbose_semester(semester)}) has no ' + 'teaching assistants to which any lab hours have been assigned') last_row = ['' for _ in range(7)] last_row.append('12:00 AM') csv_writer.writerow(last_row) return csv_writer
def get_semester(course_data): year, semester_code = get_year_and_semester_code(course_data['semester']) try: semester = Semester.objects.get(year=year, semester_code=semester_code) except Semester.DoesNotExist: semester = Semester(year=year, semester_code=semester_code) semester.save() return semester
def home(request): if request.method not in ('GET', 'POST'): return handle_bad_request(request, app='ta_system', expected='GET, POST') current_semester = utils.get_current_semester() app_form = ApplicationForm() context = { 'system_is_open': SystemStatus.objects.order_by('id').last(), 'app_form': app_form, 'current_semester': utils.get_verbose_semester(current_semester) } user = request.user student = Profile.objects.get(user=user) if request.method == 'POST': app_form = ApplicationForm(request.POST) if app_form.is_valid(): year, semester_code = utils.get_year_and_semester_code(current_semester) semester = Semester.objects.get(year=year, semester_code=semester_code) course_preferences = [app_form.cleaned_data.get('course1'), app_form.cleaned_data.get('course2'), app_form.cleaned_data.get('course3')] instructor_preferences = [app_form.cleaned_data.get('prof1'), app_form.cleaned_data.get('prof2'), app_form.cleaned_data.get('prof3')] major = app_form.cleaned_data.get('major') grad_year = app_form.cleaned_data.get('grad_year') preferences = app_form.cleaned_data.get('lab_hour_data') if utils.is_valid_preferences(preferences): utils.save_preferences(student, preferences) else: messages.error( request, 'Error: Please specify which times you ' + 'would be available to tend the CS Lab.' ) app = Application(applicant=student, semester=semester, course_preferences=course_preferences, instructor_preferences=instructor_preferences, major=major, grad_year=grad_year) app.save() messages.success(request, f'Application Submitted Successfully!') preferences = app_form.cleaned_data.get('lab_hour_data') utils.save_preferences(student, preferences) return redirect('ta_system:home') elif utils.has_submitted_application(student): context['user_has_submitted_application'] = True return render(request, 'ta_system/home.html', context=context)
def get_lab_hour_assignments(self, request): if request.method != 'GET': return handle_bad_request(request, app='admin', expected_method='GET') semester_string = request.GET.get('semester') year, semester_code = utils.get_year_and_semester_code(semester_string) semester = models.Semester.objects.get(year=year, semester_code=semester_code) return HttpResponse(dumps(semester.lab_hour_assignments), content_type='application/json', status=200)
def validate_course_data(courses): unique_course_ids = set() for course in courses: semester, course_number = course.split(',')[:2] course_id = f'({semester}: {course_number})' if course_id in unique_course_ids: raise ValueError(course_id) year, semester_code = get_year_and_semester_code(semester) course_obj = Course.objects.filter( semester__year=year, semester__semester_code=semester_code, course_number=course_number) if course_obj: raise AlreadyExistsError(course_id) unique_course_ids.add(course_id) courses.seek(0)
def write_ta_assignment_data(csv_writer, semester): semester_has_assigned_tas = False year, semester_code = get_year_and_semester_code(semester) courses = Semester.objects.get( year=year, semester_code=semester_code).course_set.all() for course in courses: tas = course.teaching_assistants.all() if not semester_has_assigned_tas and tas: semester_has_assigned_tas = True for ta in tas: row = [ course.semester, course.course_number, course.name, course.instructor.name, ta.eagle_id, ta.user.first_name, ta.user.last_name, ta.user.email ] csv_writer.writerow(row) if not semester_has_assigned_tas: raise ValueError( f'The semester ({get_verbose_semester(semester)}) has no ' + 'courses to which any teaching assistants have been assigned') return csv_writer
def process_applicant(applicant_data): applicant_data = dict(zip(DATA_FORMATS.keys(), applicant_data)) year, semester_code = get_year_and_semester_code(applicant_data['semester']) try: course = Course.objects.get( semester__year=year, semester__semester_code=semester_code, course_number=applicant_data['course_number'] ) applicant = Profile.objects.get(eagle_id=applicant_data['eagle_id']) except Course.DoesNotExist: raise ObjectDoesNotExist( 'The following course does not exist in our database: ' + f'{applicant_data["semester"]}: {applicant_data["course_number"]}' ) except Profile.DoesNotExist: raise ObjectDoesNotExist( 'The following applicant does not exist in our database: ' + f'{applicant_data["eagle_id"]}: {applicant_data["first_name"]} {applicant_data["last_name"]}' ) else: applicant.courses_taken.add(course)