def delete(self, document_id): """删除文档: 包括删除文档记录和更新memer中的文档id """ response_document = couch_db.get(r'/jsmm/%(document_id)s' % {"document_id": document_id}) document = json.loads(response_document.body.decode('utf-8')) response_member = couch_db.get(r'/jsmm/%(member_id)s' % {"member_id": document["memberId"]}) member = json.loads(response_member.body.decode('utf-8')) if document['docType'] == 'researchReport': member['researchReport'].remove(document['_id']) elif document['docType'] == 'unitedTheory': member['unitedTheory'].remove(document['_id']) elif document['docType'] == 'politicsInfo': member['politicsInfo'].remove(document['_id']) elif document['docType'] == 'propaganda': member['propaganda'].remove(document['_id']) # 删除Document记录 couch_db.delete(r'/jsmm/%(document_id)s?rev=%(document_rev)s' % { 'document_id': document_id, 'document_rev': document['_rev'] }) # 更新member中的document的id couch_db.put(r'/jsmm/%(id)s' % {"id": member["_id"]}, member) # del_result = json.loads(response_del_document.body.decode('utf-8')) self.write({'success': 'true'})
def get(self, document_id, attachment_name): """获取附件内容 返回: { "success": <'true'/'false'>, # 仅当statusCode为200时为'true' "statusCode": <status_code>, # 200, 304, 401, 404 "contentLength": <content_length>, "contentType": <content_type>, "body": <response.body> # 仅当statusCode为200时提供 } """ response = couch_db.get(r'/jsmm/%(document_id)s/%(attachment_name)s' % { 'document_id': document_id, 'attachment_name': attachment_name }) (status_code, content_length, content_type) = self._parse_header(response) output = { 'statusCode': status_code, 'contentLength': content_length, 'contentType': content_type } if status_code.startswith('200'): self.set_header('Content-Type', content_type) self.set_header( 'Content-Disposition', 'attachment; filename=' + urllib.parse.quote(attachment_name, "utf-8")) self.write(response.body) else: self.set_header('Content-Type', 'application/json') output.update({'success': 'false'}) self.write(json.dumps(output))
def put(self, member_id): """ 修改_id为member_id的member对象。 """ # 获得前台对象# member_updated = json.loads(self.request.body.decode('utf-8')) # 根据memeber_id,查询数据库中的memeber对象 response = couch_db.get(r'/jsmm/%(id)s' % {'id': member_id}) member = json.loads(response.body.decode('utf-8')) # 将前台数据赋予后台对象,然后将后台对象保存。 member.update(member_updated) # 将document中的member数据更新 query = {'keys': [member_id]} documents_response = couch_db.post( r'/jsmm/_design/documents/_view/by_memberid', query) documents = json.loads(documents_response.body.decode('utf-8')) for doc in documents['rows']: doc['value']['name'] = member['name'] doc['value']['branch'] = member['branch'] doc['value']['organ'] = member['organ'] couch_db.put(r'/jsmm/%(id)s' % {'id': doc['value']['_id']}, doc['value']) couch_db.put(r'/jsmm/%(id)s' % {'id': member_id}, member) response = {'success': 'true'} self.write(response)
def get(self): """修改_id为member_id的member对象。 """ response = couch_db.get(r'/jsmm/_design/documents/_view/by-memberid') doucment_list = json.loads(response.body.decode('utf-8')) documents = [] for row in doucment_list['rows']: documents.append(row['value']) self.set_header('Content-Type', 'application/json') self.write(json.dumps(documents))
def post(self, member_id, doc_type): response_member = couch_db.get(r'/jsmm/%(member_id)s' % {"member_id": member_id}) member_in_db = json.loads(response_member.body.decode('utf-8')) docs = self.request.files['docs'] doc_name = docs[0]['filename'] document_info = { '_id': make_uuid(), 'memberId': member_in_db['_id'], 'name': member_in_db['name'], 'type': 'document', 'branch': member_in_db['branch'], 'organ': member_in_db['organ'], 'fileUploadTime': time.strftime("%Y-%m-%d", time.localtime()), 'docType': doc_type, 'fileName': doc_name } document_response = couch_db.post(r'/jsmm/', document_info) result = json.loads(document_response.body.decode('utf-8')) document_id = result["id"] if doc_type == 'researchReport': if 'researchReport' not in member_in_db: member_in_db['researchReport'] = [] member_in_db['researchReport'].append(document_id) elif doc_type == 'unitedTheory': if 'unitedTheory' not in member_in_db: member_in_db['unitedTheory'] = [] member_in_db['unitedTheory'].append(document_id) elif doc_type == 'politicsInfo': if 'politicsInfo' not in member_in_db: member_in_db['politicsInfo'] = [] member_in_db['politicsInfo'].append(document_id) elif doc_type == 'propaganda': if 'propaganda' not in member_in_db: member_in_db['propaganda'] = [] member_in_db['propaganda'].append(document_id) couch_db.put(r'/jsmm/%(id)s' % {"id": member_id}, member_in_db) return self.put(document_id, doc_name)
def docCallBack(file): loadDb = couch_db.get(r'/jsmm/%(id)s' % {'id': file['member_id']}) memberInDb = json.loads(loadDb.body.decode('utf-8')) documentInfo = { '_id': make_uuid(), 'memberId': memberInDb['_id'], 'name': memberInDb['name'], 'type': 'document', 'branch': memberInDb['branch'], 'organ': memberInDb['organ'], 'fileUploadTime': newTime(), 'fileName': file['filename'], 'file_url': file['path'], 'fileType': file['filename'].split('.')[-1] } # if file['doc_type'] == 'researchReport': # documentInfo['docType'] = 'researchReport' # elif file['doc_type'] == 'departmentInfo': # documentInfo['docType'] = 'departmentInfo' # elif file['doc_type'] == 'speechesText': # documentInfo['docType'] = 'speechesText' # elif file['doc_type'] == 'speechesText': # documentInfo['docType'] = 'speechesText' if file['doc_type'] == 'researchReport': if ('researchReport' not in memberInDb): memberInDb['researchReport'] = [] memberInDb['researchReport'].append(documentInfo['_id']) elif file['doc_type'] == 'unitedTheory': if ('unitedTheory' not in memberInDb): memberInDb['unitedTheory'] = [] memberInDb['unitedTheory'].append(documentInfo['_id']) elif file['doc_type'] == 'politicsInfo': if ('politicsInfo' not in memberInDb): memberInDb['politicsInfo'] = [] memberInDb['politicsInfo'].append(documentInfo['_id']) elif file['doc_type'] == 'propaganda': if ('propaganda' not in memberInDb): memberInDb['propaganda'] = [] memberInDb['propaganda'].append(documentInfo['_id']) documentResponse = couch_db.post(r'/jsmm/', documentInfo) memberResponse = couch_db.put(r'/jsmm/%(id)s' % {"id": file['member_id']}, memberInDb)
def get(self, member_id): """ 获取_id为member_id的member对象。 """ query = {'keys': [member_id]} documents_response = couch_db.post( r'/jsmm/_design/documents/_view/by_memberid', query) documents = json.loads(documents_response.body.decode('utf-8')) member_response = couch_db.get(r'/jsmm/%(id)s' % {'id': member_id}) member = json.loads(member_response.body.decode('utf-8')) member['researchReport'] = [doc['value'] for doc in documents[ 'rows'] if doc['value']['docType'] == 'researchReport'] member['unitedTheory'] = [doc['value'] for doc in documents[ 'rows'] if doc['value']['docType'] == 'unitedTheory'] member['politicsInfo'] = [doc['value'] for doc in documents[ 'rows'] if doc['value']['docType'] == 'politicsInfo'] member['propaganda'] = [doc['value'] for doc in documents[ 'rows'] if doc['value']['docType'] == 'propaganda'] self.write(member)
def imageCallBack(file): loadDb = couch_db.get(r'/jsmm/%(id)s' % {'id': str(file['member_id'], encoding="utf-8")}) memberInDb = json.loads(loadDb.body.decode('utf-8')) memberInDb['picture'] = '/image/'+file['filename'] couch_db.put(r'/jsmm/%(id)s' % {"id": str(file['member_id'], encoding="utf-8")}, memberInDb)
def get(self, member_id): current_row = 18 response = couch_db.get(r'/jsmm/%(id)s' % {"id": member_id}) member = json.loads(response.body.decode('utf-8')) pattern = xlwt.Pattern() pattern.pattern = xlwt.Pattern.SOLID_PATTERN pattern.pattern_fore_colour = 22 style = xlwt.XFStyle() style.pattern = pattern style.font.height = 240 style.font.name = '宋体' memberInfoStyle = xlwt.XFStyle() memberInfoStyle.font.name = '宋体' memberInfoStyle.font.height = 240 wb = xlwt.Workbook() ws = wb.add_sheet(member['name'] + '的信息', cell_overwrite_ok=True) for c in range(0, 10): ws.col(c).width = 4000 ws.write_merge(0, 0, 0, 9, u'基本信息', style) ws.write(1, 0, u'姓名', memberInfoStyle) ws.write(1, 2, u'性别', memberInfoStyle) ws.write(1, 4, u'籍贯', memberInfoStyle) ws.write(2, 0, u'民族', memberInfoStyle) ws.write(2, 2, u'出生地', memberInfoStyle) ws.write(2, 4, u'出生年月日', memberInfoStyle) ws.write(3, 0, u'外文姓名', memberInfoStyle) ws.write(3, 3, u'曾用名', memberInfoStyle) ws.write(4, 0, u'健康状态', memberInfoStyle) ws.write(4, 3, u'婚姻状态', memberInfoStyle) ws.write(5, 0, u'所属支社', memberInfoStyle) ws.write(5, 3, u'所属基层组织', memberInfoStyle) ws.write(6, 0, u'入社时间', memberInfoStyle) ws.write(6, 3, u'党派交叉', memberInfoStyle) ws.write(7, 0, u'单位名称', memberInfoStyle) ws.write(7, 3, u'工作部门', memberInfoStyle) ws.write(8, 0, u'职务', memberInfoStyle) ws.write(8, 3, u'职称', memberInfoStyle) ws.write(9, 0, u'学术职务', memberInfoStyle) ws.write(9, 3, u'参加工作时间', memberInfoStyle) ws.write_merge(9, 9, 6, 7, u'是否办理退休', memberInfoStyle) ws.write(10, 0, u'公民身份证号', memberInfoStyle) ws.write(10, 3, u'有效证件类别', memberInfoStyle) ws.write_merge(10, 10, 6, 7, u'证件号码', memberInfoStyle) ws.write(11, 0, u'家庭地址', memberInfoStyle) ws.write(11, 4, u'邮编', memberInfoStyle) ws.write(12, 0, u'单位地址', memberInfoStyle) ws.write(12, 4, u'邮编', memberInfoStyle) ws.write(13, 0, u'通信地址', memberInfoStyle) ws.write(13, 4, u'邮编', memberInfoStyle) ws.write(14, 0, u'手机', memberInfoStyle) ws.write(14, 4, u'家庭电话', memberInfoStyle) ws.write(15, 0, u'电子信箱', memberInfoStyle) ws.write(15, 4, u'单位电话', memberInfoStyle) ws.write(16, 0, u'爱好', memberInfoStyle) ws.write(17, 0, u'专长', memberInfoStyle) ws.write_merge(1, 7, 8, 9, '头像', memberInfoStyle) ws.write(1, 1, member['name'], memberInfoStyle) ws.write(1, 3, member['gender'], memberInfoStyle) ws.write_merge(1, 1, 5, 7, member['nativePlace'], memberInfoStyle) ws.write(2, 1, member['nation'], memberInfoStyle) ws.write(2, 3, member['birthPlace'], memberInfoStyle) ws.write_merge(2, 2, 5, 7, member['birthday'], memberInfoStyle) ws.write_merge(3, 3, 1, 2, member['foreignName'], memberInfoStyle) ws.write_merge(3, 3, 4, 7, member['usedName'], memberInfoStyle) ws.write_merge(4, 4, 1, 2, member['health'], memberInfoStyle) ws.write_merge(4, 4, 4, 7, member['marriage'], memberInfoStyle) ws.write_merge(5, 5, 1, 2, member['branch'], memberInfoStyle) ws.write_merge(5, 5, 4, 7, member['organ'], memberInfoStyle) ws.write_merge(6, 6, 1, 2, member['branchTime'], memberInfoStyle) ws.write_merge(6, 6, 4, 7, member['partyCross'], memberInfoStyle) ws.write_merge(7, 7, 1, 2, member['companyName'], memberInfoStyle) ws.write_merge(7, 7, 4, 7, member['department'], memberInfoStyle) ws.write_merge(8, 8, 1, 2, member['duty'], memberInfoStyle) ws.write_merge(8, 8, 4, 9, member['jobTitle'], memberInfoStyle) ws.write_merge(9, 9, 1, 2, member['academic'], memberInfoStyle) ws.write_merge(9, 9, 4, 5, member['jobTime'], memberInfoStyle) ws.write_merge(9, 9, 8, 9, member['retire'], memberInfoStyle) ws.write_merge(10, 10, 1, 2, member['idCard'], memberInfoStyle) ws.write_merge(10, 10, 4, 5, member['idType'], memberInfoStyle) ws.write_merge(10, 10, 8, 9, member['idNo'], memberInfoStyle) ws.write_merge(11, 11, 1, 3, member['homeAddress'], memberInfoStyle) ws.write_merge(11, 11, 5, 9, member['homePost'], memberInfoStyle) ws.write_merge(12, 12, 1, 3, member['companyAddress'], memberInfoStyle) ws.write_merge(12, 12, 5, 9, member['companyPost'], memberInfoStyle) ws.write_merge(13, 13, 1, 3, member['commAddress'], memberInfoStyle) ws.write_merge(13, 13, 5, 9, member['commPost'], memberInfoStyle) ws.write_merge(14, 14, 1, 3, member['mobile'], memberInfoStyle) ws.write_merge(14, 14, 5, 9, member['homeTel'], memberInfoStyle) ws.write_merge(15, 15, 1, 3, member['email'], memberInfoStyle) ws.write_merge(15, 15, 5, 9, member['companyTel'], memberInfoStyle) ws.write_merge(16, 16, 1, 9, member['hobby'], memberInfoStyle) ws.write_merge(17, 17, 1, 9, member['speciality'], memberInfoStyle) for obj in dict(member): for case in switch(obj): if case('specializedskill'): if len(member['specializedskill']) > 0: ws.write_merge(current_row, current_row, 0, 9, u'') ws.write_merge(current_row + 1, current_row + 1, 0, 9, u'业务专长', style) ws.write_merge(current_row + 2, current_row + 2, 0, 1, u'专业分类', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 2, 4, u'专业名称', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 5, 9, u'专业详细名称', memberInfoStyle) for i in range(0, len(member['specializedskill'])): obj = member['specializedskill'][i] ws.write_merge(current_row + 3 + i, current_row + 3 + i, 0, 1, obj['specializedType'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 2, 4, obj['specializedName'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 5, 9, obj['specializedDetailName'], memberInfoStyle) obj_row = 3 + len(member['specializedskill']) current_row += obj_row break if case('educationDegree'): if len(member['educationDegree']) > 0: ws.write_merge(current_row, current_row, 0, 9, u'') ws.write_merge(current_row + 1, current_row + 1, 0, 9, u'学历信息', style) ws.write_merge(current_row + 2, current_row + 2, 0, 1, u'学校名称', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 2, 3, u'起止时间', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 4, 5, u'所学专业', memberInfoStyle) ws.write(current_row + 2, 6, u'取得学历', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 7, 8, u'所获学位', memberInfoStyle) ws.write(current_row + 2, 9, u'教育类别', memberInfoStyle) for i in range(0, len(member['educationDegree'])): obj = member['educationDegree'][i] ws.write_merge(current_row + 3 + i, current_row + 3 + i, 0, 1, obj['eduSchoolName'], memberInfoStyle) ws.write_merge( current_row + 3 + i, current_row + 3 + i, 2, 3, obj['eduStartingDate'] + ' - ' + obj['eduGraduateDate'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 4, 5, obj['eduMajor'], memberInfoStyle) ws.write(current_row + 3 + i, 6, obj['eduEducation'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 7, 8, obj['eduDegree'], memberInfoStyle) ws.write(current_row + 3 + i, 9, obj['eduEducationType'], memberInfoStyle) obj_row = 3 + len(member['educationDegree']) current_row += obj_row break if case('familyRelations'): if len(member['familyRelations']) > 0: ws.write_merge(current_row, current_row, 0, 9, u'') ws.write_merge(current_row + 1, current_row + 1, 0, 9, u'社会关系', style) ws.write(current_row + 2, 0, u'姓名', memberInfoStyle) ws.write(current_row + 2, 1, u'与本人关系', memberInfoStyle) ws.write(current_row + 2, 2, u'性别', memberInfoStyle) ws.write(current_row + 2, 3, u'出生年月', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 4, 5, u'工作单位', memberInfoStyle) ws.write(current_row + 2, 6, u'职务', memberInfoStyle) ws.write(current_row + 2, 7, u'国籍', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 8, 9, u'政治面貌', memberInfoStyle) for i in range(0, len(member['familyRelations'])): obj = member['familyRelations'][i] ws.write(current_row + 3 + i, 0, obj['familyName'], memberInfoStyle) ws.write(current_row + 3 + i, 1, obj['familyRelation'], memberInfoStyle) ws.write(current_row + 3 + i, 2, obj['familyGender'], memberInfoStyle) ws.write(current_row + 3 + i, 3, obj['familyBirthDay'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 4, 5, obj['familyCompany'], memberInfoStyle) ws.write(current_row + 3 + i, 6, obj['familyJob'], memberInfoStyle) ws.write(current_row + 3 + i, 7, obj['familyNationality'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 8, 9, obj['familyPolitical'], memberInfoStyle) obj_row = 3 + len(member['familyRelations']) current_row += obj_row break if case('jobResumes'): if len(member['jobResumes']) > 0: ws.write_merge(current_row, current_row, 0, 9, u'') ws.write_merge(current_row + 1, current_row + 1, 0, 9, u'工作履历', style) ws.write_merge(current_row + 2, current_row + 2, 0, 1, u'单位名称', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 2, 3, u'工作部门', memberInfoStyle) ws.write(current_row + 2, 4, u'职务', memberInfoStyle) ws.write(current_row + 2, 5, u'职称', memberInfoStyle) ws.write(current_row + 2, 6, u'学术职务', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 7, 8, u'起止时间', memberInfoStyle) ws.write(current_row + 2, 9, u'证明人', memberInfoStyle) for i in range(0, len(member['jobResumes'])): obj = member['jobResumes'][i] ws.write_merge(current_row + 3 + i, current_row + 3 + i, 0, 1, obj['jobCompanyName'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 2, 3, obj['jobDep'], memberInfoStyle) ws.write(current_row + 3 + i, 4, obj['jobDuties'], memberInfoStyle) ws.write(current_row + 3 + i, 5, obj['jobTitle'], memberInfoStyle) ws.write(current_row + 3 + i, 6, obj['jobAcademic'], memberInfoStyle) ws.write_merge( current_row + 3 + i, current_row + 3 + i, 7, 8, obj['jobStartTime'] + ' - ' + obj['jobEndTime'], memberInfoStyle) ws.write(current_row + 3 + i, 9, obj['jobReterence'], memberInfoStyle) obj_row = 3 + len(member['jobResumes']) current_row += obj_row break if case('award'): if len(member['award']) > 0: ws.write_merge(current_row, current_row, 0, 9, u'') ws.write_merge(current_row + 1, current_row + 1, 0, 9, u'获奖情况', style) ws.write_merge(current_row + 2, current_row + 2, 0, 2, u'获奖项目名称', memberInfoStyle) ws.write(current_row + 2, 3, u'获奖时间', memberInfoStyle) ws.write(current_row + 2, 4, u'获奖级别', memberInfoStyle) ws.write(current_row + 2, 5, u'项目中角色', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 6, 7, u'授予单位', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 8, 9, u'备注', memberInfoStyle) for i in range(0, len(member['award'])): obj = member['award'][i] ws.write_merge(current_row + 3 + i, current_row + 3 + i, 0, 2, obj['awardProjectName'], memberInfoStyle) ws.write(current_row + 3 + i, 3, obj['awardDate'], memberInfoStyle) ws.write(current_row + 3 + i, 4, obj['awardNameAndLevel'], memberInfoStyle) ws.write(current_row + 3 + i, 5, obj['awardRoleInProject'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 6, 7, obj['awardCompany'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 8, 9, obj['awardMemo'], memberInfoStyle) obj_row = 3 + len(member['award']) current_row += obj_row break if case('patents'): if len(member['patents']) > 0: ws.write_merge(current_row, current_row, 0, 9, u'') ws.write_merge(current_row + 1, current_row + 1, 0, 9, u'专利情况', style) ws.write_merge(current_row + 2, current_row + 2, 0, 3, u'获专利名称', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 4, 5, u'获专利时间', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 6, 9, u'专利号', memberInfoStyle) for i in range(0, len(member['patents'])): obj = member['patents'][i] ws.write_merge(current_row + 3 + i, current_row + 3 + i, 0, 3, obj['patentName'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 4, 5, obj['patentDate'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 6, 9, obj['patenNo'], memberInfoStyle) obj_row = 3 + len(member['patents']) current_row += obj_row break if case('paper'): if len(member['paper']) > 0: ws.write_merge(current_row, current_row, 0, 9, u'') ws.write_merge(current_row + 1, current_row + 1, 0, 9, u'主要论文著作', style) ws.write(current_row + 2, 0, u'论文/著作', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 1, 3, u'作品名称', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 4, 6, u'刊物/出版社', memberInfoStyle) ws.write(current_row + 2, 7, u'第几作者', memberInfoStyle) ws.write(current_row + 2, 8, u'发行时间', memberInfoStyle) ws.write(current_row + 2, 9, u'角色说明', memberInfoStyle) for i in range(0, len(member['paper'])): obj = member['paper'][i] ws.write(current_row + 3 + i, 0, obj['paperPublications'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 1, 3, obj['paperName'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 4, 6, obj['paperPress'], memberInfoStyle) ws.write(current_row + 3 + i, 7, obj['paperAuthorSort'], memberInfoStyle) ws.write(current_row + 3 + i, 8, obj['paperPressDate'], memberInfoStyle) ws.write(current_row + 3 + i, 9, obj['paperRoleDetail'], memberInfoStyle) obj_row = 3 + len(member['paper']) current_row += obj_row break if case('professionalSkill'): if len(member['professionalSkill']) > 0: ws.write_merge(current_row, current_row, 0, 9, u'') ws.write_merge(current_row + 1, current_row + 1, 0, 9, u'专业技术工作', style) ws.write_merge(current_row + 2, current_row + 2, 0, 3, u'项目名称', memberInfoStyle) ws.write(current_row + 2, 4, u'项目类别', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 5, 6, u'项目下达单位', memberInfoStyle) ws.write(current_row + 2, 7, u'项目中所任角色', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 8, 9, u'起止时间', memberInfoStyle) for i in range(0, len(member['professionalSkill'])): obj = member['professionalSkill'][i] ws.write_merge(current_row + 3 + i, current_row + 3 + i, 0, 3, obj['proProjectName'], memberInfoStyle) ws.write(current_row + 3 + i, 4, obj['proProjectType'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 5, 6, obj['proProjectCompany'], memberInfoStyle) ws.write(current_row + 3 + i, 7, obj['proRolesInProject'], memberInfoStyle) ws.write_merge( current_row + 3 + i, current_row + 3 + i, 8, 9, obj['proStartDate'] + ' - ' + obj['porEndDate'], memberInfoStyle) obj_row = 3 + len(member['professionalSkill']) current_row += obj_row break if case('achievements'): if len(member['achievements']) > 0: ws.write_merge(current_row, current_row, 0, 9, u'') ws.write_merge(current_row + 1, current_row + 1, 0, 9, u'专业技术成果', style) ws.write_merge(current_row + 2, current_row + 2, 0, 2, u'成果名称', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 3, 5, u'成果水平', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 6, 7, u'鉴定单位', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 8, 9, u'备注', memberInfoStyle) for i in range(0, len(member['achievements'])): obj = member['achievements'][i] ws.write_merge(current_row + 3 + i, current_row + 3 + i, 0, 2, obj['achievementsName'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 3, 5, obj['achievementsLevel'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 6, 7, obj['identificationUnit'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 8, 9, obj['achievementsRemark'], memberInfoStyle) obj_row = 3 + len(member['achievements']) current_row += obj_row break if case('agencybroker'): if len(member['agencybroker']) > 0: ws.write_merge(current_row, current_row, 0, 9, u'') ws.write_merge(current_row + 1, current_row + 1, 0, 9, u'入社介绍人', style) ws.write_merge(current_row + 2, current_row + 2, 0, 1, u'姓名', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 2, 4, u'单位', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 5, 6, u'职务', memberInfoStyle) ws.write_merge(current_row + 2, current_row + 2, 7, 9, u'与本人关系', memberInfoStyle) for i in range(0, len(member['agencybroker'])): obj = member['agencybroker'][i] ws.write_merge(current_row + 3 + i, current_row + 3 + i, 0, 1, obj['agencyName'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 2, 4, obj['agencyCompany'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 5, 6, obj['agencyJob'], memberInfoStyle) ws.write_merge(current_row + 3 + i, current_row + 3 + i, 7, 9, obj['agencyRelationShip'], memberInfoStyle) obj_row = 3 + len(member['agencybroker']) current_row += obj_row break if self.request.arguments: current_row = customizeObj(obj, current_row, ws, style, memberInfoStyle, member) tall_style = xlwt.easyxf('font:height 360;') for i in range(0, current_row): first_row = ws.row(i) first_row.set_style(tall_style) sio = BytesIO() wb.save(sio) self.set_header('Content-Type', 'application/vnd.ms-excel') self.set_header( 'Content-Disposition', 'attachment; filename=' + urllib.parse.quote(member['name'] + '的信息.xls', "utf-8")) self.write(sio.getvalue()) self.finish()
def get(self, document_id): """获取文档信息 """ self.write( couch_db.get(r'/jsmm/%(document_id)s' % {'document_id': document_id}))
def post(self): """ 修改_id为member_id的member对象。 """ params = json.loads(self.request.body.decode('utf-8')) page_number = params['page'] page_size = params['rows'] params_str = "" if "documentInfo" in params: # name = params["documentInfo"]["name"] # fileName = params["documentInfo"]["fileName"] key_world = params["documentInfo"]["keyWord"].replace(' ', '') key_word_attachment = params["documentInfo"]["keyWordAttachment"] start_date = params["documentInfo"]["startDate"] end_date = params["documentInfo"]["endDate"] doc_type = params["documentInfo"]["docType"] if key_word_attachment != '': params_str += key_word_attachment else: pass # if name != '' and params_str != '': # params_str += ' AND name:"' + name + '"' # elif name != '' and params_str == '': # params_str += 'name:"' + name + '"' # else: # pass # # if fileName != '' and params_str != '': # params_str += ' AND fileName:"' + fileName + '"' # elif fileName != '' and params_str == '': # params_str += 'fileName:"' + fileName + '"' # else: # pass if key_world != '' and params_str != '': params_str += ' AND (fileName:' + key_world + ' OR name:' + key_world + ')' elif key_world != '' and params_str == '': params_str += '(fileName:' + key_world + ' OR name:' + key_world + ')' else: pass if start_date != '' and end_date != '' and params_str != '': params_str += ' AND fileUploadTime<date>:[' + start_date + ' TO ' + end_date + ']' elif start_date != '' and end_date != '' and params_str == '': params_str += 'fileUploadTime<date>:[' + start_date + ' TO ' + end_date + ']' else: pass if doc_type != '' and params_str != '': params_str += ' AND docType:"' + doc_type + '"' elif doc_type != '' and params_str == '': params_str += 'docType:"' + doc_type + '"' else: pass if "branch" in params: branch = params["branch"] if branch != '' and params_str != '' and branch != '北京市' and branch != '朝阳区': params_str += ' AND branch:"' + branch + '"' elif branch != '' and params_str == '' and branch != '北京市' and branch != '朝阳区': params_str += 'branch:"' + branch + '"' else: pass print('params_str = ' + params_str) if params_str != '': response = couchLucene_db.get( r'/_fti/local/jsmm/_design/documents/by_doc_info?q=%(params_str)s&limit=%(limit)s&skip=%(skip)s' % { "params_str": urllib.parse.quote(params_str, "utf-8"), 'limit': page_size, 'skip': (page_number - 1) * page_size }) else: response = couch_db.get( '/jsmm/_design/documents/_view/by_memberid?limit=%(page_size)s&skip=%(page_number)s' % { 'page_size': page_size, 'page_number': (page_number - 1) * page_size }) documents_result = {} if response.code == 200: documents = [] document_list = json.loads(response.body.decode('utf-8')) print(document_list) if params_str != '': for row in document_list['rows']: row['fields']['_id'] = row['id'] documents.append(row['fields']) else: for row in document_list['rows']: documents.append(row['value']) documents_result['total'] = document_list['total_rows'] documents_result['rows'] = documents else: documents_result['total'] = 0 documents_result['rows'] = [] documents_result['page_size'] = page_size documents_result['page_number'] = page_number self.set_header('Content-Type', 'application/json') self.write(json.dumps(documents_result))