Пример #1
0
def setMsgReceiver(receivers, msg_id, receiver_type):
	for receiver in receivers:
		msg_receiver = MsgReceiver()
		msg_receiver.Msg_IDX = msg_id
		msg_receiver.ReceiverType = unicode(receiver_type)
		if type(receiver) == dict and receiver.has_key("Name"):
			msg_receiver.ReceiverID = unicode(receiver["UserID"])
			msg_receiver.ReceiverName = unicode(receiver["Name"])
		else:
			msg_receiver.ReceiverID = receiver
			msg_receiver.ReceiverName = ""
		msg_receiver.IsRead = unicode(0)
		
		Session.add(msg_receiver)
	Session.commit()
Пример #2
0
	def unit_write(self):
		if ("unit_idx" in request.params) and (request.params["unit_idx"] != ""):
			query = Session.query(Task_Unit).filter(Task_Unit.idx == request.params["unit_idx"])
			unit_record = query.first()
		else:
			unit_record = Task_Unit()
		
		unit_record.unit_name = request.params["unit_name"]
		# todo: unit_desc
		unit_record.unit_kind = ",".join(request.params.getall("usedTask"))
		
		Session.add(unit_record)
		Session.commit()
		
		return "{success: true}"
Пример #3
0
def sendSystemMessage(receiver, subject, content):
	""" 시스템에서 변경사항에 대해 쪽지를 발송 """
	
	TODAY_STR = datetime.datetime.now().strftime("%Y-%m-%d")
	NOW_STR = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
	
	sendCnt = 0		   
  
	receiverTo = getReceiver(receiver) 

	msgReceiver_q = Session.query(MsgReceiver).outerjoin(Msg).add_entity(Msg)
 
	for objReceiver  in receiverTo:
		
		q = msgReceiver_q.filter(Msg.SenderID == "system"). \
			filter(MsgReceiver.ReceiverType == u"0"). \
			filter(MsgReceiver.ReceiverID == objReceiver["UserID"]). \
			filter(Msg.CreateDate > TODAY_STR). \
			order_by(desc(Msg.CreateDate))
		rs = q.first()

		if q.count() > 0 and u"0" == rs[0].IsRead:
			# 쪽지를 읽지 않았다면 보낸 쪽지의 내용을 수정한다.
			modifyContent = rs[1].Content + u"\n %s --------- \n%s\n" % (NOW_STR, unicode(content))
			rs[1].Content = modifyContent

			Session.add(rs[1])
			Session.commit()
		else:
			rowMsg = Msg()
			rowMsg.SenderID = u"system"
			rowMsg.SenderName = u"업데이트"
			rowMsg.Subject = unicode(subject)
			rowMsg.Content = u"\n %s --------- \n%s\n "  % (NOW_STR, unicode(content))
			rowMsg.CreateDate = datetime.datetime.now()

			Session.add(rowMsg)
			Session.commit()

			rowReceiver = MsgReceiver()
			rowReceiver.Msg_IDX = rowMsg.idx
			rowReceiver.ReceiverType = u"0"
			rowReceiver.ReceiverID = objReceiver["UserID"]
			rowReceiver.ReceiverName = objReceiver["Name"]
			rowReceiver.IsRead = u"0"

			Session.add(rowReceiver)
			Session.commit()

			sendCnt += 1
		
	return sendCnt 
Пример #4
0
	def write(self, id, id2=None):
		""" 게시물 작성 처리 """
		
		dSave = {}
		bData = Archive("AdminBoard").getValues("AdminBoard.BCode == "+str(id), "IDX,AccessWrite" )
		
		if bData:
			if bData["AccessWrite"] == "" or bData["AccessWrite"].find(session["UserType"]) > -1:
				
				CopyDict( srcDic=request.params, destDic=dSave, keyList="IDX,Category,Status")#, prefix="Board.")
				
				dSave["BoardID"] = str(id)
				dSave["BoardIDX"] = bData["IDX"]
				dSave["Title"] = request.params["Title"]
				dSave["Content"] = request.params["Content"]
				
# [SH] 이 아래줄 부터 쭈욱 
				article_id = Archive("Board").New( **dSave )
				
				# File Upload
				objUpload = Upload()
				objUpload.BoardDir(dSave["BoardID"])
				upload_files = request.params.getall("bf_file")
				
				# 업로드한 파일 목록 가져오기(수정 모드일때)
				if dSave.has_key("IDX"):
					
					# File Delete
					selDeletedCheck = request.params.getall("delete_file")
					
					from sqlalchemy import and_
					
					board_attach_q = Session.query(BoardAttach)
					board_attach = board_attach_q.filter(
						and_(
							BoardAttach.article_idx == dSave["IDX"],
							BoardAttach.id.in_(selDeletedCheck)
						)
					).all()
					
					# 파일이 있을때만 삭제하도록 변경
					for attach_item in board_attach:
						if os.path.exists(attach_item.new_path):
							os.unlink(attach_item.new_path)
							Session.delete(attach_item)
					
					Session.commit()
				
				for upload_file in upload_files:
					if type(upload_file) == unicode:
						# 빈 문자열이 넘어온 경우 처리를 건너뛴다.
						continue
					
					# 실제 파일 업로드를 여기에서 수행한다.
					new_file = objUpload.upload_file_move(upload_file)
					
					board_attach_row = BoardAttach()
					board_attach_row.board_code = unicode(dSave["BoardID"])
					if dSave.has_key("IDX"):
						board_attach_row.article_idx = dSave["IDX"]
					else:
						board_attach_row.article_idx = article_id
					board_attach_row.org_path = unicode(new_file["O_PATH"])
					board_attach_row.new_path = new_file["D_PATH"]
					board_attach_row.filesize = unicode(new_file["SIZE"])
					
					Session.add(board_attach_row)
					Session.commit()
# ------------------------------------------------------------				  
				return okMessage("작성되었습니다.")
			else:
				return errMessage("작성 권한이 없습니다.")
		else:
			return errMessage("게시판 구분아이디가 잘못 전달되었습니다")
Пример #5
0
def sendMessage( receiver, receiverCC, receiverBCC, subject, content, attachments=None, withSMS=None ):
	""" 쪽지함에 쪽지를 발송"""
	
	#[TODO] IF not logined !!

	withEmail = True

	emailList = []
	smsList = []
	msgIDXs = []

	receiverTo = getReceiver(receiver)
	receiverCc = getReceiver(receiverCC)
	receiverBcc = getReceiver(receiverBCC)
	
	# 쪽지 내용 저장
	msg = Msg()
	msg.SenderID = unicode(Login.getID())
	msg.SenderName = unicode(Login.getName())
	msg.Subject = unicode(subject)
	msg.Content = unicode(content)
	msg.withSMS = unicode(withSMS)
	msg.CreateDate = datetime.datetime.now() 
	
	Session.add(msg)
	Session.commit()
	
	# To들에게 보내기
	setMsgReceiver(receiverTo, msg.idx, "0")
	# CC들에게 보내기
	setMsgReceiver(receiverCc, msg.idx, "1")
	# BCC들에게 보내기
	setMsgReceiver(receiverBcc, msg.idx, "2")

	# SMS 발송 관련 처리
	if withSMS:
		smsList = list()
		receiverList = receiverTo + receiverCc +receiverBcc
		for msg_receiver in receiverList:
			if type(msg_receiver) != dict:
				continue
			smsList.append(msg_receiver["HandPhone"])

		if len(smsList) > 0:
			SMS.send(sendMsg=u"[sparta] %s" % msg.Content[:70], recvList=smsList)
	
	if withEmail:
		senderData = getReceiver("<%s>" % Login.getID())[0]["GwID"]
		emailList = list()
		receiverList = receiverTo + receiverCc +receiverBcc
		for msg_receiver in receiverList:
			if type(msg_receiver) != dict:
				continue			
			if str(msg_receiver["GwID"]).startswith("D"):
				emailList.append( str(msg_receiver["GwID"])+"@idea.co.kr" )
		if len(emailList) > 0:
			sendEmail("*****@*****.**" % senderData, msg.Subject, msg.Content, recvList=emailList)
   
	if attachments:
		objUpload = Upload()
		objUpload.MsgInitialize()
		
		for attach_item in attachments:
			new_file = objUpload.upload_file_move(attach_item)

			rowMsgAttach = MsgAttach()
			rowMsgAttach.Msg_IDX = unicode(msg.idx)
			rowMsgAttach.OriginalFileName = unicode(new_file["O_PATH"])
			rowMsgAttach.NewFileName = unicode(new_file["D_PATH"])
			rowMsgAttach.FileSize = unicode(new_file["SIZE"])

			Session.add(rowMsgAttach)

		Session.commit()
	return len(receiverTo)