def delete(self, id="json"): # 필수 입력 인자 client_request_key = request.params.keys() # 태이크 고유 번호 if "takeNo" not in client_request_key: response.status_int = 403 return "Required variable Not Exists - takeNo" takeNo = request.params["takeNo"] # Take Attr Delete take_attr_sql = "delete from Take_Attr where ParentIDX = %d" % int(takeNo) Session.execute(take_attr_sql) Session.commit() # Take Delete take_sql = "delete from Take where IDX = %d" % int(takeNo) Session.execute(take_sql) Session.commit() if "json" == id: return '{"success": true}' else: return "<success>true</success>"
def remove(self, id, id2): # [SH] ------------------------------- board_attach_q = Session.query(BoardAttach) board_attach = board_attach_q.filter_by(article_idx = id2).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() # ---------------------- [SH] Archive("Board").Remove( id2 ) return okMessage("삭제되었습니다.")
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()
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}"
def unit_remove(self): unit_idx = request.params["idx"] print unit_idx if unit_idx != None: query = Session.query(Task_Unit).filter(Task_Unit.idx == unit_idx) fetchrow = query.first() Session.delete(fetchrow) Session.commit() return "{success: true}" else: return "{success: false, errorMessage: \"none data\"}"
def removeMessage(msgidx): msg_receiver_q = Session.query(MsgReceiver).filter_by(idx = msgidx).first() if None == msg_receiver_q: raise SpartaUserError("존재하지 않는 쪽지입니다") # 로그인한 사용자가 메시지를 받은 사용자가 아닌 경우 삭제할 수 없다는 메시지를 출력하게 한다. if msg_receiver_q.ReceiverID != Login.getID() and (not CheckAdmin()): raise SpartaAccessError("메시지를 삭제할 수 있는 권한이 없습니다") msg_receiver_q.IsDelete = u"1" Session.commit() # 항상 1을 반환한다. return 1
def getMessage(msgReceiver_idx, readStamp=True): """ 쪽지를 읽어온다 """ msgReceiver_q = Session.query(MsgReceiver).outerjoin(Msg).add_entity(Msg) msg = msgReceiver_q.filter(MsgReceiver.idx == msgReceiver_idx).first() if None == msg: raise SpartaUserError("존재하지 않는 쪽지입니다") # 로그인 중인 사용자와 메시지를 받은 사용자 ID를 비교하여 일치하지 않으면 권한 오류를 발생시킨다. if Login.getID() != msg[0].ReceiverID: raise SpartaUserError("메시지를 볼 수 있는 권한이 없습니다") # 읽음여부 수정 if u"0" == msg[0].IsRead: msg[0].IsRead = u"1" Session.commit() outText = msg[1].Content # 첨부파일 가져오기 msgAttach_q = Session.query(MsgAttach).filter_by(Msg_IDX = msg[1].idx).all() attach_text = [] if len(msgAttach_q) > 0: attach_text.append("<table class=\"filedownBox\">") attach_text.append(u"<tr><td rowspan=\"%d\">첨부</td><td>" % len(msgAttach_q)) for attach_item in msgAttach_q: attach_text.append("<a href=\"/getfile/nmessage/%d\">%s</a><br />" % (attach_item.idx, attach_item.OriginalFileName) ) attach_text.append("</td></tr></table>") attach_text = "".join(attach_text) return "<p>%s</p>%s" % (outText, attach_text)
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
def removeSendMessage(sendidx): # 메시지 정보를 가져온다. msg_q = Session.query(Msg).filter(Msg.idx == sendidx) if msg_q.count() == 0: raise SpartaUserError("존재하지 않는 쪽지입니다") msg = msg_q.first() if msg.SenderID != Login.getID() and (not CheckAdmin()): raise SpartaAccessError("메시지를 삭제할 수 있는 권한이 없습니다") # 수신자 지우기 receiver_q = Session.query(MsgReceiver).filter(MsgReceiver.Msg_IDX == sendidx) if receiver_q.count() > 0: # 수신자중에 한명이라도 메시지를 읽지 않았다면 쪽지를 삭제하지 못하게 한다. for receiver_user in receiver_q.all(): if receiver_user.IsDelete == u"0": return u"%s 사용자가 아직 쪽지를 읽지 않았습니다" % receiver_user.ReceiverID receiver_q.delete() Session.commit() # 우선 첨부파일 정보를 가져온다. attach_q = Session.query(MsgAttach).filter(MsgAttach.Msg_IDX == sendidx).all() if len(attach_q) > 0: for attach_info in attach_q: # File Exists if os.path.exists(attach_info.NewFileName): os.unlink(attach_info.NewFileName) Session.delete(attach_info) Session.commit() # 본 메시지 삭제 msg_q = Session.delete(msg) Session.commit() return 1
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("게시판 구분아이디가 잘못 전달되었습니다")
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)
def modify(self, id="json"): # 필수 입력 인자 client_request_key = request.params.keys() # 태이크 고유 번호 if "takeNo" not in client_request_key: response.status_int = 403 return "Required variable Not Exists - takeNo" takeNo = request.params["takeNo"] # 기존에 존재한 Take 정보 가져오기 take_info = ( Session.query( "takeName", "takeStatus", "takeType", "takeContent", "takeWorktime", "takeIndication", "takePreview" ) .from_statement( """ select Take.Name as takeName, StatCode as takeStatus, TypeCode as takeType, Content as takeContent, attr1.`Value` AS takeWorktime, attr2.`Value` AS takeIndication, Preview as takePreview from Take LEFT OUTER JOIN `Take_Attr` AS attr1 ON attr1.`ParentIDX` = `Take`.`IDX` AND attr1.`MAttrID` = 'Worktime' LEFT OUTER JOIN `Take_Attr` AS attr2 ON attr2.`ParentIDX` = `Take`.`IDX` AND attr2.`MAttrID` = 'Indication' where IDX = :takeNo """ ) .params(takeNo=takeNo) .first() ) # 태이크명 takeName = None if "takeName" in client_request_key: takeName = request.params["takeName"] # 태이크 미리보기(MOV, Directory) takePreview = None if "takePreview" in client_request_key: takePreview = request.params["takePreview"] # 태이크 상태 takeStatus = None if "takeStatus" in client_request_key: takeStatus = request.params["takeStatus"] exiStatus = ExistsCode("Take_Stat", takeStatus) if not exiStatus: response.status_int = 403 return "An invalid status code." # 태이크 타입 takeType = None if "takeType" in client_request_key: takeType = request.params["takeType"] exiType = ExistsCode("Take_Type", takeType) if not exiType: response.status_int = 403 return "An invalid status code." # 일한 시간 takeWorktime = None if "takeWorktime" in client_request_key: takeWorktime = request.params["takeWorktime"] # 지시사항 takeIndication = "" if "takeIndication" in client_request_key: takeIndication = request.params["takeIndication"] # 태이크 상세내용 takeContent = "" if "takeContent" in client_request_key: takeContent = request.params["takeContent"] take_sql = "update Take set " take_sql_values = [] if None != takeName and len(takeName) > 0: take_sql_values.append("takeName = '" + takeName + "'") if None != takePreview and len(takePreview) > 0: take_sql_values.append("takePreview = '" + takePreview + "'") if None != takeStatus and len(takeStatus) > 0: take_sql_values.append("takeStatus = '" + takeStatus + "'") if None != takeType and len(takeType) > 0: take_sql_values.append("takeType = '" + takeType + "'") if None != takeContent and len(takeContent) > 0: take_sql_values.append("takeContent = '" + takeContent + "'") modifyDate = time.strftime("%Y-%m-%d %H:%M:%S") take_sql_values.append("ModifyDate = '" + modifyDate + "'") take_sql += ", ".join(take_sql_values) take_sql += " where IDX = %d" % int(takeNo) Session.execute(take_sql) if None != takeWorktime and len(takeWorktime) > 0: take_attr_sql = ( "update Take_Attr set Value='" + takeWorktime + "' where ParentIDX=%(ParentIDX)d and MAttrIDX=24" % dict(ParentIDX=takeNo) ) Session.execute(take_attr_sql) if None != takeIndication and len(takeIndication) > 0: take_attr_sql = ( "update Take_Attr set Value='" + takeIndication + "' where ParentIDX=%(ParentIDX)d and MAttrIDX=25" % dict(ParentIDX=takeNo) ) Session.execute(take_attr_sql) Session.commit() if "json" == id: return json.dumps({"takeNo": takeNo, "takeModifyDate": modifyDate}) else: to_xml = "<records><takeNo>" + takeNo to_xml += "</takeNo><takeModifyDate>" to_xml += modifyDate + "</takeModifyDate></records>" return to_xml
def write(self, id="json"): # 필수 입력 인자 client_request_key = request.params.keys() # 태스크 고유 번호 if "taskNo" not in client_request_key: response.status_int = 403 return "Required variable Not Exists - taskNo" taskNo = request.params["taskNo"] # 태이크명 takeName = None if "takeName" not in client_request_key: response.status_int = 403 return "Required variable Not Exists - takeName" takeName = request.params["takeName"] # 태이크 미리보기(MOV, Directory) takePreview = None if "takePreview" not in client_request_key: response.status_int = 403 return "Required variable Not Exists - takePreview" takePreview = request.params["takePreview"] # 선택인자 검사 # 태이크 상태 takeStatus = "RDY" if "takeStatus" in client_request_key: takeStatus = request.params["takeStatus"] exiStatus = ExistsCode("Take_Stat", takeStatus) if not exiStatus: response.status_int = 403 return "An invalid status code." # 태이크 타입 takeType = "MDL" if "takeType" in client_request_key: takeType = request.params["takeType"] exiType = ExistsCode("Take_Type", takeType) if not exiType: response.status_int = 403 return "An invalid status code." # 일한 시간 takeWorktime = "0" if "takeWorktime" in client_request_key: takeWorktime = request.params["takeWorktime"] # 지시사항 takeIndication = "" if "takeIndication" in client_request_key: takeIndication = request.params["takeIndication"] # 태이크 상세내용 takeContent = "" if "takeContent" in client_request_key: takeContent = request.params["takeContent"] # Task의 정보를 가져온다. task_info = ( Session.query("IDX", "Parent1", "Parent2", "Parent3", "Confirmer") .from_statement( " select IDX, Parent1, Parent2, Parent3, Parent4, Confirmer from " " Task where IDX = :taskNo" ) .params(taskNo=taskNo) .first() ) import uuid # Take 테이블의 최대 IDX 값을 가져온다 take_max_idx = Session.query("max_no").from_statement("select max(IDX) as max_no from Take").first() take_sql = ( "insert into Take (IDX, UUID, Name, Code, StatCode, " " TypeCode, Parent1, Parent2, Parent3, Parent4, Element, `Version`, " " Content, Preview, Confirmer, CreateDate, CreateBy, CreateBy2, " " ModifyDate, ModifyBy, ModifyBy2, SortNumber, IsPublish, IsStable, " " IsApproved) values (%(IDX)d, '%(UUID)s', '%(Name)s', '%(Name)s', '%(StatCode)s', " " '%(TypeCode)s', %(Parent1)d, %(Parent2)d, %(Parent3)d, %(Parent4)d, '%(Element)s', %(Version)d, " " '%(Content)s', '%(Preview)s', '%(Confirmer)s', timestamp('%(CreateDate)s'), '%(CreateBy)s', '%(CreateBy2)s', " " timestamp('%(ModifyDate)s'), '%(ModifyBy)s', '%(ModifyBy2)s', %(SortNumber)d, %(IsPublish)d, %(IsStable)d, %(IsApproved)d)" ) CreateTime = time.strftime("%Y-%m-%d %H:%M:%S") take_sql = take_sql % dict( IDX=int(take_max_idx.max_no + 1), UUID=unicode(uuid.uuid1()), Name=unicode(takeName), StatCode=takeStatus, TypeCode=takeType, Parent1=task_info.Parent1, Parent2=task_info.Parent2, Parent3=task_info.Parent3, Parent4=task_info.IDX, Element="all", # 임시고정 Version=1, # 임시고정 Content=takeContent, Preview=takePreview, Confirmer=unicode(task_info.Confirmer), CreateDate=CreateTime, CreateBy="broker", CreateBy2="시스템".decode("utf-8"), ModifyDate=CreateTime, ModifyBy="broker", ModifyBy2="시스템".decode("utf-8"), SortNumber=500, IsPublish=0, IsStable=0, IsApproved=0, ) Session.execute(take_sql) Session.commit() # Take_Attr Dict take_attr_value_dict = { 0: {"MAttrIDX": 24, "MAttrID": "Worktime", "Name": "작업시간".decode("utf-8"), "Value": takeWorktime}, 1: {"MAttrIDX": 25, "MAttrID": "Indication", "Name": "지시사항".decode("utf-8"), "Value": takeIndication}, } # Take_Attr 테이블의 최대 IDX 값을 가져온다 for i in range(2): take_attr_max_idx = ( Session.query("max_no").from_statement("select max(AttrIDX) as max_no from Take_Attr").first() ) if None == take_attr_max_idx.max_no: take_attr_max_idx = 1 else: take_attr_max_idx = take_attr_max_idx.max_no + 1 take_attr_sql = ( "insert into Take_Attr (AttrIDX, ParentIDX, MAttrIDX, MAttrID, Category, Name, Value) values " ) take_attr_sql += ( " (%(AttrIDX)d, %(ParentIDX)d, %(MAttrIDX)d, '%(MAttrID)s', '%(Category)s', '%(Name)s', '%(Value)s')" ) take_extend_attr = take_attr_value_dict[i] take_attr_sql = take_attr_sql % dict( AttrIDX=take_attr_max_idx, ParentIDX=int(take_max_idx.max_no + 1), MAttrIDX=take_extend_attr["MAttrIDX"], MAttrID=take_extend_attr["MAttrID"], Category="Take", Name=take_extend_attr["Name"], Value=take_extend_attr["Value"], ) Session.execute(take_attr_sql) Session.commit() if "json" == id: return json.dumps({"takeNo": int(take_max_idx.max_no + 1), "takeCreateDate": CreateTime}) else: to_xml = "<records><takeNo>" + int(take_max_idx.max_no + 1) to_xml += "</takeNo><takeCreateDate>" to_xml += CreateTime + "</takeCreateDate></records>" return to_xml