Ejemplo n.º 1
0
def index(request):
	if request.method == 'GET':
		posts = MentorPost.objects
		user_type = ""
		try:
			user_type = request.session['user_type']
		except Exception:
			user_type = ""
			
		context = {'posts':posts,'user_type':user_type,'user_id':request.user,}
		return render(request,'myapp/personalhome.html', context)
	elif request.method == 'POST':
		posttype = request.POST['posttype']
		#post type = 2 mean lecture;
		if posttype == '2':
			#user_id = request.session['_auth_user_id']
			print("creating post...")
			Title = request.POST['txtTitle']
			Content = request.POST['txtContent']
			#FromDate = request.POST['dtpfromdate']
			#ToDate = request.POST['dtptodate']
			Amazonlink = request.POST['txtAmazonLink']
			#Cost = request.POST['txtCost']
			user_id = User.objects.get(id=request.session['_auth_user_id'])
			print(user_id)
			mp = MentorPost()
			mp.title = Title
			# 			mp.videolink = Videolink
			# 			mp.imagelink = Imagelink
			# 			mp.amazonlink = Amazonlink
			mp.content = Content
			mp.user_id = user_id
			mp.post_type = "2"
			mp.status = "1"
			#mp.from_date = FromDate
			#mp.to_date = ToDate
			mp.amazonlink = Amazonlink
			mp.save()
			#post created
			posts = MentorPost.objects
			user_type = ""
			try:
				user_type = request.session['user_type']
			except Exception:
				user_type = ""
				
			context = {'posts':posts,'user_type':user_type,'user_id':request.user,}
			return HttpResponseRedirect('/personalhome')
		elif posttype == '1':
			comment = request.POST['txtComment']
			post_id = request.POST['hd_post_id']
			user_id = request.session['_auth_user_id']
			cmt = CommentPost()
			cmt.content=comment
			cmt.user_id=User.objects.get(id=user_id)
			cmt.post_id=MentorPost.objects.get(id=post_id)
			cmt.save()# 		user_id = request.session
			post = MentorPost.objects.get(id=post_id)
			post.comments.append(cmt);
			post.save()
			user_type = ""
			try:
				user_type = request.session['user_type']
			except Exception:
				user_type = ""
			context = {'post':post,'user_type':user_type,'user_id':request.user,}
			context.update(csrf(request))
			context.update(context_processors.user(request))
			return HttpResponseRedirect('/personalhome')
		elif posttype == '3':
			title = request.POST['txtTitle']
			content = request.POST['txtContent']
			post_id = request.POST['post_id']
			user_id = request.session['_auth_user_id']
# 			cmt = CommentPost()
# 			cmt.content=comment
# 			cmt.user_id=User.objects.get(id=user_id)
# 			cmt.post_id=MentorPost.objects.get(id=post_id)
# 			cmt.save()
			esay = Esay()
			esay.title = title
			esay.content = content
			esay.save()
			post = MentorPost.objects.get(id=post_id)
			post.esay.append(esay);
			post.save()
			posts = MentorPost.objects
			user_type = ""
			try:
				user_type = request.session['user_type']
			except Exception:
				user_type = ""
			context = {'post':post,'user_type':user_type,'user_id':request.user,}
			context.update(csrf(request))
			context.update(context_processors.user(request))
		elif posttype == '4':
			comment = request.POST['txaComment']
			post_id = request.POST['post_id']
			user_id = request.session['_auth_user_id']

			cmt = CommentPost()
			cmt.content=comment
			cmt.user_id=User.objects.get(id=user_id)
			cmt.post_id=MentorPost.objects.get(id=post_id)
			cmt.save()# 		user_id = request.session
			post = MentorPost.objects.get(id=post_id)
			post.comments.append(cmt);
			post.save()
			user_type = ""
			try:
				user_type = request.session['user_type']
			except Exception:
				user_type = ""
			context = {'post':post,'user_type':user_type,'user_id':request.user,}
			context.update(csrf(request))
			context.update(context_processors.user(request))
			return HttpResponseRedirect('/personalhome')
		elif posttype == '5':
			rate = request.POST['txtrate']
			post_id = request.POST['post_id']
			user_id = request.session['_auth_user_id']

			rate = RatingPost()
			rate.starnumber=rate
			rate.user_id=User.objects.get(id=user_id)
			rate.post_id=MentorPost.objects.get(id=post_id)
			rate.save()# 		user_id = request.session
			post = MentorPost.objects.get(id=post_id)
			post.rating.append(rate);
			post.save()
			user_type = ""
			try:
				user_type = request.session['user_type']
			except Exception:
				user_type = ""
			context = {'post':post,'user_type':user_type,'user_id':request.user,}
			context.update(csrf(request))
			context.update(context_processors.user(request))
			return HttpResponseRedirect('/personalhome')
		return HttpResponseRedirect('/personalhome')
Ejemplo n.º 2
0
def index(request):
	if request.method == 'GET':
		print("method is get")
		context = {}
		return render(request, 'myapp/mentor-post.html', context)
	elif request.method == 'POST':
		print("method is get")
		Title = request.POST['txtTitle']
		Imagelink = request.POST['txtImagelink']
		Videolink = request.POST['txtVideolink']
		Amazonlink = request.POST['txtAmazonlink']
		Content = request.POST['txtContent']
		PostType = request.POST['slPostType']
		if PostType != '0':
			FromDate = request.POST['dtpfromdate']
			ToDate = request.POST['dtptodate']
			Place = request.POST['txtPlace']
		user_id = User.objects.get(id=request.session['_auth_user_id'])
		print(user_id)
		mp = MentorPost()
		mp.title = Title
		mp.videolink = Videolink
		mp.imagelink = Imagelink
		mp.amazonlink = Amazonlink
		mp.content = Content
		mp.user_id = user_id
		mp.post_type = PostType
		mp.status = "1"
		if PostType != '0':
			mp.from_date = FromDate
			mp.to_date = ToDate
			mp.place = Place
		mp.save()
		return HttpResponseRedirect('/home')