예제 #1
0
def index(request):
	if request.method == 'GET':
		lisCategory =Category.objects()
		user=User.objects.get(username=str(request.user))
		mentor = Mentor.objects.get(user=user.id)
		cl = Curriculumn.objects(mentor=mentor).order_by('published_date')
		has_curriculum = False
		is_mentor = request.session['is_mentor']
		if len(cl):
			has_curriculum = True
		clTaken = 0
		clLike = 0
		mtTaken = 0
		mtLike = 0
		actTaken = 0
		actLike = 0
		mtTotal = 0
		actTotal = 0
		context = {	'user_id':user.id,
					'username':request.user,
					'cl':cl,
					'author':mentor.user.username,
					'author_id':mentor.user.id,
					'is_mentor':is_mentor,
					'clTaken':clTaken,
					'clLike':clLike,
					'mtTaken':mtTaken,
					'mtLike':mtLike,
					'actTaken':actTaken,
					'actLike':actLike,
					'mtTotal':mtTotal,
					'actTotal':actTotal,
					'has_curriculum':has_curriculum,
					'listCategory':lisCategory,}
		return render(request,'myapp/mentorview.html', context)
예제 #2
0
def index(request):
	if request.method == 'GET':
# 		cl = Curriculumn.objects(mentor=mentor)
# 		mentor = Mentor.objects.get(user=re)
# 		mentor_id = '5375ce146c02298c9af00e00'
		user_id=request.session['user_id']
		user = User.objects.get(id=user_id)
		mentor = Mentor.objects.get(user=user)
		cl = Curriculumn.objects(mentor=mentor)
		has_curriculum = False
		is_mentor = request.session['is_mentor']
		if len(cl):
			has_curriculum = True
		clTaken = 0
		clLike = 0
		mtTaken = 0
		mtLike = 0
		actTaken = 0
		actLike = 0
		mtTotal = 0
		actTotal = 0
		try:
			for c in cl:
				clTaken += c.statistic.currentTakenNumber
				clLike += c.statistic.currentLikeNumber
				for mt in c.material:
						mtTaken += mt.statistic.currentTakenNumber
						mtLike += mt.statistic.currentLikeNumber
						mtTotal += 1
				for act in c.action:
					actTaken += act.statistic.currentTakenNumber
					actLike += act.statistic.currentLikeNumber
					actTotal +=1
			print(mtTaken)
			print(mtLike)
			print(actTaken)
			print(actLike)
		except Exception as e:
			print(e)
		for c in cl:
			if len(c.joined_user)>0 :
				for u in c.joined_user:
					print(u)
		context = {'user_id':user_id,
					'username':request.user,
					'cl':cl,
					'author':mentor.user.username,
					'author_id':user_id,
					'is_mentor':is_mentor,
					'clTaken':clTaken,
					'clLike':clLike,
					'mtTaken':mtTaken,
					'mtLike':mtLike,
					'actTaken':actTaken,
					'actLike':actLike,
					'mtTotal':mtTotal,
					'actTotal':actTotal,
					'has_curriculum':has_curriculum,}
		return render(request,'myapp/studentview.html', context)
예제 #3
0
def signinsns(request):
	is_mentor = False
	is_join = False
	defaultUserImage = "/images/avatar/default.png"
	
	if 'next' in request.GET:
		nextpage = request.GET['next']
	else:
		nextpage = ""
	user1=User.objects.get(username=str(request.user))
	thismentor = Mentor.objects(user=user1.id)
	thisstudent = Student.objects(user=user1.id)
	thiscurrijoined = Curriculumn.objects()
	
	username=str(request.user)
	avatar = ""
	user_images = ""
	try:
		thisprofile = UserProfile.objects(user_id=user1)
		request.session['user_images'] = thisprofile[0].images
		user_images= request.session['user_images']

	except Exception as e:
		upro = UserProfile()
		upro.user_id = user1
		upro.images = defaultUserImage
		upro.save()
		request.session['user_images'] = defaultUserImage
		print(e)
			
	for cl in thiscurrijoined:
		if username in cl.joined_user:
			is_join = True	
	
	if len(thisstudent) ==  0:
		studentnew = Student()
		studentnew.user = user1
		studentnew.save()

	if len(thismentor) > 0:
		is_mentor = True
		
	request.session['is_mentor'] = is_mentor
	context = 	{
				'avatar':avatar,
				'user_images':user_images
				}
	if nextpage:
		return HttpResponseRedirect(nextpage,context)
	else:
		if is_mentor:
			return HttpResponseRedirect('/mentorview',context )
		else:
			if is_join:
				return HttpResponseRedirect('/student-home',context)
			else:
				return HttpResponseRedirect('/search-mentor',context)
예제 #4
0
def index(request):
	if request.method == 'GET':
# 		cl = Curriculumn.objects(mentor=mentor)
# 		mentor = Mentor.objects.get(user=re)
# 		mentor_id = '5375ce146c02298c9af00e00'
		lisCategory =Category.objects()
		user_id=request.GET['user_id']
		user = User.objects.get(id=user_id)
		mentor = Mentor.objects.get(user=user)
		cl = Curriculumn.objects(mentor=mentor)
		has_curriculum = False
		is_mentor = False
		try:
			is_mentor = request.session['is_mentor']
		except Exception as e:
			print(e)
		if len(cl):
			has_curriculum = True
		clTaken = 0
		clLike = 0
		mtTaken = 0
		mtLike = 0
		actTaken = 0
		actLike = 0
		mtTotal = 0
		actTotal = 0
		for c in cl:
			if len(c.joined_user)>0 :
				for u in c.joined_user:
					print(u)
		context = {'user_id':user_id,
					'username':request.user,
					'cl':cl,
					'author':mentor.user.username,
					'author_id':user_id,
					'is_mentor':is_mentor,
					'clTaken':clTaken,
					'clLike':clLike,
					'mtTaken':mtTaken,
					'mtLike':mtLike,
					'actTaken':actTaken,
					'actLike':actLike,
					'mtTotal':mtTotal,
					'actTotal':actTotal,
					'has_curriculum':has_curriculum,
					'listCategory':lisCategory,}
		return render(request,'myapp/studentview.html', context)
예제 #5
0
def afterlogin(request):
	if request.method == 'GET':
		lisCategory =Category.objects()
		try:
			user=User.objects.get(username=str(request.user))
			user_id = user.id
		except Exception as e:
			c = {
					'error_message':e,
				}
		
		user = User.objects.get(id=user_id)
		mentor = Mentor.objects.get(user=user.id)
		cl = Curriculumn.objects(mentor=mentor)
		has_curriculum = False
		is_mentor = request.session['is_mentor']
		if len(cl):
			has_curriculum = True
		clTaken = 0
		clLike = 0
		mtTaken = 0
		mtLike = 0
		actTaken = 0
		actLike = 0
		mtTotal = 0
		actTotal = 0
		context = {'user_id':user_id,
					'username':request.user,
					'userlogged':user_id,
					'cl':cl,
					'author':mentor.user.username,
					'author_id':mentor.user.id,
					'is_mentor':is_mentor,
					'clTaken':clTaken,
					'clLike':clLike,
					'mtTaken':mtTaken,
					'mtLike':mtLike,
					'actTaken':actTaken,
					'actLike':actLike,
					'mtTotal':mtTotal,
					'actTotal':actTotal,
					'has_curriculum':has_curriculum,
					'listCategory':lisCategory,}
		return render(request,'myapp/mentorview.html', context)
예제 #6
0
def index(request):
	if request.method == 'GET':
		#user = request.user
		user = User.objects.get(username=str(request.user))
		user_id = user.id
		lsCourse = []
		lsjoined = CurriculumnLog.objects(user_id = user_id)
		for ls in lsjoined:
			Course = Curriculumn.objects.get(id=ls.curriculumn.id)
			lsmt = []
			lsac = []
			for mt in Course.material:
				mt={"name":mt.name,"description":mt.description,"url": mt.url}
				lsmt.append(mt)
			if len(Course.action)>0:
				for ac in Course.action:
					ac={"name":ac.name,"description":ac.description}
					lsac.append(ac)
			lsCourseDetail={
							"id": Course.id,
							"author_id":Course.mentor.user.id,
							"name":Course.name,
							"duration":Course.duration,
							"duration_type":Course.duration_type,
							"from_date":Course.from_date,
							"lsmt":lsmt,
							"lsac":lsac
							}
			lsCourse.append(lsCourseDetail)
		#List recomment by admin
		lsRecomment = Curriculumn.objects().all().order_by('published_date')[:5]
		
		context = {	'lsCourse':lsCourse,
					'lsRecomment':lsRecomment
				}
		return render(request,'myapp/student-home.html', context)
예제 #7
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('/');
예제 #8
0
def index(request):
	username = ""
	password = ""
	is_mentor=False
	is_join = False
	defaultUserImage = "/images/avatar/default.png"
	
	username=str(request.user)
	
	thiscurrijoined1 = Curriculumn.objects()
	
	for cl in thiscurrijoined1:
		if username in cl.joined_user:
			is_join = True	
			
	if request.method == 'GET':
		return render(request, 'myapp/signin.html', {})
	elif request.method == 'POST':
		username = request.POST['txtUserName']
		password = request.POST['txtPassWord']
		
		if 'next' in request.GET:
			nextpage = request.GET['next']
		else:
			nextpage = ""
		try: 
			
			user = User.objects.get(username=username)
			transaction = UserLogin()
			transaction.user = user
			transaction.save()
			if user.check_password(password):
				logout(request)
				user.backend = 'mongoengine.django.auth.MongoEngineBackend'
				login(request, user)

				mentor = Mentor.objects(user=user)
				if len(mentor) > 0:
					is_mentor = True
				request.session['is_mentor'] = is_mentor

				user_images = ""
				try:
					profile = UserProfile.objects(user_id=user)
					user_images = profile[0].images
					request.session['user_images'] = "/upload/" +user.username+"-avatar.jpg"
				except Exception as e:
					upro = UserProfile()
					upro.user_id = user
					upro.images = defaultUserImage
					upro.save()
					request.session['user_images'] = defaultUserImage
					print(e)
				context = 	{
							'user_images':user_images,
							}
				if nextpage:
					return HttpResponseRedirect(nextpage,context)	
				else:
					if is_mentor:
						return HttpResponseRedirect('/mentorview',context)	
					else:
						if is_join:
							return HttpResponseRedirect('/student-home',context)
						else:
							return HttpResponseRedirect('/search-mentor',context)
						#return HttpResponseRedirect('/search-mentor')
			else:
				c = {
						'error_message':"User name or password does not correct",
						'username':username,
						'password':password,
					}
				c.update(csrf(request))
				c.update(context_processors.user(request))
				return render_to_response("myapp/signin.html", c)
		except Exception as e:
				c = {
						'error_message':e,
					}
				c.update(csrf(request))
				c.update(context_processors.user(request))
				return render_to_response("myapp/signin.html", c)
	return render(request, 'myapp/signin.html', {})
예제 #9
0
def index(request):
    if request.method == "GET":
        vCourse_id = request.GET["course_id"]
        author_id = request.GET["user_id"]
        author = User.objects.get(id=author_id)
        cl = Curriculumn.objects(id=vCourse_id)
        has_curriculum = False
        try:
            is_mentor = request.session["is_mentor"]
        except Exception as e:
            is_mentor = False
        user = User.objects.get(username=str(request.user))
        student = Student.objects(user=user.id)
        status = "1"

        if len(cl):
            has_curriculum = True

        clTaken = 0
        clLike = 0
        mtTaken = 0
        mtLike = 0
        actTaken = 0
        actLike = 0
        mtTotal = 0
        actTotal = 0

        is_joined = False
        if len(student):
            progress = CurriculumnStudyProgress.objects(curriculumn=cl[0].id, student=student[0].id)
            if len(progress) > 0:
                is_joined = True
        lscl = []
        lscl = cl[0]

        for i in lscl.__getattribute__("material"):
            i.note = "0"
            try:
                is_like = StatisticDetail.objects(object_id=str(i.id), status=status, user=user.id)
                if len(is_like):
                    i.note = "1"
                    i.__getattribute__("statistic").currentLikeNumber -= 1
            except Exception as e:
                print(e)
        avatar = ""
        try:
            avatar = request.session["avatar"]
        except Exception as e:
            request.session["avatar"] = ""
            print(e)

        context = {
            "cl": lscl,
            "is_joined": is_joined,
            "user_id": request.user,
            "course_id": vCourse_id,
            "author_id": author_id,
            "author": author.username,
            "is_mentor": is_mentor,
            "clTaken": clTaken,
            "clLike": clLike,
            "mtTaken": mtTaken,
            "mtLike": mtLike,
            "actTaken": actTaken,
            "actLike": actLike,
            "mtTotal": mtTotal,
            "actTotal": actTotal,
            "has_curriculum": has_curriculum,
            "avatar": avatar,
        }
        return render(request, "myapp/course-detail.html", context)
    elif request.method == "POST":
        if request.POST["posttype"] == "likeMaterial":
            user = User.objects.get(username=str(request.user))
            print(request.POST["posttype"])
            materialId = request.POST["materialId"]
            status = request.POST["status"]  # like or dislike

            # update status=0 for recors last with status=1,user_id,material
            sdLast = StatisticDetail.objects(user=user.id, object_id=str(materialId), status="1").order_by(
                "published_date"
            )[:10]
            if len(sdLast):
                for sdUpdate in sdLast:
                    sdUpdate.status = "0"
                    sdUpdate.save()
            else:
                print("no update ")
            sdNew = StatisticDetail()
            sdNew.user = user
            sdNew.object_id = str(materialId)
            if status == "0":
                sdNew.status = "1"
            else:
                sdNew.status = "0"
            sdNew.save()
            # update or insert statistic
            stCurent = Statistic.objects(object_id=str(materialId)).order_by("create_date")[:1]
            stNew = Statistic()
            if len(stCurent) > 0:
                stNew = stCurent[0]
                if status == "1":
                    stNew.currentLikeNumber -= 1
                else:
                    stNew.currentLikeNumber += 1
                stNew.type = "1"
                stNew.save()
            else:
                if status == "0":
                    stNew.currentLikeNumber = 1
                else:
                    stNew.currentLikeNumber = 0
                stNew.object_id = str(materialId)
                stNew.type = "1"
                stNew.save()
                # update material
            mtCurrent = Material.objects.get(id=materialId)
            mtCurrent.statistic = stNew
            mtCurrent.note = "0"
            mtCurrent.save()

            return HttpResponse(json.dumps({"formdata": materialId}), content_type="application/json")
        elif request.POST["posttype"] == "frmJoincourse":
            curriculum_id = request.POST["curriculum_id"]
            user_id = request.POST["user_id"]
            print(curriculum_id)
            curriculum = Curriculumn.objects.get(id=curriculum_id)

            user = User.objects.get(username=str(request.user))
            student = Student.objects(user=user.id)

            planstart = request.POST["planstart"]
            planend = request.POST["planend"]
            impression = request.POST["impression"]
            description = request.POST["description"]
            # Save CurriculumnStudyProgress
            csp = CurriculumnStudyProgress()
            if len(student):
                st = student[0]
                csp.student = st
            csp.curriculumn = curriculum
            csp.PlanStartDate = datetime.strptime(planstart, "%m/%d/%Y")
            csp.PlanEndDate = datetime.strptime(planend, "%m/%d/%Y")
            csp.impression = Impression.objects.get(showpiority=impression)
            csp.description = description
            csp.save()

            # UPDATE Curriculumn
            print(user.id)
            curri = Curriculumn()

            curri = Curriculumn.objects.get(id=curriculum_id)
            curri.joined_user.append(user)

            curri.save()
            # Save CurriculumnLog
            lisProgressType = ProgressType.objects().order_by("rate")
            progressType = lisProgressType[0]

            curriLog = CurriculumnLog()

            curriLog.curriculumn = curri
            curriLog.process = progressType
            curriLog.data = "[]"
            curriLog.user_id = user

            curriLog.save()
            # SHOW Record
            cl = Curriculumn.objects(id=curriculum_id)
            has_curriculum = False
            is_mentor = False
            mentor = Mentor.objects(user=user.id)
            if len(mentor):
                is_mentor = True
            if len(cl):
                has_curriculum = True
            print(has_curriculum)
            clTaken = 0
            clLike = 0
            mtTaken = 0
            mtLike = 0
            actTaken = 0
            actLike = 0
            mtTotal = 0
            actTotal = 0
            try:
                for c in cl:
                    if c.statistic.currentTakenNumber:
                        clTaken += c.statistic.currentTakenNumber
                    if c.statistic.currentLikeNumber:
                        clLike += c.statistic.currentLikeNumber
                    for mt in c.material:
                        if mt.statistic.currentTakenNumber:
                            mtTaken += mt.statistic.currentTakenNumber
                        if mt.statistic.currentLikeNumber:
                            mtLike += mt.statistic.currentLikeNumber
                            mtTotal += 1
                    for act in c.action:
                        if act.statistic.currentTakenNumber:
                            actTaken += act.statistic.currentTakenNumber
                        if act.statistic.currentLikeNumber:
                            actLike += act.statistic.currentLikeNumber
                            actTotal += 1
            except Exception as e:
                print(e)
            is_joined = False
            if len(student):
                progress = CurriculumnStudyProgress.objects(curriculumn=cl[0].id, student=student[0].id)
                if len(progress) > 0:
                    is_joined = True
            context = {
                "cl": cl[0],
                "is_joined": is_joined,
                "user_id": request.user,
                "course_id": curriculum_id,
                "author": user.username,
                "is_mentor": is_mentor,
                "clTaken": clTaken,
                "clLike": clLike,
                "mtTaken": mtTaken,
                "mtLike": mtLike,
                "actTaken": actTaken,
                "actLike": actLike,
                "mtTotal": mtTotal,
                "actTotal": actTotal,
                "has_curriculum": has_curriculum,
            }
            return HttpResponseRedirect("course-detail?course_id=" + curriculum_id + "&user_id=" + user_id)
        elif request.POST["posttype"] == "deleteComment":
            try:
                comment_status = "0"
                comment_id = request.POST["hd_comment_id"]
                course_id = request.POST["hd_course_id"]
                author_id = request.POST["hd_author_course_id"]
                user_id = request.session["_auth_user_id"]

                cmt = Comment.objects.get(id=comment_id)
                cmt.status = comment_status
                cmt.save()
                status = "1"
                author = User.objects.get(id=author_id)
                cl = Curriculumn.objects(id=course_id)
                has_curriculum = False
                is_mentor = request.session["is_mentor"]
                user = User.objects.get(username=str(request.user))
                student = Student.objects.get(user=user.id)

                clTaken = 0
                clLike = 0
                mtTaken = 0
                mtLike = 0
                actTaken = 0
                actLike = 0
                mtTotal = 0
                actTotal = 0
                try:
                    for c in cl:
                        if c.statistic.currentTakenNumber:
                            c.statistic.currentTakenNumber = 10
                            clTaken += c.statistic.currentTakenNumber
                        if c.statistic.currentLikeNumber:
                            clLike += c.statistic.currentLikeNumber

                        for mt in c.material:
                            if mt.statistic.currentTakenNumber:
                                mtTaken += mt.statistic.currentTakenNumber
                            if mt.statistic.currentLikeNumber:
                                mtLike += mt.statistic.currentLikeNumber
                                mtTotal += 1
                            print(mt.name)
                        for act in c.action:
                            if act.statistic.currentTakenNumber:
                                actTaken += act.statistic.currentTakenNumber
                            if act.statistic.currentLikeNumber:
                                actLike += act.statistic.currentLikeNumber
                                actTotal += 1
                except Exception as e:
                    print(e)

                progress = CurriculumnStudyProgress.objects(curriculumn=cl[0].id, student=student.id)
                is_joined = False
                if len(progress) > 0:
                    is_joined = True

                lscl = []
                lscl = cl[0]
                for i in lscl.__getattribute__("material"):
                    i.note = "0"
                    try:
                        is_like = StatisticDetail.objects(object_id=str(i.id), status=status, user=user.id)
                        if len(is_like):
                            i.note = "1"
                            i.__getattribute__("statistic").currentLikeNumber -= 1
                    except Exception as e:
                        print(e)

                context = {
                    "cl": lscl,
                    "is_joined": is_joined,
                    "user_id": request.user,
                    "course_id": course_id,
                    "author_id": author_id,
                    "author": author.username,
                    "is_mentor": is_mentor,
                    "clTaken": clTaken,
                    "clLike": clLike,
                    "mtTaken": mtTaken,
                    "mtLike": mtLike,
                    "actTaken": actTaken,
                    "actLike": actLike,
                    "mtTotal": mtTotal,
                    "actTotal": actTotal,
                    "has_curriculum": has_curriculum,
                }
            except Exception as e:
                print(e)
            finally:
                return render(request, "myapp/course-detail.html", context)
        elif request.POST["posttype"] == "editComment":
            try:
                comment = request.POST["txtcommentName"]
                comment_id = request.POST["hd_comment_id"]
                course_id = request.POST["hd_course_id"]
                author_id = request.POST["hd_author_course_id"]
                user_id = request.session["_auth_user_id"]

                cmt = Comment.objects.get(id=comment_id)
                cmt.content = comment
                cmt.save()
                status = "1"
                author = User.objects.get(id=author_id)
                cl = Curriculumn.objects(id=course_id)
                has_curriculum = False
                is_mentor = request.session["is_mentor"]
                user = User.objects.get(username=str(request.user))
                student = Student.objects.get(user=user.id)

                clTaken = 0
                clLike = 0
                mtTaken = 0
                mtLike = 0
                actTaken = 0
                actLike = 0
                mtTotal = 0
                actTotal = 0
                try:
                    for c in cl:
                        if c.statistic.currentTakenNumber:
                            c.statistic.currentTakenNumber = 10
                            clTaken += c.statistic.currentTakenNumber
                        if c.statistic.currentLikeNumber:
                            clLike += c.statistic.currentLikeNumber

                        for mt in c.material:
                            if mt.statistic.currentTakenNumber:
                                mtTaken += mt.statistic.currentTakenNumber
                            if mt.statistic.currentLikeNumber:
                                mtLike += mt.statistic.currentLikeNumber
                                mtTotal += 1
                            print(mt.name)
                        for act in c.action:
                            if act.statistic.currentTakenNumber:
                                actTaken += act.statistic.currentTakenNumber
                            if act.statistic.currentLikeNumber:
                                actLike += act.statistic.currentLikeNumber
                                actTotal += 1
                except Exception as e:
                    print(e)

                progress = CurriculumnStudyProgress.objects(curriculumn=cl[0].id, student=student.id)
                is_joined = False
                if len(progress) > 0:
                    is_joined = True

                lscl = []
                lscl = cl[0]
                for i in lscl.__getattribute__("material"):
                    i.note = "0"
                    try:
                        is_like = StatisticDetail.objects(object_id=str(i.id), status=status, user=user.id)
                        if len(is_like):
                            i.note = "1"
                            i.__getattribute__("statistic").currentLikeNumber -= 1
                    except Exception as e:
                        print(e)

                context = {
                    "cl": lscl,
                    "is_joined": is_joined,
                    "user_id": request.user,
                    "course_id": course_id,
                    "author_id": author_id,
                    "author": author.username,
                    "is_mentor": is_mentor,
                    "clTaken": clTaken,
                    "clLike": clLike,
                    "mtTaken": mtTaken,
                    "mtLike": mtLike,
                    "actTaken": actTaken,
                    "actLike": actLike,
                    "mtTotal": mtTotal,
                    "actTotal": actTotal,
                    "has_curriculum": has_curriculum,
                }
            except Exception as e:
                print(e)
            finally:
                return render(request, "myapp/course-detail.html", context)
        else:
            comment = request.POST["txtComment"]
            course_id = request.POST["hd_course_id"]
            material_id = request.POST["hd_material_id"]
            user_id = request.session["_auth_user_id"]
            author_id = request.POST["hd_author_course_id"]
            ur = request.user
            cmt = Comment()
            cmt.user = request.user
            cmt.content = comment
            cmt.save()
            cl = Curriculumn.objects.get(id=course_id)
            mt = Material.objects.get(id=material_id)
            mt.comment.append(cmt)
            mt.save()
            cl.save()
            status = "1"
            print(author_id)
            author = User.objects.get(id=author_id)
            cl = Curriculumn.objects(id=course_id)
            has_curriculum = False
            is_mentor = request.session["is_mentor"]
            user = User.objects.get(username=str(request.user))
            student = Student.objects.get(user=user.id)

            clTaken = 0
            clLike = 0
            mtTaken = 0
            mtLike = 0
            actTaken = 0
            actLike = 0
            mtTotal = 0
            actTotal = 0
            try:
                for c in cl:
                    if c.statistic.currentTakenNumber:
                        c.statistic.currentTakenNumber = 10
                        clTaken += c.statistic.currentTakenNumber
                    if c.statistic.currentLikeNumber:
                        clLike += c.statistic.currentLikeNumber

                    for mt in c.material:
                        if mt.statistic.currentTakenNumber:
                            mtTaken += mt.statistic.currentTakenNumber
                        if mt.statistic.currentLikeNumber:
                            mtLike += mt.statistic.currentLikeNumber
                            mtTotal += 1
                        print(mt.name)
                    for act in c.action:
                        if act.statistic.currentTakenNumber:
                            actTaken += act.statistic.currentTakenNumber
                        if act.statistic.currentLikeNumber:
                            actLike += act.statistic.currentLikeNumber
                            actTotal += 1
            except Exception as e:
                print(e)

            progress = CurriculumnStudyProgress.objects(curriculumn=cl[0].id, student=student.id)
            is_joined = False
            if len(progress) > 0:
                is_joined = True

            lscl = []
            lscl = cl[0]
            for i in lscl.__getattribute__("material"):
                i.note = "0"
                try:
                    is_like = StatisticDetail.objects(object_id=str(i.id), status=status, user=user.id)
                    if len(is_like):
                        i.note = "1"
                        i.__getattribute__("statistic").currentLikeNumber -= 1
                except Exception as e:
                    print(e)

            context = {
                "cl": lscl,
                "is_joined": is_joined,
                "user_id": request.user,
                "course_id": course_id,
                "author_id": author_id,
                "author": author.username,
                "is_mentor": is_mentor,
                "clTaken": clTaken,
                "clLike": clLike,
                "mtTaken": mtTaken,
                "mtLike": mtLike,
                "actTaken": actTaken,
                "actLike": actLike,
                "mtTotal": mtTotal,
                "actTotal": actTotal,
                "has_curriculum": has_curriculum,
            }
            return render(request, "myapp/course-detail.html", context)
예제 #10
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")