Ejemplo n.º 1
0
    async def after_insert(self, raw_post: Dict,
                           values_lst: List[SQLValuesToWrite],
                           records: List[DataRecord]):
        for record in records:
            # 添加统计记录
            statistic_new(POST_TYPES.BOARD, record['id'])

            # 管理日志:重置密码
            ManageLog.new(self.current_user, self.current_role,
                          POST_TYPES.BOARD, record['id'], MOP.BOARD_NEW,
                          record['name'])
Ejemplo n.º 2
0
    def after_update(self, raw_post: Dict, values: SQLValuesToWrite,
                     old_records: List[DataRecord], records: List[DataRecord]):
        for old_record, record in zip(old_records, records):
            if 'content' in values:
                # 管理日志:正文编辑
                ManageLog.new(self.current_user, self.current_role,
                              POST_TYPES.TOPIC, record['id'],
                              record['user_id'], MOP.TOPIC_CONTENT_CHANGE,
                              None)
                Topic.update(edit_count=Topic.edit_count +
                             1).where(Topic.id == record['id']).execute()

            if 'title' in values:
                # 管理日志:标题编辑
                ManageLog.new(self.current_user, self.current_role,
                              POST_TYPES.TOPIC, record['id'],
                              record['user_id'], MOP.TOPIC_TITLE_CHANGE, None)

            # 管理日志:改变状态
            ManageLog.add_by_post_changed(self, 'state', MOP.POST_STATE_CHANGE,
                                          POST_TYPES.TOPIC, values, old_record,
                                          record)

            # 管理日志:改变可见度
            ManageLog.add_by_post_changed(self, 'visible',
                                          MOP.POST_VISIBLE_CHANGE,
                                          POST_TYPES.TOPIC, values, old_record,
                                          record)

            # 管理日志:移动板块
            if ManageLog.add_by_post_changed(self, 'board_id',
                                             MOP.TOPIC_BOARD_MOVE,
                                             POST_TYPES.TOPIC, values,
                                             old_record, record):
                statistic_move_topic(old_record['board_id'],
                                     record['board_id'], record['id'])

            # 管理日志:设置精华
            ManageLog.add_by_post_changed(self, 'awesome',
                                          MOP.TOPIC_AWESOME_CHANGE,
                                          POST_TYPES.TOPIC, values, old_record,
                                          record)

            # 管理日志:置顶权重
            ManageLog.add_by_post_changed(self, 'sticky_weight',
                                          MOP.TOPIC_STICKY_WEIGHT_CHANGE,
                                          POST_TYPES.TOPIC, values, old_record,
                                          record)

            # 管理日志:修改权重
            ManageLog.add_by_post_changed(self, 'weight',
                                          MOP.TOPIC_WEIGHT_CHANGE,
                                          POST_TYPES.TOPIC, values, old_record,
                                          record)
Ejemplo n.º 3
0
    def after_update(self, raw_post: Dict, values: SQLValuesToWrite,
                     old_records: List[DataRecord], records: List[DataRecord]):
        for old_record, record in zip(old_records, records):
            # 注:此处记录不考虑可写不可读的情况。代码比较丑陋,后面改吧
            o = old_record.to_dict()
            n = record.to_dict()
            to_remove = set()
            for k, v in n.items():
                if k in o and o[k] == v:
                    to_remove.add(k)
            for k, v in o.items():
                if k in n and n[k] == v:
                    to_remove.add(k)
            for k in to_remove:
                del o[k]
                del n[k]

            # 管理日志
            ManageLog.new(self.current_user, self.current_role,
                          POST_TYPES.BOARD, record['id'], MOP.BOARD_CHANGE,
                          [o, n])