Skip to content

Commit

Permalink
Adding backend code to write the Corse Metadata to a json file locally
Browse files Browse the repository at this point in the history
Signed-off-by: Satish Surath <[email protected]>
  • Loading branch information
satishsurath committed Sep 19, 2023
1 parent ac292bb commit 53d41c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion app/file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,15 @@ def delete_file(file_name):
return False

# Create a New Folder under this app.config["FOLDER_UPLOAD"]
def create_folder(folder_name):
def create__course_folder_with_metadata(folder_name, metadata):
try:
user_folder = session['folder']
os.makedirs(os.path.join(app.config["FOLDER_UPLOAD"], user_folder, folder_name))
# Create JSON file inside the course folder
name = os.path.join(app.config["FOLDER_UPLOAD"], user_folder, folder_name)
json_file_path = f"{name}/course_meta.json"
with open(json_file_path, 'w') as json_file:
json.dump(metadata, json_file)
return True
except:
return False
Expand Down Expand Up @@ -182,6 +187,7 @@ def get_content_files(folder_path):
and f != 'Textchunks.npy'
and f != 'Textchunks-originaltext.csv'
and f != app.config['ACTIVATIONS_FILE']
and f != 'course_meta.json'
]

def check_and_update_activations_file(folder_path):
Expand Down
11 changes: 9 additions & 2 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
list_folders,
rename_folder,
delete_folder,
create_folder,
create__course_folder_with_metadata,
allowed_file,
delete_file,
get_first_txt_file,
Expand Down Expand Up @@ -197,7 +197,14 @@ def course_management():
@login_required
def create_course():
name = request.form['name'].replace(' ', '-')
create_folder(name)
meta_data = {
'classname': request.form.get('classname', ''),
'professor': request.form.get('professor', ''),
'assistants': request.form.get('assistants', ''),
'classdescription': request.form.get('classdescription', ''),
'assistant_name': request.form.get('assistant_name', '')
}
create__course_folder_with_metadata(name, meta_data)
return redirect(url_for('course_management'))

@app.route('/rename-item', methods=['POST'])
Expand Down

0 comments on commit 53d41c4

Please sign in to comment.