def add_material(request): if request.method == 'POST': #curriculum try: curriculum_id = request.POST['curriculum_id'] curriculum = Curriculumn.objects.get(id=curriculum_id) #material material_title = request.POST['material_title'] material_type = request.POST['material_type'] material_url = request.POST['material_url'] material_code = "" material_description = request.POST['material_description'] except Exception as e: c = { 'error_message':e, } material = Material() material.name = material_title material.type = MaterialType.objects.get(name=material_type) material.url = material_url material.code = material_code material.description = str(material_description.encode('utf-8')) material.save() #curriculum curriculum.material.append(material) curriculum.save() return HttpResponseRedirect('/mentorview');
def index(request): if request.method == 'GET': try: user_id = request.GET['user_id'] except Exception: user_id = request.user user = User.objects.get(id=user_id) context = {'mentor':user} return render(request,'myapp/mentor-course.html', context) elif request.method == 'POST': # profile = UserProfile.objects.get(user_id=request.user) # profile.is_mentor = True # profile.save() # mentor = Mentor() # mentor.user = request.user # mentor.save() mentor = Mentor.objects.get(user=request.user) #curriculum course_name = request.POST['course_name'] duration = request.POST['duration'] duration_type = request.POST['duration_type'] start_date = request.POST['start_date'] end_date = request.POST['end_date'] curriculumn = Curriculumn() curriculumn.name = course_name curriculumn.duration = duration curriculumn.duration_type = duration_type curriculumn.from_date = datetime.strptime(start_date,'%m/%d/%Y') curriculumn.to_date = datetime.strptime(end_date,'%m/%d/%Y') curriculumn.mentor = mentor curriculumn.save() #material material_title = request.POST['material_title'] material_type = request.POST['material_type'] material_url = request.POST['material_url'] material_code = "" material_description = request.POST['material_description'] material = Material() material.name = material_title material.type = MaterialType.objects.get(name=material_type) material.url = material_url material.code = material_code material.description = material_description material.save() curriculumn.material.append(material) curriculumn.save() #action action_name = request.POST['action_name'] action_description = request.POST['action_description'] action = Action() action.name = action_name action.description = action_description if request.POST['action_name']: action.save() curriculumn.action.append(action) curriculumn.save() return HttpResponseRedirect('/');
def add_material(request): if request.method == 'POST': #curriculum curriculum_id = request.POST['curriculum_id'] curriculum = Curriculumn.objects.get(id=curriculum_id) #material material_title = request.POST['material_title'] material_type = request.POST['material_type'] material_url = request.POST['material_url'] material_code = request.POST['material_code'] material_description = request.POST['material_description'] material = Material() material.name = material_title material.type = MaterialType.objects.get(name=material_type) material.url = material_url material.code = material_code material.description = material_description material.save() #curriculum curriculum.material.append(material) curriculum.save() return HttpResponseRedirect('/');