diff options
author | ankitjavalkar | 2021-01-17 01:21:56 +0530 |
---|---|---|
committer | GitHub | 2021-01-17 01:21:56 +0530 |
commit | 9b9ebb227bbaafca3daf5485c3bbe0d948d3e843 (patch) | |
tree | 9ae8e5ea5b08c0baf9fd84621055afdc3c8cd64a /yaksh/views.py | |
parent | b98d41e77d0abdd6cc5a2fb0cf89fe0cbc0fb985 (diff) | |
parent | 3966ae20fc68041721f97c45ff92102ed5729aee (diff) | |
download | online_test-9b9ebb227bbaafca3daf5485c3bbe0d948d3e843.tar.gz online_test-9b9ebb227bbaafca3daf5485c3bbe0d948d3e843.tar.bz2 online_test-9b9ebb227bbaafca3daf5485c3bbe0d948d3e843.zip |
Merge pull request #804 from ankitjavalkar/crs-upload
Course upload and download with MD file formats
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index 643b2ae..50f9ded 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -40,7 +40,7 @@ from yaksh.models import ( StdIOBasedTestCase, StringTestCase, TestCase, User, get_model_class, FIXTURES_DIR_PATH, MOD_GROUP_NAME, Lesson, LessonFile, LearningUnit, LearningModule, CourseStatus, question_types, Post, Comment, - Topic, TableOfContents, LessonQuizAnswer, MicroManager + Topic, TableOfContents, LessonQuizAnswer, MicroManager, dict_to_yaml ) from stats.models import TrackLesson from yaksh.forms import ( @@ -2624,6 +2624,23 @@ def download_sample_toc(request): @login_required @email_verified +def download_toc(request, course_id, lesson_id): + user = request.user + tmp_file_path = tempfile.mkdtemp() + yaml_path = os.path.join(tmp_file_path, "lesson_toc.yaml") + TableOfContents.objects.get_all_tocs_as_yaml(course_id, lesson_id, yaml_path) + + with open(yaml_path, 'r') as yml_file: + response = HttpResponse(yml_file.read(), content_type='text/yaml') + response['Content-Disposition'] = ( + 'attachment; filename="lesson_toc.yaml"' + ) + return response + + + +@login_required +@email_verified def duplicate_course(request, course_id): user = request.user course = Course.objects.get(id=course_id) @@ -4147,3 +4164,25 @@ def _read_marks_csv(request, reader, course, question_paper, question_ids): messages.info(request, 'Updated successfully for user: {0}, question: {1}'.format( username, question.summary)) + + +@login_required +@email_verified +def upload_download_course_md(request, course_id): + course = get_object_or_404(Course, pk=course_id) + if request.method == "POST": + from upload.views import upload_course_md + status, msg = upload_course_md(request) + if status: + messages.success(request, "MD File Successfully uploaded to course") + else: + messages.warning(request, "{0}".format(msg)) + return redirect( + 'yaksh:course_detail', course.id + ) + else: + context = { + 'course': course, + 'is_upload_download_md': True, + } + return my_render_to_response(request, 'yaksh/course_detail.html', context) |