コード例 #1
0
def create_in_drive(conn, client, enrollments, count, offset):
    if offset != None:
        offset = int(offset)
        count = offset

    last_disp = len(enrollments)
    if offset != None:
        last_disp = len(enrollments) + offset

    for enrollment in enrollments:
        try:
            print("Processing enrollment %s/%s..." % (count, last_disp))

            fe_q = Database.get(Database.execute(conn, Database.folder_exists_query_string(enrollment.course.id)))
            rcf_q = Database.get(Database.execute(conn, query="SELECT folder_id FROM vlacs_class_folders_structure WHERE folder_name = '%s'" % (config.ROOT_CLASS_FOLDER)))
            fe_id = fe_q['folder_id']
            rcf_id = rcf_q['folder_id']

            if folder_exists:
                if isinstance(folder_exists, list):
                    folder_exists = folder_exists[0]
                print "Creating Student Folder: %s" % Utilities.gen_title(enrollment, "s")
                studentfolder = Folder.create_flat(conn, client, Utilities.gen_title(enrollment, "s"), rcf_id, fe_id, enrollment.course.id, enrollment.student.id)
            else:
                title = Utilities.gen_title(enrollment, "c")
                print "Creating Class Folder: %s" % title
                classfolder = Folder.create_flat(conn, client, title, rcf_id, rcf_id, enrollment.course.id)
                print "Creating Student Folder: %s" % Utilities.gen_title(enrollment, "s")
                studentfolder = Folder.create_flat(conn, client, Utilities.gen_title(enrollment, "s"), rcf_id, classfolder.resource_id.text, enrollment.course.id, enrollment.student.id)
            count += 1

        except GDRequestError as e:
            print "ERROR:", e.status
            count += 1
コード例 #2
0
def student_needs_renaming(enrollment, database_contents):
    for entry in database_contents:
        if (enrollment.student.id == entry['student_id'] and
            Utilities.gen_title(enrollment, "s") != entry['folder_name']):
            enrollment.folder_id = entry['folder_id']
            enrollment.folder_name = entry['folder_name']
            return True
    return False
コード例 #3
0
def course_needs_renaming(conn, enrollment):
    qs = Database.construct_query_string('vlacs_class_folders_structure', 
                                        {'folder_name' : 
                                            {'value' : Utilities.gen_title(enrollment, "c"),
                                             'type' : 's'}})
    needs_renaming = Database.get(Database.execute(conn, qs))
    if len(needs_renaming) > 0:
        return False
    enrollment.folder_id = needs_renaming['folder_id']
    enrollment.folder_name = Utilites.gen_title(enrollment, "c")
    return True
コード例 #4
0
def get(client, conn, template, enrollment=None):
	parsed_template = {'folder_name': "", 'role': {'teacher': "", 'student': ""}}

	template_variables = {
			"{{CLASS_FILES}}" : {
					 'folder_id'   : None,
					 'folder_name' : "Class Files (%s)" % (enrollment['class_id']),
					        'role' : {
										'teacher' : 'writer',
										'student' : 'reader',
									},
					'copy' : True
			},
			"{{CLASSROOM}}" : {
					 'folder_id'   : None,
					 'folder_name' : "%s (%s - %s)" % (enrollment['course_name'], enrollment['class_id'], Utilities.course_version(enrollment['course_full_name'])),
					        'role' : {
										'teacher' : 'reader',
										'student' : 'reader',
									},
					'copy' : False
			},
			"{{COURSE_NAME}}" : {
					 'folder_id'   : None,
					 'folder_name' : enrollment['course_name'],
					        'role' : {
										'teacher' : 'reader',
										'student' : 'reader',
									},
					'copy' : False
			},
			"{{COURSES}}" : {
					 'folder_id'   : None,
					 'folder_name' : "Courses",
					        'role' : {
										'teacher' : 'reader',
										'student' : 'reader',
									},
					'copy' : False
			},
			"{{STUDENT_ASSIGNMENTS}}" : {
					 'folder_id'   : None,
					 'folder_name' : None,
					        'role' : {
										'teacher' : 'writer',
										'student' : 'writer',
									},
					'copy' : True
			},
			"{{STUDENT_NAME}}" : {
					 'folder_name' : "%s, %s" % (enrollment['student_lastname'], enrollment['student_firstname']),
					        'role' : {
										'teacher' : 'reader',
										'student' : 'none',
									},
					'copy' : False
			},
			"{{STUDENT_ROOT}}" : {
					 'folder_name' : None,
					 'folder_id'   : None,
					        'role' : {
										'teacher' : 'none',
										'student' : 'reader',
									},
					'copy' : False
			},
			"{{STUDENTS}}" : {
					 'folder_id'   : None,
					 'folder_name' : "Students",
					        'role' : {
										'teacher' : 'reader',
										'student' : 'none',
									},
					'copy' : False
			},
			"{{TEACHER_ROOT}}" : {
					 'folder_id'   : None,
					 'folder_name' : None,
					        'role' : {
										'teacher' : 'reader',
										'student' : 'none',
									},
					'copy' : False
			},
		}

	# These template variables rely on external systems, we shouldn't generate them
	# each time the function is called.
	if template == "{{TEACHER_ROOT}}":
		root_folders = Folder.list_sub_folders(client, "root")
		template_variables[template]['folder_id'] = root_folders[config.TEACHER_SHARE_FOLDER]
		template_variables[template]['folder_name'] = config.TEACHER_SHARE_FOLDER + " (%s)" % (enrollment['teacher_id'])
	elif template == "{{STUDENT_ROOT}}":
		root_folders = Folder.list_sub_folders(client, "root")
		template_variables[template]['folder_id'] = root_folders[config.STUDENT_SHARE_FOLDER]
		template_variables[template]['folder_name'] = config.STUDENT_SHARE_FOLDER + " (%s)" % (enrollment['student_id'])
	elif template == "{{STUDENT_ASSIGNMENTS}}":
		folder_id = Database.get(Database.execute(conn, Database.structure_get_folder_id_string(Utilities.gen_title(enrollment, "s"), enrollment['class_id'], enrollment['student_id'])))
		folder_id = folder_id['folder_id']
		template_variables[template]['folder_id'] = folder_id
		template_variables[template]['folder_name'] = "%s, %s - Assignments" % (enrollment['student_lastname'], enrollment['student_firstname'])
		
	parsed_template = template_variables[template]

	return parsed_template