Example #1
0
 def save_member(self):
     """
     保存社员信息
     :return:
     """
     query_name = self._member["name"]
     query_id_card = self._member["idCard"]
     obj = {
         "selector": {
             "name": {
                 "$eq": query_name
             },
             "idCard": {
                 "$eq": query_id_card
             }
         },
         "fields": ["_id", "name", "idCard"]
     }
     request = couch_db.post(r'/jsmm/_find/', obj)
     member = json.loads(request.body.decode('utf-8'))
     if len(member["docs"]):
         memberInfo = member["docs"]
         msg = {
             "success": False,
             "name": memberInfo[0]["name"],
             "idCard": memberInfo[0]["idCard"]
         }
         return msg
     else:
         self._member["retireTime"] = get_retire_time(
             self._member["birthday"], self._member["gender"])
         self._member["lost"] = "否"
         self._member["stratum"] = "否"
         couch_db.post(r'/jsmm/', self._member)
         return {"success": True}
Example #2
0
    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)
Example #3
0
def customizeObj(obj, current_row, ws, style, memberInfoStyle, member):
    if len(obj) > 6:
        if obj[0:7] == 'custab_':
            selector = {
                "selector": {
                    "type": {
                        "$eq": "tab"
                    },
                    "tab_id": {
                        "$eq": obj
                    }
                }
            }
            response = couch_db.post(r'/jsmm/_find/', selector)
            tab = json.loads(response.body.decode('utf-8'))
            tabObj = tab['docs'][0]
            ws.write_merge(current_row, current_row, 0, 9, u'')
            ws.write_merge(current_row + 1, current_row + 1, 0, 9,
                           tabObj['gridTitle'], style)
            columns = tabObj['columns']
            for y in range(0, len(columns)):
                ws.write(current_row + 2, y, columns[y]['title'],
                         memberInfoStyle)

            for i in range(0, len(member[obj])):
                memberObj = member[obj][i]
                for z in range(0, len(columns)):
                    ws.write(current_row + 3 + i, z,
                             memberObj['file_' + str(z)], memberInfoStyle)

            obj_row = 3 + len(member[obj])
            current_row += obj_row
    return current_row
Example #4
0
    def get(self):
        """
        通过find获取对象列表。
        """

        obj = {"selector": {"type": {"$eq": "tab"}}}

        response = couch_db.post(r'/jsmm/_find/', obj)
        tab = json.loads(response.body.decode('utf-8'))
        self.write(tab)
Example #5
0
    def delete(self, tab_name):
        # 判断自定义tab名称是否已经存在
        tab_id = 'custab_' + ''.join(lazy_pinyin(tab_name))
        tab_selector = {"selector": {"tab_id": {"$eq": tab_id}}}

        response = couch_db.post(r'/jsmm/_find/', tab_selector)
        tabs = json.loads(response.body.decode('utf-8'))
        tab_list = tabs["docs"]
        # 判断是否存在名称为tab_name的tab
        if len(tab_list) <= 0:
            result = {"success": False, "content": u"该tab名称不存在,请重新输入!"}
        else:
            tab_target = tab_list[0]
            # 刪除member中的tab信息
            member_selector = {
                "selector": {
                    "$and": [{
                        "type": {
                            "$eq": "member"
                        }
                    }, {
                        tab_id: {
                            "$ne": "null"
                        }
                    }]
                }
            }

            member_response = couch_db.post(r'/jsmm/_find/', member_selector)
            member_list = json.loads(
                member_response.body.decode('utf-8'))["docs"]
            for member in member_list:
                del member[tab_id]
                couch_db.put(r'/jsmm/%(id)s' % {"id": member["_id"]}, member)

            # 刪除tab
            couch_db.delete(r'/jsmm/%(id)s?rev=%(rev)s' % {
                'id': tab_target["_id"],
                'rev': tab_target["_rev"]
            })
            result = {"success": True}
        self.write(result)
Example #6
0
    def post(self):
        """
        创建tab对象。
        """
        print(self.request.files)
        tab = json.loads(self.request.body.decode('utf-8'))
        tab['type'] = 'tab'
        tab['_id'] = make_uuid()
        tab['tab_id'] = 'custab_' + ''.join(lazy_pinyin(tab['gridTitle']))

        # 判断自定义tab名称是否已经存在
        obj = {"selector": {"tab_id": {"$eq": tab['tab_id']}}}

        response = couch_db.post(r'/jsmm/_find/', obj)
        tabs = json.loads(response.body.decode('utf-8'))
        if len(tabs["docs"]) > 0:
            result = {"success": False, "content": u"该tab名称已经存在,请重新输入!"}
        else:
            couch_db.post(r'/jsmm/', tab)
            result = {"success": True}
        self.write(result)
Example #7
0
    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)
Example #8
0
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)
Example #9
0
 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)
Example #10
0
 def get(self, retire_time):
     """
         退休提醒
     """
     if re.match(
             "([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))",
             retire_time,
             flags=0):
         obj = {
             "selector": {
                 "retireTime": {
                     "$lt": retire_time
                 }
             },
             "fields": [
                 "_id", "_rev", "name", "gender", "birthday", "nation",
                 "idCard", "branch", "organ", "branchTime"
             ]
         }
         response = couch_db.post(r'/jsmm/_find/', obj)
         members = json.loads(response.body.decode('utf-8'))
         self.write(members)
Example #11
0
    def delete(self, member_id):
        """
        删除_id为member_id的member对象。
        """
        # 通过HEAD方法查询Etag(即_rev)。
        response = couch_db.head(r'/jsmm/%(id)s' % {'id': member_id})
        # 从返回的headers中查找包含"Etag"的数据,取第一条,并去除头尾的双引号。
        rev = response.headers.get_list('Etag')[0][1:-1]
        # couch_db.delete(r'/jsmm/%(id)s?rev=%(rev)s' % {'id': member_id, 'rev': rev})
        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']:
            couch_db.delete(r'/jsmm/%(id)s?rev=%(rev)s' %
                            {'id': doc['value']['_id'], 'rev': doc['value']['_rev']})

        couch_db.delete(r'/jsmm/%(id)s?rev=%(rev)s' %
                        {'id': member_id, 'rev': rev})

        response = {'success': 'true'}
        self.write(response)
Example #12
0
    def get(self, search_obj):
        keys = [
            'name', 'gender', 'sector', 'lost', 'stratum', 'jobLevel',
            'titleLevel', 'highestEducation'
        ]
        column_name = [
            "name", "gender", "highestEducation", "jobTitle", "duty", "mobile",
            "email", "companyName", "companyTel", "commAddress", "commPost"
        ]
        titles = {
            u'姓名': 10,
            u'性别': 6,
            u'最高学历': 10,
            u'职称': 12,
            u'职务': 12,
            u'移动电话': 13,
            u'邮箱': 25,
            u'单位名称': 26,
            u'单位电话': 15,
            u'单位地址': 40,
            u'邮编': 10
        }
        selector = {"selector": {}, "fields": column_name}
        selector_content = selector["selector"]
        search = json.loads(search_obj.replace('/', ''))

        for key in keys:
            if key in search:
                if search[key] != '':
                    selector_content[key] = {'$eq': search[key]}

        if 'retireTime' in search:
            if search['retireTime'] != '':
                selector_content['retireTime'] = {"$lt": search["retireTime"]}

        if 'branch' in search:
            if search['branch'] != '' and search[
                    'branch'] != u'北京市' and search['branch'] != u'朝阳区':
                selector_content['branch'] = {"$eq": search["branch"]}

        if 'socialPositionName' in search:
            if search['socialPositionName'] != '':
                selector_content['social'] = {
                    "$elemMatch": {
                        "socialPositionName": {
                            "$regex": search['socialPositionName']
                        }
                    }
                }

        if 'socialPositionLevel' in search:
            if search['socialPositionLevel'] != '':
                selector_content['social'] = {
                    "$elemMatch": {
                        "socialPositionLevel": {
                            "$regex": search['socialPositionLevel']
                        }
                    }
                }

        if 'formeOrganizationJob' in search:
            if search['formeOrganizationJob'] != '':
                selector_content['formercluboffice'] = {
                    "$elemMatch": {
                        "formeOrganizationJob": {
                            "$regex": search['formeOrganizationJob']
                        }
                    }
                }

        if 'formeOrganizationLevel' in search:
            if search['formeOrganizationLevel'] != '':
                selector_content['formercluboffice'] = {
                    "$elemMatch": {
                        "formeOrganizationLevel": {
                            "$regex": search['formeOrganizationLevel']
                        }
                    }
                }

        if 'startAge' in search and 'endAge' in search:
            if search['startAge'] != '' and search['endAge']:
                selector_content['birthday'] = {
                    "$gte": search['endAge'],
                    "$lte": search['startAge']
                }

        selector_content['type'] = {"$eq": "member"}

        response = couch_db.post(r'/jsmm/_find/', selector)
        members_simple_info = json.loads(response.body.decode('utf-8'))["docs"]

        style_heading = xlwt.easyxf("""
                font:
                    name 微软雅黑,
                    colour_index black,
                    bold on,
                    height 200;
                align:
                    wrap off,
                    vert center,
                    horiz centre;
                pattern:
                    pattern solid,
                    fore-colour 22;
                borders:
                    left THIN,
                    right THIN,
                    top THIN,
                    bottom THIN;
                """)
        style_data = xlwt.easyxf("""
                        font:
                            name 微软雅黑,
                            colour_index black,
                            bold off,
                            height 180;
                        align:
                            wrap off,
                            vert center,
                            horiz left;
                        pattern:
                            pattern solid,
                            fore-colour 1;
                        borders:
                            left thin,
                            right thin,
                            top thin,
                            bottom thin;
                        """)

        workbook = xlwt.Workbook(encoding='utf-8')
        worksheet = workbook.add_sheet('社员信息简表')

        column = 0
        row = 0
        for title in titles:
            worksheet.write(row, column, title, style_heading)
            worksheet.col(column).width = titles[title] * 256
            column += 1

        if len(members_simple_info) > 0:
            row = 1
            for member in members_simple_info:
                column = 0
                for key in column_name:
                    worksheet.write(
                        row, column, '',
                        style_data) if key not in member else worksheet.write(
                            row, column, member[key], style_data)
                    column += 1

                row += 1
        else:
            pass

        sio = BytesIO()
        workbook.save(sio)
        self.set_header('Content-Type', 'application/vnd.ms-excel')
        self.set_header(
            'Content-Disposition', 'attachment; filename=' +
            urllib.parse.quote('社员信息简表.xls', "utf-8"))
        self.write(sio.getvalue())
        self.finish()