def index(request): if request.method == 'GET': vpost_id = request.GET['post_id'] post = MentorPost.objects.get(id=vpost_id) # comments = CommentPost.objects(post_id=vpost_id).all() comments = post.comments context = { 'post':post,'comments':comments, 'user_type':request.session['user_type'], 'user_id':request.user, } return render(request, 'myapp/post-detail.html', context) elif request.method == 'POST': 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() # comments = CommentPost.objects(post_id=post_id).all() comments = post.comments c = {'post':post,'comments':comments,'user_type':request.session['user_type']} c.update(csrf(request)) c.update(context_processors.user(request)) return render_to_response("myapp/blog-single.html", c)
def index(request): if (request.user.is_authenticated()==False) or(request.user is None): return render(request, 'myapp/home1.html', {}) elif request.method == 'GET': # posts = MentorPost.objects # user_type = "" # try: # user_type = request.session['user_type'] # is_mentor = request.session['is_mentor'] # if is_mentor: # return HttpResponseRedirect('/mentor-course?user_id='+str(request.user.id)) # else: # return HttpResponseRedirect('/search-mentor') # except Exception: # user_type = "" try: is_mentor = request.session['is_mentor'] except Exception as e: is_mentor = False if is_mentor: return HttpResponseRedirect('/mentor-course?user_id='+str(request.user.id)) else: return HttpResponseRedirect('/student-home') # context = {'posts':posts,'user_type':user_type,'user_id':request.user,} # return render(request,'myapp/index.html', context) # return HttpResponseRedirect('/personalhome') # return render(request, 'myapp/home.html', {}) elif request.method == 'POST': 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 render_to_response("myapp/index.html", context)
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')