Exemple #1
0
    def _get_news_or_notice(self, key):
        """
        返回新闻或通知
        key不带Id时返回所有的新闻或通知
        key为指定id值时返回具体新闻或通知内容
        """
        # 返回所有新闻的名字,时间,和对应id
        if key in ('news', 'notice'):
            with db.execution_context():
                all_data = main_data.select(main_data.name_id,
                                            main_data.html_content). \
                                    where(main_data.name_id.startswith(key))
            data_list = []
            for data in all_data:
                data = model_to_dict(data)
                title = self._get_title(data['html_content'])
                time = self._get_time(data['name_id'])
                news_id = data['name_id']
                data_list.append({
                    'name': title,
                    'time': time,
                    'id': news_id
                })

            return {'data': data_list}
        else:
            # 带具体值时返回新闻具体内容
            with db.execution_context():
                single_data = main_data.select(main_data.html_content) \
                                    .where(main_data.name_id == key)
            return {'HTML': str(single_data[0].html_content)}
Exemple #2
0
 def _rewrite_html(self, key, html):
     """修改html内容
     """
     with db.execution_context():
         html_content = main_data.select().where(main_data.name_id == key)
     if not html_content:
         # 第一次添加
         with db.execution_context():
             main_data.create(**{"name_id": key, "html_content": html})
     else:
         with db.execution_context():
             main_data.update(**{
                 "html_content": html
             }).where(main_data.name_id == key).execute()
     return {"state": "SUCCESS"}
Exemple #3
0
    def _get_all_overview_data(self, key):
        """返回所有概览信息

        可能的类别有领导,教师,纪实活动,欢乐时光
        数据格式{"getdata": [{"pictures": "src",
                             "html": "xxxxx",
                             "name": "overviews_xxxxx"},
                             {"pictures": "src",
                              "html": "xxxxxx",
                              "name": "overviews_xxxxx"}]}
        """
        if key == 'leaders':
            name = 'leader'
        elif key == 'teachers':
            name = 'teacher'
        else:
            name = key
        with db.execution_context():
            overviews = main_data.select(main_data.name_id,
                                         main_data.html_content) \
                               .where(main_data.name_id.startswith(name))
        data_list = []
        for overview in overviews:
            overview = model_to_dict(overview)
            edit = overview['html_content']
            pictures = re.findall(r'src="(.*?)"', overview['html_content'])
            pictures = pictures[0]
            html = re.sub(r'<img.*?>', '', overview['html_content'])
            data_list.append({"pictures": pictures,
                              "html": html,
                              "name": overview['name_id'],
                              "edit": edit})
        return {"getdata": data_list}
Exemple #4
0
    def _set_lab_data(self, key, html):
        """添加或修改组织机构的信息

        key值为固定四个值之一
        """
        with db.execution_context():
            data = main_data.select().where(main_data.name_id == key)
        if not data:
            # 第一次插入
            with db.execution_context():
                main_data.create(**{'name_id': key, 'html_content': html})
        else:
            # 更新
            with db.execution_context():
                main_data.update(**{
                    'html_content': html
                }).where(main_data.name_id == key).execute()
        return {'state': 'SUCCESS'}
Exemple #5
0
 def _get_html_data(self, key):
     """返回key值对应的html_content内容
     """
     with db.execution_context():
         data = main_data.select(main_data.html_content).where(
             main_data.name_id == key)
     if not data:
         return {'error': 'no data'}
     return {'HTML': str(data[0].html_content)}
Exemple #6
0
    def _get_science_result_data(self, key):
        """返回科研成果html内容

        分为系统证书,专利,论文,软著
        ('gains', 'patent', 'article', 'soft')
        """
        with db.execution_context():
            data = main_data.select(main_data.html_content).where(
                main_data.name_id == key)
        return {'HTML': data[0].html_content}
Exemple #7
0
    def _delete_data(self, key):
        """从数据库中删除一条记录

        根据key值delete_之后name_id删除
        """
        name = key[7:]
        detail_name = 'desc_' + name
        with db.execution_context():
            # 删除概览记录
            main_data.delete().where(main_data.name_id == name).execute()
            # 删除详细记录
            main_data.delete().where(main_data.name_id == detail_name) \
                              .execute()
        return {'state': 'SUCCESS'}
Exemple #8
0
    def _rewrite_news_or_notice(self, key, html):
        """
        修改新闻或通知
        """
        title = re.findall(r'<h1>(.*?)</h1>', html)
        if not title:
            return {'error': '缺少一个标题'}
        elif len(title) >= 2:
            return {'error': '标题数目大于一个'}

        with db.execution_context():
            main_data.update(**{"html_content": html}) \
                    .where(main_data.name_id == key).execute()
        return {'state': 'SUCCESS'}
Exemple #9
0
    def _get_images(self, key):
        """提取html中所有图片的src

        html为首页走马灯或中心环境的html内容
        key值为'index_imgs'或'enviro_imgs'
        json:{'pictures': ['url_1', 'url_2', 'url_3']}
        """
        name = key + '_html'
        with db.execution_context():
            html_data = main_data.select(main_data.html_content) \
                                .where(main_data.name_id == name)
        html_data = model_to_dict(html_data[0])
        src = re.findall(r'src="(.*?)"', html_data["html_content"])
        return {'pictures': src}
Exemple #10
0
    def _rewrite_overview_or_detail_data(self, key, html):
        """修改概览信息或者详细信息

        提取key值中的name_id字段
        """
        name = key[8:]
        if 'desc_' not in name:
            # 修改概览信息
            pictures = re.findall(r'src="(.*?)"', html)
            if not pictures or len(pictures) > 1:
                return {'error': '照片数量必须为1'}
        with db.execution_context():
            main_data.update(**{
                'html_content': html
            }).where(main_data.name_id == name).execute()
        return {'state': 'SUCCESS'}
Exemple #11
0
    def _add_data(self, key, html):
        """在数据库中添加一条记录

        根据key值的不同选择不同的前缀+时间戳形成name_id字段
        """
        now = datetime.datetime.now()
        time = now.strftime('%y%m%d%H%M%S')
        pre_name = key.split('_')[1]
        name = pre_name + '_' + time
        detail_name = 'desc_' + name
        pictures = re.findall(r'src="(.*?)"', html)
        if not pictures or len(pictures) > 1:
            return {'error': '照片数量必须为1'}
        with db.execution_context():
            # 插入概览信息
            main_data.create(**{'name_id': name, 'html_content': html})
            main_data.create(**{'name_id': detail_name, 'html_content': ''})
        return {'state': 'SUCCESS'}
Exemple #12
0
    def _add_news_or_notice(self, key, html):
        """
        添加新闻或通知
        """
        title = re.findall(r'<h1(.*?)</h1>', html)
        if not title:
            return {'error': '缺少一个标题'}
        elif len(title) >= 2:
            return {'error': '标题数目大于一个'}

        now = datetime.datetime.now()
        time = now.strftime('%y%m%d%H%M%S')

        name = key + '_' + time

        with db.execution_context():
            main_data.create(**{"name_id": name, "html_content": html})
        return {'state': 'SUCCESS'}