Esempio n. 1
0
def upload_course(request):
	if request.method != "POST":
		return JsonResponse({'error_code': 1, 'msg': "not POST method, it's "+request.method})
	data = json.loads(request.body)
	team = Team.objects.filter(pk=data.get("tid")).first()
	# print(data.get("tid"))
	if team is None:
		return JsonResponse({'error_code': 2, 'msg': "team not exist", "id": Team.objects.all().last().id, "tid":data.get("tid")})
	name = data.get('name')
	teacher = data.get('teacher')
	description = data.get('description')
	link = data.get('link')
	# TODO: change time
	startTime = data.get('startTime')
	endTime = data.get('endTime')
	startTime = datetime.datetime.strptime(startTime, "%Y-%m-%d %H:%M:%S")
	endTime = datetime.datetime.strptime(endTime, "%Y-%m-%d %H:%M:%S")
	# courseTime = CourseTime(addTime=addTime, endTime=endTime)
	# courseTime.save()

	image = data.get('image')
	print("this is image:\n"+image)
	course = Course(tid=team, name=name, teacher=teacher, description=description, link=link, picture=image)
	course.save()
	courseTime = CourseTime(startTime=startTime, endTime=endTime, cid=course)
	courseTime.save()
	return JsonResponse({'error_code': 0})
Esempio n. 2
0
def change_course(request):
	if request.method != "POST":
		return JsonResponse({'error_code': 1, 'msg': "not POST method"})
	data = json.loads(request.body)
	course = Course.objects.filter(pk=data.get("id")).first()
	if course is None:
		return JsonResponse({'error_code': 2, 'msg': "course not exist"})
	courseTime = course
	name = data.get('name')
	teacher = data.get('teacher')
	description = data.get('description')
	link = data.get('link')
	# TODO: change time
	startTime = data.get('startTime')
	endTime = data.get('endTime')
	image = data.get('image')
	course.name = name
	course.image = image
	startTime = datetime.datetime.strptime(startTime, "%Y-%m-%d %H:%M:%S")
	endTime = datetime.datetime.strptime(endTime, "%Y-%m-%d %H:%M:%S")
	# courseTime = CourseTime(addTime=addTime, endTime=endTime)
	# courseTime.save()
	courseTime = course.course_time.first()
	courseTime.startTime = startTime
	courseTime.endTime = endTime
	# course.course_time.create(startTime=startTime, endTime=endTime)
	if teacher != "":
		course.teacher = teacher
	if description != "":
		course.description = description
	if link != "":
		course.link = link
	course.save()
	courseTime.save()
	return JsonResponse({'error_code': 0})
Esempio n. 3
0
def Calc_HW(HW_name, HW_time, HW_due):
    """
    This sets the times and days that the newly entered assignment should be
    completed in. Using the function get_all_times from course to get
    a dictionary of days of the week with the number of busy hours, and finding all
    availble time on the day with the least busy hours, we are able to evenly spread 
    out work throughout the week. Note: This is set up best for weekly assignments.
    """
    (name_HW, hours, Due_day) = get_HW(HW_name, HW_time, HW_due)
    color = course.color_rand()

    while hours:
        Work_time = course.get_all_times()    
        if Due_day in Work_time:
            #So that work on the due date is not set, it is eliminated fromt he dictionary
            Work_time.pop(Due_day)
        (cur_day, time) = min(Work_time.items(), key = lambda x: x[1])
        avail_hours = avail_time(cur_day)
        if avail_hours == [ ]:
            #If the least busy day has no work hours, homework will not be scheduled till ten
            avail_hours = [10.0]
            #This could be made a variable and set by the user
        course.Course((name_HW, [avail_hours[0], avail_hours[0] + .5], [cur_day]), color=color)
        #Each half hour of work is its own object
        markBusy(name_HW, avail_hours[0], avail_hours[0] + .5, cur_day, color)
        hours = hours - .5
        #This also is used to save the assignment objects in the text file
        course.save()
Esempio n. 4
0
def save_contents(course_name, Times, Days):
    """
    Retrieves informationg containing name, day and times, from the function
    get contents. Checks if this day and time is already taken in the 
    schedule, if it is your addition will not be added. Creates a course type
    object using the information from get_contents and puts it visually 
    on the schedule. Also calls save, so that the new object can be saved
    in the text current text file. 
    """
    info = get_contents(course_name, Times, Days)
    for i in course.Course.get_all_instances():
    	if info[1][0] > i.get_start_time() and info[1][0] < i.get_end_time():
            #Checks if the start time to be added is within any of the busy times 
    		for j in info[2]:
    			if j in i.get_days():
    				return None
    	elif info[1][1] > i.get_start_time() and info[1][1] < i.get_end_time():
            #Checks if the end time to be added is within any of the busy times 
    		for j in info[2]:
    			if j in i.get_days():
    				return None
    	elif info[1][0] == i.get_start_time():
            #Checks if the start time to be added is the same as other start times 
    		for j in info[2]:
    			if j in i.get_days():
    				return None
    clear_contents(Days, course_name, Times)
    app = course.Course((info))
    #Adds each day of busy time to the schedule
    for i in app.get_days():
        markBusy(app.get_name(), app.get_start_time(), app.get_end_time(), i, app.get_color())

    course.save()
Esempio n. 5
0
def delete_contents(Days, course_name, Times):
	#convert all strings to values we can use!
	info = get_contents(course_name, Times, Days)
	#find the course we are trying to delete
	for i in course.Course.get_all_instances():
		if info[0]==i.get_name():
			course_object = i
			#Delete the course on all days that it happens
			for i in course_object.get_days():
				markAvailable(course_object.get_start_time(), course_object.get_end_time(), i)
				course_object.del_instances()


	
	course.save()
Esempio n. 6
0
def addNewCourse(request):
    user=request.user
    if not checkUser(user)=='manager':
        return HttpResponse(u'权限不足,禁止访问')
    courseId=""
    role="admin"
    username=user.username
    if "courseId" in request.POST:
        courseId=request.POST["courseId"]
    if "courseName" in request.POST:
        courseName=request.POST["courseName"]
    if "teaId" in request.POST:
       	teaId=request.POST["teaId"]
    if "description" in request.POST:
       	description=request.POST["description"]
    if Course.objects.filter(course_code=courseId):
	info="course already exist!!"
    else:
	u=User.objects.filter(username=teaId)
				
	if u:
            user=u[0]
	    t=Teacher.objects.filter(user=user)[0]
	    log.info("add course teacher!!!yy"+t.user.username)
	    course=Course(course_code=courseId,course_name=courseName,description=description)
	    course.save()
	    course.teacher.add(t)
	else:
	    u=User(username=teaId)
	    u.save()
	    t=Teacher(user=u)
	    t.save()
			
	    log.info("add course teacher!!!yy"+t.user.username)
	    course=Course(course_code=courseId,course_name=courseName,description=description)
	    course.save()
	    course.teacher.add(t)
        courselist=Course.objects.all()
    log_detail = LogDetail(manager = request.user.manager,detail = u'添加课程'+courseId)
    log_detail.save()
    return render_to_response("allcourse.html",
                       { "courseList" : courselist,
                        "role":role,
                        "username":username} ,
                        context_instance=RequestContext(request))