Пример #1
0
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('/');
Пример #2
0
def index(request):
    if request.method == "GET":
        print("method is get")
        name = "ádasdasfas"
        context = {"name": name}
        return render(request, "myapp/mentor-post.html", context)
    elif request.method == "POST":

        numberMaterial = int(request.POST["numberMaterial"])

        mentor = Mentor.objects.get(user=request.user)

        category_id = request.POST["childrenCategory"]
        category = Category.objects.get(id=category_id)
        # curriculum
        course_name = request.POST["course_name"]
        description = request.POST["curriculumn_description"]
        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.description = str(description.encode("utf-8"))
        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.category = category
        curriculumn.save()
        # material
        try:
            for n in range(numberMaterial):
                material_title = request.POST["material_title" + str(n + 1)]
                material_type = request.POST["material_type" + str(n + 1)]
                material_url = request.POST["material_url" + str(n + 1)]
                material_description = request.POST["material_description" + str(n + 1)]
                material_hide = request.POST["material_hide" + str(n + 1)]
                material = Material()
                material.name = material_title
                material.type = MaterialType.objects.get(name=material_type)
                material.url = material_url
                material.description = str(material_description.encode("utf-8"))
                if material_hide == "0":
                    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 = str(action_description.encode("utf-8"))
            if request.POST["action_name"]:
                action.save()
                curriculumn.action.append(action)
                curriculumn.save()
        except Exception as ex:
            print("CreateCurriculumn.add material: " + ex)
            curriculumn.delete()
        return HttpResponseRedirect("/mentorview")