예제 #1
0
def index(request):
	lisUserProfile = {}
# 	print('begin')
# 	for user in lisUserProfile:
# 		print(user.company)
# 	print('finish')
	c = {'lisUserProfile':lisUserProfile,}
	if request.method == 'GET':
		return render(request, 'myapp/search-mentor.html', c)
	elif request.method == 'POST':
		try:
			keyword = request.POST['search']
			users = User.objects(Q(first_name__icontains=keyword) | Q(last_name__icontains=keyword))
			#search data
# 			lisUserProfile = UserProfile.objects(user_id__in=users,is_mentor=True)
			lisUserProfile = UserProfile.objects(user_id__in=users)
			
			listAllCurriculumn = Curriculumn.objects()
			listCurriculumn =Curriculumn.objects(name__icontains=keyword)
			c = {'lisUserProfile':lisUserProfile,'listCurriculumn':listCurriculumn,'listAllCurriculumn':listAllCurriculumn,'search':keyword}
			#get data from mongodb
			c.update(csrf(request))
			c.update(context_processors.user(request))
			return render_to_response("myapp/search-mentor.html", c)
		except Exception:
			c.update(csrf(request))
			c.update(context_processors.user(request))
			return render_to_response("myapp/search-mentor.html", c)
	return render(request, 'myapp/search-mentor.html', c)
예제 #2
0
def index(request):
	lisUserProfile = UserProfile.objects
# 	print('begin')
# 	for user in lisUserProfile:
# 		print(user.images)
# 	print('finish')
	c = {'lisUserProfile':lisUserProfile,}
	if request.method == 'GET':
		return render(request, 'myapp/people-directory.html', c)
	elif request.method == 'POST':
		try:
			keyword = request.POST['keyword']
			users = User.objects(first_name__icontains=keyword)#search data
			lisUserProfile = UserProfile.objects(user_id__in=users)
			c = {'lisUserProfile':lisUserProfile,'keyword':keyword}
# 			profile = Profile()
# 			profile.name = 'Nusja Nawancali'
# 			profile.image_url='images/user3.png'
# 			profile.address='Phuket, Thailand'
# 			profile.location='Product Manager'
# 			profile.company='SomeCompany, Inc.'
# 			profile.save()

			#get data from mongodb
			c.update(csrf(request))
			c.update(context_processors.user(request))
			return render_to_response("myapp/people-directory.html", c)
		except Exception:
			c.update(csrf(request))
			c.update(context_processors.user(request))
			return render_to_response("myapp/people-directory.html", c)
	return render(request, 'myapp/test.html', c)
예제 #3
0
def updateProfile(request):
	if request.method == 'GET':
		job_titles = JobTitle.objects
		work_fields = WorkField.objects
		context = {'job_titles':job_titles, 'work_fields':work_fields, 'acccount_type':request.GET['acccount_type'], }
		return render(request, 'myapp/create-profile-update.html', context)
	elif request.method == 'POST':
		try:
			acccount_type = request.POST['acccount_type']
			jobTitle = request.POST['slJobTitle']
			workField = request.POST['slWorkField']
			company = request.POST['txtCompany']
			about = request.POST['txtAbout']
			_profile = UserProfile.objects.get(user_id=request.user)
			_profile.job_title = JobTitle.objects.get(id=jobTitle)
			_profile.work_field = WorkField.objects.get(id=workField)
			_profile.user_type = UserType.objects.get(code=acccount_type)
			_profile.user_id = request.user
			_profile.company = company
			_profile.about = about
			_profile.save()
			request.session['user_type'] = acccount_type
			return HttpResponseRedirect('/home')
		except Exception as e:
			print(e)
			c = {
				'error_message':e, 'job_titles':JobTitle.objects, 'work_fields':WorkField.objects, 'acccount_type':request.GET['acccount_type'],
				}
			c.update(csrf(request))
			c.update(context_processors.user(request))
			return render_to_response("myapp/create-profile-update.html", c)
예제 #4
0
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)
예제 #5
0
파일: SignIn.py 프로젝트: cuongnmeas/ase
def index(request):
	username = ""
	password = ""
	if request.method == 'GET':
		return render(request, 'myapp/signin.html', {})
	elif request.method == 'POST':
		username = request.POST['txtUserName']
		password = request.POST['txtPassWord']
		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)
				profile = UserProfile.objects.get(user_id=user)
				request.session['user_images'] = profile.images
				request.session['is_mentor'] = profile.is_mentor
				if profile.is_mentor:
					return HttpResponseRedirect('/mentor-course?user_id='+str(user.id))	
				else:
					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', {})
예제 #6
0
파일: SignUp.py 프로젝트: cuongnmeas/ase
def getSignupError(request,e,firstname,lastname,username,password,email):
	c = {
			'error_message':e,
			'firstname':firstname,
			'lastname':lastname,
			'username':username,
			'password':password,
			'email':email,
			'rangerDay':range(1,31),
			'rangerYear':range(2014,1905,-1),
		}
	c.update(csrf(request))
	c.update(context_processors.user(request))
	return render_to_response("myapp/signup.html", c)
예제 #7
0
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)
예제 #8
0
파일: d_NewCus.py 프로젝트: cuongnmfis/dms
def getNewCusError(request,e,firstname,lastname,idNo,address,homeaddress,phonenumber,about):
	
	c = {
			'error_message':e,
			'firstname':firstname,
			'lastname':lastname,
			'txtidNo':idNo,
			'txtAddress':address,
			'txtHomeAddress':homeaddress,
			'txtPhoneNumber':phonenumber,
			'txtAbout':about,
			'rangerDay':range(1,31),
			'rangerYear':range(2014,1905,-1),
		}
	c.update(csrf(request))
	c.update(context_processors.user(request))
	return render_to_response("myapp/d-NewCus.html", c)
예제 #9
0
파일: SignIn.py 프로젝트: cuongnmfis/dms
def index(request):
	username = ""
	password = ""
	defaultUserImage = "/images/avatar/default.png"
	
	if 'next' in request.GET:
		nextpage = request.GET['next']
	else:
		nextpage = ""
			
	if request.method == 'GET':
		return render(request, 'myapp/signin.html', {})
	elif request.method == 'POST':
		username = request.POST['txtUserName']
		password = request.POST['txtPassWord']
		
		try: 
			
			user = User.objects.get(username=username)
			
			if user.check_password(password):
				logout(request)
				user.backend = 'mongoengine.django.auth.MongoEngineBackend'
				login(request, user)


				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:
					return HttpResponseRedirect('/custom-debit-detail?type=loan')
			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', {})
예제 #10
0
def index(request):
	lisUserProfile = {}
# 	listParentCategory = Category.objects(parentCategory = None)
	lisCategory =Category.objects()
# 	print('begin')
# 	for user in listCategory:
# 		if user.parentCategory is not None :
# 			print(user.parentCategory.categoryName)
# 	print('finish')
	
	if len(lisCategory) > 0:
		category=lisCategory[0]
		c = {'lisUserProfile':lisUserProfile,'listCategory':lisCategory,'category':category}
	else:
		c = {'lisUserProfile':lisUserProfile,'listCategory':lisCategory}
	if request.method == 'GET':
		return render(request, 'myapp/search-mentor.html', c)
	elif request.method == 'POST':
		
		try:
			lisUserProfile={}
			listCurriculumn={}
			lisCategory =Category.objects()
			user=User.objects.get(username=str(request.user))
			mentor=Mentor.objects(user=user.id)
			
			keyword = request.POST['search']
			parentCategory = request.POST['parentCategory'];
			childrenCategory =request.POST['childrenCategory'];
			#search data
# 			users = User.objects(Q(first_name__icontains=keyword) | Q(last_name__icontains=keyword))
# 			lisUserProfile = UserProfile.objects(user_id__in=users,is_mentor=True)
			
# 			categoryObject =Category.objects.get(id=childrenCategory)
			if len(mentor)>0:
				mt=mentor[0]
				listCurriculumn =Curriculumn.objects(category=childrenCategory ,name__icontains=keyword).order_by('published_date')
			else:
				listCurriculumn =Curriculumn.objects(category=childrenCategory ,name__icontains=keyword).order_by('published_date')
# 			listCurriculumn =Curriculumn.objects(name__icontains=keyword)
			c = {'lisUserProfile':lisUserProfile,'listCurriculumn':listCurriculumn,'listCategory':lisCategory,'search':keyword,'parentCategory':parentCategory,'childrenCategory':childrenCategory}
			#get data from mongodb
			c.update(csrf(request))
			c.update(context_processors.user(request))
			return render_to_response("myapp/search-mentor.html", c)
		except Exception:
			lisUserProfile={}
			listCurriculumn={}
			lisCategory =Category.objects()
			user=User.objects.get(username=str(request.user))
			mentor=Mentor.objects(user=user.id)
			keyword = request.POST['search']
			parentCategory = request.POST['parentCategory'];
			if len(mentor)>0:
				mt=mentor[0]
				listCurriculumn =Curriculumn.objects(name__icontains=keyword).order_by('published_date')
			else:
				listCurriculumn =Curriculumn.objects(name__icontains=keyword).order_by('published_date')
			c = {'lisUserProfile':lisUserProfile,'listCurriculumn':listCurriculumn,'listCategory':lisCategory,'search':keyword,'parentCategory':parentCategory}
			c.update(csrf(request))
			c.update(context_processors.user(request))
			return render_to_response("myapp/search-mentor.html", c)
	return render(request, 'myapp/search-mentor.html', c)
예제 #11
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')
예제 #12
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', {})