@login_required(login_url='/landpage')
def save_lecture(request, course_id):
    response_data = {'status' : 'failed', 'message' : 'unknown error with saving'}
    if request.is_ajax():
        if request.method == 'POST':
            course = Course.objects.get(id=course_id)
            lecture_id = int(request.POST['lecture_id'])
            form = None

            # If lecture already exists, then lets update only, else insert.
            if lecture_id > 0:
                lecture = Lecture.objects.get(lecture_id=lecture_id)
                form = LectureForm(instance=lecture, data=request.POST)
            else:
                form = LectureForm(request.POST, request.FILES)

            if form.is_valid():
                instance = form.save(commit=False)
                instance.course = course
                instance.save()
                response_data = {'status' : 'success', 'message' : 'saved'}
            else:
                response_data = {'status' : 'failed', 'message' : json.dumps(form.errors)}
    return HttpResponse(json.dumps(response_data), content_type="application/json")
dataset/ETHPy150Open AcademicsToday/py-academicstoday/academicstoday_project/teacher/views/lecture.py/save_lecture/original