def get_comment_value_by_assignment_id(marked_grade_cell: Cell, marked_comment_cells: Cell, row_number, ws: worksheet): """ Helper method to find the corresponding comment value for a given grade_cell. Column index marked by assignment ID in upload_marker row. Row indexing by given row_number. The list of cells (marked_comment_cells) is cleaned before and do not contain the CommentMarkerPrefix anymore, but assignment IDs. :param marked_grade_cell: Grade cell marked by assignment ID in the upload_marker row. :param marked_comment_cells: List of all comment cells we want to find the assignment ID of marked_grade_cell in. :param row_number: Number of current row. :param ws: Worksheet to read from (data_only). :return: Empty string if cell value is None or if cell is not found. """ if Config.get_behavior_comments_switch(): for coment_cell in marked_comment_cells: # find matching assignment id if str(coment_cell.value) == str(marked_grade_cell.value): # extract coordinates (column index) column_index_of_comment_cell = column_index_from_string( coordinate_from_string(coment_cell.coordinate)[0]) # read value of cell comment_value = ws.cell( row=row_number, column=column_index_of_comment_cell).value if not comment_value: # normalize - we want string only as return type comment_value = '' return comment_value if Config.get_behavior_log(): print('Comment for grade cell ' + str(marked_grade_cell.coordinate) + ' not found!') return ''
def get_group_id_by_name(group_name, student_name): group_id = -1 result_get_course_groups = ws.do_post_on_webservice( 'core_group_get_course_groups', {'courseid': current_course_id}) for group in result_get_course_groups: if group['name'] == group_name: group_id = group['id'] break if group_id == -1: util.print_error_message_and_prompt_any_key_to_exit( 'Gruppen ID in Moodle für Wechsel nicht gefunden!' + '\n' + 'Student: ' + student_name + '\n' + 'Gruppe: ' + group_name) return group_id
from PythonScripts.Imports import Config from PythonScripts.Imports import Utility as util from PythonScripts.Imports import WebService as ws from PythonScripts.Imports.Classes import Group # ask user if ['OUTPUT_FILE']['OutputFileNameStudent2Group'] shall be overwritten util.ask_user_to_overwrite_file(Config.get_output_student2group()) # create a workbook in memory wb_out = Workbook() ws_out = wb_out.active # get all groups of current moodle course result_get_groups = ws.do_post_on_webservice( 'core_group_get_course_groups', {'courseid': Config.get_current_course_id()}) # create list of Group for simpler handling groups = [] for group in result_get_groups: groups.append(Group.Group(group['id'], group['name'], [])) # sort for proper displaying in excel groups = sorted(groups, key=lambda group: group.id) # create payload for api call group_counter = 0 payload = {} for group in groups: payload.update({'groupids[' + str(group_counter) + ']': group.id})
Saves the freshly created course id in config.ini in section ['CURRENT_COURSE']['CurrentCourseID']. So the freshly created course will be the course we are working on from now on. The CurrentCourseID can be changed manually to work on another course - f.e. for testing another moodle system... """ # duplicate template course payload = { 'courseid': Config.get_course_creation_template_course_id(), 'fullname': Config.get_course_creation_course_name(), 'shortname': Config.get_course_creation_course_short_name(), 'categoryid': Config.get_course_creation_course_category_id( ), # 'topics' TODO: moodle HSMA? 'visible': Config.get_course_creation_visibility() } result_duplicate_course = ws.do_post_on_webservice( 'core_course_duplicate_course', payload) # save cloned course id; its used in almost each script >IMPORTANT< new_course_id = result_duplicate_course['id'] Config.replace_current_course_id_in_config_file(new_course_id) Config.__init__(Config.loaded_config_file_path) # update cloned course description ws.do_post_on_webservice( 'core_course_update_courses', { 'courses[0][id]': new_course_id, 'courses[0][summary]': Config.get_course_creation_course_description() }) # open cloned course in moodle util.open_moodle_in_webbrowser('course/view.php?id=' + str(new_course_id))
get_comment_value_by_assignment_id(grade_marker_cell, grade_comment_cells, current_row, ws_grading_data), 'id_not_set', current_assignment_id)) students_in_front_sheet.append(current_student) students_in_front_sheet = sorted(students_in_front_sheet, key=lambda user: user['username']) # ************************************************************************************ # READ IN MOODLE COURSE # ************************************************************************************ result_get_enrolled_users = ws.do_post_on_webservice( 'core_enrol_get_enrolled_users', {'courseid': current_course_id}) result_get_course_groups = ws.do_post_on_webservice( 'core_group_get_course_groups', {'courseid': current_course_id}) enrolled_users_in_course = [] for enrolled_user in result_get_enrolled_users: group_details = {} if enrolled_user['groups']: # enrolled user is in a group group_details = { 'name': enrolled_user['groups'][0]['name'], 'id': str(enrolled_user['groups'][0]['id']) } enrolled_users_in_course.append({ 'username': str(enrolled_user['username']), # 'firstname': enrolled_user['firstname'],
wb_out = Workbook() ws_grades = wb_out.active # Workbook is created with empty sheet ws_grades.title = 'grades' # rename that empty sheet ws_assignments = wb_out.create_sheet('assignments') ws_groups = wb_out.create_sheet('groups') ws_not_in_group = wb_out.create_sheet('not_in_group') course_id = Config.get_current_course_id() moodle_uid = Config.get_moodle_user_id_field_name() # **************************************************************** # START OF API CALLS - START TO FILL WORKBOOK # **************************************************************** # get groups of course result_get_course_groups = ws.do_post_on_webservice( 'core_group_get_course_groups', {'courseid': course_id}) # get enrolled users result_get_enrolled_users = ws.do_post_on_webservice( 'core_enrol_get_enrolled_users', {'courseid': course_id}) list_of_enrolled_users_in_group = [] list_of_enrolled_users_not_in_group = [] groups = [] for grp in result_get_course_groups: if grp: groups.append(Group.Group(grp['id'], grp['name'], [])) # sort for proper display in excel groups = sorted(
sys.path.append( os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')) sys.path.append( os.path.join( os.path.dirname(os.path.dirname(os.path.realpath(__file__))), '..')) from PythonScripts.Imports import WebService as ws from PythonScripts.Imports import Utility as util from PythonScripts.Imports import Config """ Self enrolment into moodle course. This is necessary to perform any grading or user action in that course as 'Manager'. """ # TODO: get enrolment methods to extract instanceids? ws.do_post_on_webservice( 'enrol_self_enrol_user', { 'courseid': Config.get_current_course_id(), 'instanceid': Config.get_enrolment_method_id( ), # use default instance (self enrolment?) # TODO: HSMA? 'password': Config.get_enrolment_password() }) # if set in moodle, this might be needed # open moodle page - enrolled users view to delete student role from PyWsClient - should be Manager only (to hide it from other Students f.e.) util.open_moodle_in_webbrowser('enrol/users.php?id=' + Config.get_current_course_id()) # wait for user prompt util.wait_for_user_input_to_keep_console_opened()
#!/usr/bin/env python if __name__ == '__main__': import os, sys sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')) sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), '..')) from PythonScripts.Imports import WebService as ws from PythonScripts.Imports import Utility as util from PythonScripts.Imports import Config """ Deletes groups from freshly cloned course. Due to avoid null-errors in moodle the template course has a few (placeholder) groups for the groupchoice module. Or if we reuse an old course several groups may be still in it. We want to delete those groups before creating new ones. """ # get all groups of course result_get_course_groups = ws.do_post_on_webservice('core_group_get_course_groups', {'courseid': Config.get_current_course_id()}) payload = {} for n in range(0, len(result_get_course_groups)): #if ('Platzhalter' in result_get_course_groups[n]['name']): payload.update({'groupids[' + str(n) + ']': result_get_course_groups[n]['id']}) ws.do_post_on_webservice('core_group_delete_groups', payload) #wait for user prompt util.wait_for_user_input_to_keep_console_opened()
payload.update({ 'groups[' + str(group_counter) + '][courseid]=': course_id, 'groups[' + str(group_counter) + '][name]=': final_group_name, 'groups[' + str(group_counter) + '][description]=': group_description, 'groups[' + str(group_counter) + '][descriptionformat]=': 1, # 1 = plain text 'groups[' + str(group_counter) + '][enrolmentkey]=': '', 'groups[' + str(group_counter) + '][idnumber]=': '' }) group_counter += 1 ws.do_post_on_webservice('core_group_create_groups', payload) # get group choice id to open in webbrowser result_get_contents = ws.do_post_on_webservice('core_course_get_contents', {'courseid': course_id}) group_choice_id = -1 # in case we cannot find it in course for entity in result_get_contents: for module in entity['modules']: if module['modname'] == 'choicegroup': group_choice_id = module['id'] if group_choice_id != -1: # open group choice edit page on moodle # to set 'Limit the number of responses allowed' manually util.open_moodle_in_webbrowser('course/modedit.php?update=' +