示例#1
0
def sessionLogin():
	if request.method  == "POST":  
		email    = request.form['email']
		password  = request.form['password']

		user = query_db('select * from users where email=\"'+email+'\"', one=True)
		if user is None:
		    return 'No such email'
		else:
			if user['password'] == password:
				print user['username'],user['role'],' passed login authentication.'
				session['email'] = user['email']
				session['username'] = user['username']
				session['role'] = user['role']
				session['password'] = user['password']
				session['profile_pic'] = user['profile_pic']

				######!!!!!! 아이 테이블에서 사진 정보를 가져와 세션정보에 굽고 JSON리턴에 더해주기	
				if session['role'] == 'parent':
					childInfo = query_db('select * from children where parent_email=\"'+email+'\"', one=True)
					if childInfo is None:
					    return 'No such child'
					else:			
						session['child_pic'] = childInfo['profile_pic']
						session['child_name'] = childInfo['name']
					
					return jsonify(username=session['username'],email=session['email'],role=session['role'],password=session['password'],profile_pic=session['profile_pic'],childProfile_pic=session['child_pic'],child_name=session['child_name'])
				else :
					return jsonify(username=session['username'],email=session['email'],role=session['role'],password=session['password'],profile_pic=session['profile_pic'])
				
			else: 
				return "Password is incorrect."
def getMyPartners(role, email):
	lResult = [] # 친구들의 정보를 담아 return할 결과 배열
	friendInfo = {} # 친구 한 명, 한 명의 정보를 담을 친구정보 딕셔너리

	#DB에 쿼리요청을 보내서 레코드를 받아온다.

	for friendInfo in query_db(getMyFriendsQueryByRole(role,email)):

		# DB 요청에서 받아온 레코드를 하나씩(user) 순회하면서 JSON을 만들기 위한 작업을 수행한다.
		# 친구정보 딕셔너리에 현재 친구인지 여부도 기록
		friendInfo["currentFriend"] = isCurrentPartner(friendInfo["startDate"], friendInfo["endDate"], get10numberTimestamp())
		if role == 'classTeacher' :
			# 상대가 엄마인 경우 아이의 이름과 아이ID, 프로필 사진주소 를 가져온다. 
			childInfo = query_db('select name,child_id,profile_pic from children where parent_email=\''+friendInfo['email']+'\'')
			if childInfo is None:
			    print 'No child'
			else: #부모 당 아이수가 1명일 경우를 가정하여서 이렇게 만들었는데 아니라면? 고쳐야 한다 ㅠ
			    friendInfo["childname"] = childInfo[0]['name']		
			    friendInfo["child_id"] = childInfo[0]['child_id']		
			    friendInfo["childprofile_pic"] = childInfo[0]['profile_pic']		
		
			#  아이의 위키정보도 가져온다 
			childWiki = query_db('select id,title,content from child_description where child_id='+str(friendInfo["child_id"]))
			if childWiki is None:
			    print 'No such child profile'
			else:
				friendInfo["childDescription"] = []
				for singleWikiSection in childWiki:
				    friendInfo["childDescription"].append(singleWikiSection)
		elif role == 'parent':
			#  내 아이의 위키정보도 가져온다 
			child_id_list = query_db('select * from children where parent_email=\''+email+'\'')
			
			childWiki = query_db('select id,title,content from child_description where child_id='+str(child_id_list[0]['child_id']))
			friendInfo["child_id"]=child_id_list[0]['child_id']
			friendInfo["childprofile_pic"]=child_id_list[0]['profile_pic']
			friendInfo["childname"]=child_id_list[0]['name']
			
			if childWiki is None:
				friendInfo["childDescription"] = []
				print 'No such child profile'
			else:
				friendInfo["childDescription"] = []
				for singleWikiSection in childWiki:
				    friendInfo["childDescription"].append(singleWikiSection)
	
			

		# 친구정보를 하나씩 리스트에 삽입하기
		lResult.append(friendInfo)

	return json.dumps(lResult)
				
示例#3
0
def ajax_publishAnnouncementNote() :
	if (request.method == 'POST') :	
		# 'method' : 'publish' 또는 'delete'
		method = request.form['method']	
		if ( method== 'publish') :
			### id 는 자동적으로 입력해줌

			publisher_email = request.form['publisher_email']

			published_date = request.form['published_date']
			content = request.form['content']
			
			numOfReceivers = (len(request.form)-5) / 2
			
			# 우선 공통공지사항들을 보냅니다
			sQuery = 'INSERT INTO common_announcement (publisher_email,published_date,content) '
			sQuery = sQuery + 'VALUES (\'' + publisher_email+ '\',\'' + published_date + '\',\'' + content+'\')'
			
			g.db.execute(sQuery)
			g.db.commit()
			
			sQuery = 'SELECT id FROM common_announcement where publisher_email = \''
			sQuery = sQuery + publisher_email + '\' AND published_date = \'' + published_date+'\''
			common_announcement_id = query_db(sQuery)
				
			# 각각의 개인 공지는 individual_announcement KEY 안의 딕셔너리들!
			# 따라서 individual_announcement를 하나하나 업데이트 해줍니다.
			# 업데이트 사항은 content와 publisher_email, common_announcement_id
			sQuery = ""
			for i in range(numOfReceivers):
				sQuery = 'INSERT INTO individual_announcement '
				sQuery = sQuery + '(content,receiver_email,common_announcement_id) VALUES (\''
				sQuery = sQuery + request.form['individual_announcement['+str(i)+'][content]'] + '\',\''
				sQuery = sQuery + request.form['individual_announcement['+str(i)+'][receiver_email]'] + '\',' 
				sQuery = sQuery + str(common_announcement_id[0]['id'])+')'
				g.db.execute(sQuery)
				g.db.commit()
			
			return json.dumps(["알림장 발행 완료"])
		# 해당 아디를 갖는 모든 공통공지 개별공지 지워뿌림.
		elif (method == 'delete') :
			# 지울놈 아이디 기억해 둡니다
			target_id = request.form['id']

			# 우선 individual_announcement 테이블에서
			# common_announcement_id == target_id 인 놈들을 지워요
			sQuery = 'DELETE FROM individual_announcement WHERE common_announcement_id = ' + target_id
			g.db.execute(sQuery)
			g.db.commit()

			# 그 뒤에 common_annoucement 테이블에서
			# id = target_id 인 놈들을 지워요
			sQuery = 'DELETE FROM common_announcement WHERE id =' + target_id
			g.db.execute(sQuery)
			g.db.commit()
			
			return json.dumps(["알림장 삭제 완료"])
def getNoteConfirmationCheck(email):
	#common_announcement 에서 published_date를 내림차순으로 정렬한 상태로 받아와 finder 리스트로 만든다
	finder=query_db('SELECT published_date FROM common_announcement WHERE publisher_email=\''+email+'\' ORDER BY published_date desc')
	keyDate=finder[0]['published_date']
	#내림차순으로 정렬했으므로 finder[0]이 가장 최근 날짜임. 날짜 값만 keyDate로 받는다.		
	dResult={} 
	#DB에 쿼리요청을 보내서 레코드를 받아온다.
	for mailData in query_db('select id from common_announcement where published_date=\'' + keyDate +'\' and publisher_email=\''+email+'\''):
		receiver = []
		dResult["published_date"]=keyDate
		for receiverData in query_db('select email, username, confirmed_date, response_message_date from users, individual_announcement where users.email=individual_announcement.receiver_email and individual_announcement.common_announcement_id=' + str(mailData['id']))	:				
			parents={}
			parents["email"]=receiverData['email']
			parents["username"]=receiverData['username']
			parents["confirmed_date"]=receiverData['confirmed_date']
			parents["response_message_date"]=receiverData['response_message_date']
			receiver.append(parents)
		dResult["receiver"]=receiver
	return json.dumps(dResult)
			
		
示例#5
0
def ajax_getUserProfilePic():
	if request.method == 'POST' :
		email = request.form["email"]
		sQuery = 'SELECT email,username,profile_pic,role FROM users '
		sQuery = sQuery + 'WHERE email =\''  +email+'\''
		userInfo = query_db(sQuery)	
		userInfo[0]['a'] = request.form["a"]
		userInfo[0]['j'] = request.form["j"]
		if(userInfo):
			return json.dumps(userInfo[0])
		else :
			return json.dumps(["there is no person"])
def getAnnouncementNotes(role, userEmail):
	dResult = {}
	publisherEmail = userEmail
	## 총 공통공지 개수를 저장하는 변수
	total_common_announcement = 0
	if role == 'parent':
		dMyPartners = json.loads(getMyPartners(role,userEmail))
		currentClassTeacherEmail = ""
		for teacher in dMyPartners:
			if teacher['currentFriend']:
				publisherEmail = teacher['email']
				break
				
	# for문을 통해 total_common_announcement의 개수를 세서 입력
	for common_announcement in query_db('select * from common_announcement \
			where publisher_email='+'\''+publisherEmail+'\''):
		total_common_announcement = total_common_announcement + 1

	# dResult에 다음의 key들을 추가합니다.
	dResult['total_common_announcement'] = total_common_announcement
	dResult['num_of_article_per_request'] = 5

	# dResult['page']를 구하기 위한 연산과정. request당 한 페이지, 한 페이지 당 5개
	if (total_common_announcement % dResult['num_of_article_per_request']) != 0 :
		dResult['page'] = total_common_announcement / dResult['num_of_article_per_request'] + 1
	else :
		dResult['page'] = total_common_announcement / dResult['num_of_article_per_request']
		
	dResult['articles'] = []

	# dResult['articles'] 에 쓸 내용 담기위해 dArticles 딕셔너리를 만들었어욧.
	dArticles = {}
	dArticles['individual_announcement'] = []

	# cur_id 의 초기값을 -1로 합니다.
	cur_id = -1

	# 현재 로그인 id가 session['email']이면 query_db의내용을 하나하나 불러옵니다
	for common_announcement in query_db('select * from common_announcement where publisher_email='+'\''+publisherEmail+'\''):

		# 현재 individual_announcement의 id가 common_announcement의 id와 같으면
		# individual_announcement를 append 합니다.
		indivisual_announcement_query = 'select * from individual_announcement where common_announcement_id='+str(common_announcement['id'])

		if role == 'parent':
			indivisual_announcement_query = indivisual_announcement_query + ' AND receiver_email=\''+session['email']+'\''

		for individual_announcement in query_db(indivisual_announcement_query):
			dArticles['individual_announcement'].append(individual_announcement)

		# cur_id가 common_announcement['id']와 다르다면
		# 즉 common_announcement의 loop가 충분히 돌아 다른 날짜의 글로 넘어갔다면
		# 다음 내용들을 실행합니다.
		if cur_id != common_announcement['id']:
			dArticles['published_date'] = common_announcement['published_date']
			dArticles['publisher_email'] = common_announcement['publisher_email']
			dArticles['content'] = common_announcement['content']
			dArticles['id'] = common_announcement['id']
			dArticles['attached_file'] = common_announcement['attached_file']

			# 앞의 내용들이 다 저장되었으면 최종적으로 dResult에 append 합니다
			dResult['articles'].append(dArticles)

			# append 이후 dArticles 를 초기화합니다.
			dArticles = {}
			dArticles['individual_announcement'] = []

			cur_id = common_announcement['id']

	## json.dumps() 함수안에 인자로 리스트나 딕셔너리를 넣어주면
	## JSON 스트링으로 바꿔준다. 
	return json.dumps(dResult)	
示例#7
0
def getParent():
	sResult = ""
	for parent in query_db('select * from parent'):
		sResult += parent['name']+ ' '+ parent['email'] + '\n'
	return sResult
示例#8
0
def ajax_respondToAnnouncementNote():
	# 메소드가 POST인 경우에만 동작한다.
	if request.method == 'POST' :

		# 각 변수에 값을 할당
		parent_email = request.form["parent_email"]
		common_announcement_id = request.form["common_announcement_id"]
		method = request.form["method"]
		date = request.form["date"]
		sQuery = ""
	

		# 부모가 알림장 확인을 한 경우
		if method == 'confirm':		
			# <확인 날짜>만 업데이트
			sQuery = 'UPDATE individual_announcement '
			sQuery = sQuery + 'SET confirmed_date =\'' +date+ '\'' 
			sQuery = sQuery + 'WHERE receiver_email = \'' +parent_email+ '\''
			sQuery = sQuery + 'AND common_announcement_id = ' +common_announcement_id
			g.db.execute(sQuery)
			g.db.commit()
			
			return  json.dumps(["gooood"])

		# 부모가 알림장에 댓글을 단 경우
		elif method == 'reply':
			response_message = request.form["response_message"]

			# 댓글을 달기 전에 확인버튼을 눌렀는지 알아내기 위해 확인 날짜를 체크
			sQuery = 'SELECT confirmed_date FROM individual_announcement '
			sQuery = sQuery + 'WHERE common_announcement_id ='  +common_announcement_id
			sQuery = sQuery + ' AND receiver_email = \'' +parent_email+ '\''
			check_confirmed_date = query_db(sQuery)
			
			# 댓글을 달기 전에 확인버튼을 눌렀으면 <댓글 내용과 댓글 날짜>만 업데이트
			if (check_confirmed_date[0]['confirmed_date']) :
				sQuery = 'UPDATE individual_announcement '
				sQuery = sQuery + 'SET response_message_date = \'' +date+ '\', '
				sQuery = sQuery + 'response_message = \'' +response_message+ '\' '
				sQuery = sQuery + 'WHERE receiver_email = \'' +parent_email+ '\' '
				sQuery = sQuery + 'AND common_announcement_id =' +common_announcement_id
			
			# 댓글을 달기 전에 확인버튼을 누르지 않았으면 <댓글 내용, 댓글 날짜, 확인 날짜>까지 업데이트
			else :
				sQuery = 'UPDATE individual_announcement '
				sQuery = sQuery + 'set confirmed_date =\'' +date+ '\', response_message_date = \'' +date+ '\', '
				sQuery = sQuery + 'response_message = \'' +response_message+ '\' '
				sQuery = sQuery + 'where receiver_email = \'' +parent_email+ '\' '
				sQuery = sQuery + 'AND common_announcement_id = ' +common_announcement_id
					
			g.db.execute(sQuery)
			g.db.commit()

			return  json.dumps(["gooood"])

		# 부모가 알림장에 단 댓글을 지우고 싶을 때
		elif method == 'delete':
			sQuery = 'UPDATE individual_announcement '
			sQuery = sQuery + 'SET response_message_date = null, '
			sQuery = sQuery + 'response_message = null '
			sQuery = sQuery + 'WHERE common_announcement_id ='  +common_announcement_id
			sQuery = sQuery + ' AND receiver_email = \'' +parent_email+ '\''
			g.db.execute(sQuery)
			g.db.commit()

			return  json.dumps(["gooood"])