Skip to content

Commit

Permalink
added ability to receive canvas checkbox data
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxwell-Lindsey committed Oct 23, 2023
1 parent 7a9c21d commit 65b2ba1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
21 changes: 11 additions & 10 deletions ai_ta_backend/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def download_course_content(self, canvas_course_id: int, dest_folder: str, conte
return "Failed! Error: " + str(e)


def ingest_course_content(self, canvas_course_id: int, course_name: str)-> str:
def ingest_course_content(self, canvas_course_id: int, course_name: str, content_ingest_dict: dict = None) -> str:
"""
Ingests all Canvas course materials through the course ID.
1. Download zip file from Canvas and store in local directory
Expand All @@ -81,14 +81,15 @@ def ingest_course_content(self, canvas_course_id: int, course_name: str)-> str:
print("In ingest_course_content")
try:
# a dictionary of all contents we want to ingest - files, pages, modules, syllabus, assignments, discussions.
content_to_ingest = {
'files': True,
'pages': True,
'modules': True,
'syllabus': True,
'assignments': True,
'discussions': True
}
if content_ingest_dict is None:
content_ingest_dict = {
'files': True,
'pages': True,
'modules': True,
'syllabus': True,
'assignments': True,
'discussions': True
}

# Create a canvas directory with a course folder inside it.
canvas_dir = "canvas_materials"
Expand All @@ -108,7 +109,7 @@ def ingest_course_content(self, canvas_course_id: int, course_name: str)-> str:
print("Course folder created")

# Download course content
self.download_course_content(canvas_course_id, folder_path, content_to_ingest)
self.download_course_content(canvas_course_id, folder_path, content_ingest_dict)

# Upload files to S3
s3_paths = upload_data_files_to_s3(course_name, folder_path)
Expand Down
13 changes: 12 additions & 1 deletion ai_ta_backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,17 @@ def ingest_canvas():
canvas_course_id: str = request.args.get('course_id')
course_name: str = request.args.get('course_name')

# Retrieve the checkbox values from the request and create the content_ingest_dict
# Set default values to True if not provided in the request
content_ingest_dict = {
'files': request.args.get('files', 'true').lower() == 'true',
'pages': request.args.get('pages', 'true').lower() == 'true',
'modules': request.args.get('modules', 'true').lower() == 'true',
'syllabus': request.args.get('syllabus', 'true').lower() == 'true',
'assignments': request.args.get('assignments', 'true').lower() == 'true',
'discussions': request.args.get('discussions', 'true').lower() == 'true'
}

if canvas_course_id == '' or course_name == '':
# proper web error "400 Bad request"
abort(
Expand All @@ -409,7 +420,7 @@ def ingest_canvas():
f"Missing one or more required parameters: 'course_id' and 'course_name' must be provided. course_id: `{canvas_course_id}`, course_name: `{course_name}`"
)

success_or_failure = canvas.ingest_course_content(canvas_course_id, course_name)
success_or_failure = canvas.ingest_course_content(canvas_course_id, course_name, content_ingest_dict)
response = jsonify({"outcome": success_or_failure})
response.headers.add('Access-Control-Allow-Origin', '*')
return response
Expand Down

0 comments on commit 65b2ba1

Please sign in to comment.