Ejemplo n.º 1
0
def add_current_course(request):
    if "user_id" in request.session:
        # load all courses
        all_courses = Course.objects.all()
        errors = []
        professors = Professor.objects.all()

        if request.POST.get('add_current_course_button'):
            if request.POST.get('course') == "NULL":
                errors.append('Select a Course')
            else:
                # get course id
                course = Course.objects.get(course_name=request.POST.get('course'))
                this_course_id = course.id

                # check if course was already added
                course_query = Course_Taken.objects.filter(user_id=request.session['user_id'], course_id=this_course_id)
                if len(course_query) > 0:
                    # duplicate course
                    errors.append('Course was already added')

            if request.POST.get('professor') == "NULL":
                errors.append('Select a Professor')

            if not errors:
                new_course_taken = Course_Taken(user_id=request.session['user_id'], prof_id=request.POST.get('professor'), course_id=this_course_id, semester_taken=current_semester, year_taken=current_year, current=True, date_added = datetime.datetime.now())
                new_course_taken.save()
                return HttpResponseRedirect('/profile/')

        user_info, all_courses, user_courses, current_courses, previous_courses, hangouts, user_rating, activity_tuple, num_posts = load_user_info(request)

        return render(request, 'add_current_course.html', {'courses': all_courses, 'professors': professors, 'errors': errors, 'num_posts': num_posts, 'user_info': user_info, 'user_rating': user_rating})
    else:
        return HttpResponseRedirect('/')
Ejemplo n.º 2
0
def add_previous_course(request):
    if "user_id" in request.session:
        # load all courses
        all_courses = Course.objects.all()

        years = []

        for i in range(26):
            years.append(1990+i)

        errors = []

        professors = Professor.objects.all()

        if request.POST.get('add_previous_course_button'):
            if request.POST.get('course_name') == "NULL":
                errors.append('Select a Course')
            else:
                course = Course.objects.get(course_name=request.POST.get('course_name'))
                this_course_id = course.id

            if request.POST.get('semester_taken') == "NULL":
                errors.append('Select a Semester')

            if request.POST.get('year_taken') == "NULL":
                errors.append('Select a Year')

            if request.POST.get('skill_level') == "NULL":
                errors.append('Select a Skill Level')

            if request.POST.get('professor_taken') == "NULL":
                errors.append('Select a Professor')

            if request.POST.get('course_difficulty') == "NULL":
                errors.append('Rate the Course')

            if request.POST.get('professor_rating') == "NULL":
                errors.append('Rate the Professor')


            if not errors:
                new_course_taken = Course_Taken(user_id=request.session['user_id'], prof_id=request.POST.get('professor_taken'), skill_level = request.POST.get('skill_level'), course_id=this_course_id, semester_taken=request.POST.get('semester_taken'), year_taken=request.POST.get('year_taken'), current=False, prof_difficulty=request.POST.get('professor_rating'), course_difficulty=request.POST.get('course_difficulty'), date_added = datetime.datetime.now())
                new_course_taken.save()
                return HttpResponseRedirect('/profile/')

        user_info, all_courses, user_courses, current_courses, previous_courses, hangouts, user_rating, activity_tuple, num_posts = load_user_info(request)

        return render(request, 'add_previous_course.html', {'courses': all_courses, 'years': years, 'professors': professors, 'errors': errors, 'num_posts': num_posts, 'user_info': user_info, 'user_rating': user_rating})
    else:
        return HttpResponseRedirect('/')
Ejemplo n.º 3
0
def professor_add_course(request):
    course_list = Course.objects.all()

    errors = []

    if request.POST.get('prof_add_course_button'):
        if request.POST.get('course_name') == 'NULL':
            errors.append("Select a Course")

        if request.POST.get('course_type') == 'NULL':
            errors.append("Select a Type")

        if not errors:
            course_insert = Course_Taken(user_id = request.session['user_id'], course_id = request.POST.get('course_name'), prof_id = request.session['user_id'], semester_taken = 'NULL', year_taken = 2015, current=False)
            course_insert.save()
            return HttpResponseRedirect('/profile/')

    return render(request, 'professor_add_course.html', {'course_list': course_list})