コード例 #1
0
    def GET(self):
        if not helper.logged(helper.PRIV_MCH, 'OBJ_STORE'):
            raise web.seeother('/')

        mch_id = helper.get_session_mch_id()
        render = helper.create_render()
        user_data = web.input(obj_id='', exam_id='')

        if user_data.obj_id.strip() == '':
            return render.info('obj_id不能为空!')

        exam_data = {'exam_id': 'n/a'}

        if user_data.exam_id != '':
            db_exam = db.exam_info.find_one({
                'exam_id': user_data.exam_id,
                'mch_id': mch_id
            })
            if db_exam != None:
                # 已存在的obj
                exam_data = db_exam

        return render.exam_edit(helper.get_session_uname(),
                                helper.get_privilege_name(), exam_data,
                                user_data.obj_id)
コード例 #2
0
ファイル: topic_store_edit.py プロジェクト: jack139/pretty
    def GET(self):
        if not helper.logged(helper.PRIV_MCH, 'TOPIC_STORE'):
            raise web.seeother('/')

        mch_id = helper.get_session_mch_id()
        render = helper.create_render()
        user_data = web.input(tpc_id='')

        obj_data = {'tpc_id': 'n/a'}
        obj_list = []

        if user_data.tpc_id != '':
            db_obj = db.topic_store.find_one({
                'tpc_id': user_data.tpc_id,
                'mch_id': mch_id
            })
            if db_obj is not None:
                # 已存在的obj
                obj_data = db_obj
                obj_list = db.obj_store.find({
                    'obj_type': 'topic',
                    'tpc_id': user_data.tpc_id
                })

        return render.topic_store_edit(helper.get_session_uname(),
                                       helper.get_privilege_name(), obj_data,
                                       obj_list)
コード例 #3
0
    def POST(self):
        if not helper.logged(helper.PRIV_MCH, 'OBJ_STORE'):
            raise web.seeother('/')
        mch_id = helper.get_session_mch_id()
        render = helper.create_render()
        user_data = web.input(obj_id='', tpc_id='')

        if user_data.obj_id == '' and user_data.tpc_id == '':
            return render.info('参数错误!')

        if user_data.obj_id != '':  # 课程
            db_obj = db.obj_store.find_one({
                'obj_id': user_data.obj_id,
                'mch_id': mch_id
            })
            if db_obj is None:
                return render.info('obj_id参数错误!')

            object_helper.obj_change_status(user_data['obj_id'], 'WAIT',
                                            '提交审核')

            return render.info('成功提交!', '/mch/obj_store')

        else:  # 专辑
            db_obj = db.topic_store.find_one({
                'tpc_id': user_data.tpc_id,
                'mch_id': mch_id
            })
            if db_obj is None:
                return render.info('tpc_id参数错误!')

            object_helper.topic_change_status(user_data['tpc_id'], 'WAIT',
                                              '提交审核')

            return render.info('成功提交!', '/mch/topic_store')
コード例 #4
0
ファイル: topic_store_edit.py プロジェクト: jack139/pretty
    def POST(self):
        if not helper.logged(helper.PRIV_MCH, 'TOPIC_STORE'):
            raise web.seeother('/')
        mch_id = helper.get_session_mch_id()
        render = helper.create_render()
        user_data = web.input(tpc_id='')

        if user_data.tpc_name.strip() == '':
            return render.info('品名不能为空!')

        if user_data['tpc_id'] == 'n/a':  # 新建
            db_pk = db.user.find_one_and_update({'uname': 'settings'},
                                                {'$inc': {
                                                    'sa_count': 1
                                                }}, {'sa_count': 1})
            tpc_id = '2%07d' % db_pk['sa_count']
            message = '新建'
        else:
            tpc_id = user_data['tpc_id']
            message = '修改'

        try:
            update_set = {
                'tpc_id': tpc_id,
                'tpc_name': user_data['tpc_name'],
                'title': user_data['title'],
                'title2': user_data['title2'],
                'description': user_data['description'],
                'note': user_data['note'],
                'last_tick': int(time.time()),  # 更新时间戳
                'image': user_data['image'].split(','),  # 图片
                'price': int(float(user_data['price']) * 100),  # 单位: 分
                'status':
                'SAVED',  # 审核状态: SAVED 已修改未提交 WAIT 提交等待审核  PASS 审核通过 NOGO 审核拒绝
            }
        except ValueError:
            return render.info('请在相应字段输入数字!')

        r2 = db.topic_store.find_one_and_update(
            {
                'tpc_id': tpc_id,
                'mch_id': mch_id
            },
            {
                '$set': update_set,
                '$push': {
                    'history':
                    (helper.time_str(), helper.get_session_uname(), message),
                }  # 纪录操作历史
            },
            upsert=True)

        if r2 and r2.get('status') != 'SAVED':
            object_helper.topic_change_status(tpc_id, 'SAVED', u'专辑修改')

        return render.info('成功保存!', '/mch/topic_store')
コード例 #5
0
    def POST(self):
        if not helper.logged(helper.PRIV_MCH, 'OBJ_STORE'):
            raise web.seeother('/')
        mch_id = helper.get_session_mch_id()
        render = helper.create_render()
        user_data = web.input(exam_id='', obj_id='', correct=[], option=[])

        #print user_data

        if user_data.obj_id.strip() == '':
            return render.info('obj_id不能为空!')

        if user_data.question.strip() == '':
            return render.info('题目内容不能为空!')

        if user_data['exam_id'] == 'n/a':  # 新建
            db_pk = db.user.find_one_and_update({'uname': 'settings'},
                                                {'$inc': {
                                                    'pk_count': 1
                                                }}, {'pk_count': 1})
            exam_id = 'ex%07d' % db_pk['pk_count']
            message = '新建'
        else:
            exam_id = user_data['exam_id']
            message = '修改'

        try:
            update_set = {
                'obj_id': user_data['obj_id'],
                'question': user_data['question'],
                'correct': user_data['correct'],
                'option': user_data['option'],
                'score': int(user_data['score']),
                'available': int(user_data['available']),
                'last_tick': int(time.time()),  # 更新时间戳
            }
        except ValueError:
            return render.info('请在相应字段输入数字!')

        db.exam_info.update_one(
            {
                'exam_id': exam_id,
                'mch_id': mch_id
            },
            {
                '$set': update_set,
                '$push': {
                    'history':
                    (helper.time_str(), helper.get_session_uname(), message),
                }  # 纪录操作历史
            },
            upsert=True)

        return render.info('成功保存!',
                           '/mch/exam?obj_id=%s' % user_data['obj_id'])
コード例 #6
0
ファイル: topic_store.py プロジェクト: jack139/pretty
    def GET(self):
        if not helper.logged(helper.PRIV_MCH, 'TOPIC_STORE'):
            raise web.seeother('/')
        user_data = web.input(page='0')
        render = helper.create_render()
        mch_id = helper.get_session_mch_id()
        #print mch_id

        if not user_data['page'].isdigit():
            return render.info('参数错误!')

        # 分页获取数据
        db_sku = db.topic_store.find({'mch_id': mch_id},
                                     sort=[('obj_id', -1)],
                                     limit=PAGE_SIZE,
                                     skip=int(user_data['page']) * PAGE_SIZE)

        sku_data = []
        for x in db_sku:
            one = {
                'tpc_id': x['tpc_id'],
                'tpc_name': x['tpc_name'],
                'title': x['title'],
                'obj_count': 0,
                'note': x['note'],
                'status': x.get('status', 'SAVED'),
            }
            r2 = db.obj_store.find({
                'obj_type': 'topic',
                'tpc_id': x['tpc_id']
            })
            one['obj_count'] = r2.count()
            sku_data.append(one)

        num = db_sku.count()
        if num % PAGE_SIZE > 0:
            num = num / PAGE_SIZE + 1
        else:
            num = num / PAGE_SIZE

        return render.topic_store(helper.get_session_uname(),
                                  helper.get_privilege_name(), sku_data,
                                  range(0, num), helper.OBJ_STATUS)
コード例 #7
0
ファイル: exam.py プロジェクト: jack139/pretty
    def GET(self):
        if not helper.logged(helper.PRIV_MCH, 'OBJ_STORE'):
            raise web.seeother('/')
        user_data = web.input(page='0', obj_id='')
        render = helper.create_render()
        mch_id = helper.get_session_mch_id()
        #print mch_id

        if not user_data['page'].isdigit():
            return render.info('参数错误!')

        if user_data['obj_id'] == '':
            return render.info('obj_id参数错误!')

        db_sku = db.exam_info.find(
            {
                'obj_id': user_data['obj_id'],
                'mch_id': mch_id
            },
            sort=[('available', -1), ('exam_id', 1)],
            limit=PAGE_SIZE,
            skip=int(user_data['page']) * PAGE_SIZE)

        sku_data = []
        for x in db_sku:
            one = {
                'exam_id': x['exam_id'],
                'question': x['question'],
                'available': x['available'],
                'mch_id': x['mch_id'],
            }
            sku_data.append(one)

        num = db_sku.count()
        if num % PAGE_SIZE > 0:
            num = num / PAGE_SIZE + 1
        else:
            num = num / PAGE_SIZE

        return render.exam(helper.get_session_uname(),
                           helper.get_privilege_name(), sku_data,
                           range(0, num), user_data['obj_id'])
コード例 #8
0
ファイル: obj_store_edit.py プロジェクト: jack139/pretty
    def GET(self):
        if not helper.logged(helper.PRIV_MCH, 'OBJ_STORE'):
            raise web.seeother('/')

        mch_id = helper.get_session_mch_id()
        render = helper.create_render()
        user_data = web.input(obj_id='')

        obj_data = { 'obj_id' : 'n/a'}

        if user_data.obj_id != '': 
            db_obj=db.obj_store.find_one({'obj_id':user_data.obj_id, 'mch_id':mch_id})
            if db_obj!=None:
                # 已存在的obj
                obj_data = db_obj

        db_topic = db.topic_store.find({'mch_id':mch_id})

        return render.obj_store_edit(helper.get_session_uname(), helper.get_privilege_name(), 
            obj_data, db_topic)
コード例 #9
0
    def GET(self):
        if not helper.logged(helper.PRIV_MCH, 'OBJ_STORE'):
            raise web.seeother('/')
        user_data = web.input(obj_id='', tpc_id='')
        render = helper.create_render()
        mch_id = helper.get_session_mch_id()
        #print mch_id

        if user_data.obj_id == '' and user_data.tpc_id == '':
            return render.info('参数错误!')

        if user_data.obj_id != '':  # 课程
            db_obj = db.obj_store.find_one({
                'obj_id': user_data.obj_id,
                'mch_id': mch_id
            })
            if db_obj is None:
                return render.info('obj_id参数错误!')

            object_name = db_obj['obj_name']
        else:
            db_obj = db.topic_store.find_one({
                'tpc_id': user_data.tpc_id,
                'mch_id': mch_id
            })
            if db_obj is None:
                return render.info('tpc_id参数错误!')

            object_name = db_obj['tpc_name']

        if db_obj.get('status') == 'PASSED':
            return render.info('此课程已审核通过!')

        return render.check_submit(helper.get_session_uname(),
                                   helper.get_privilege_name(),
                                   user_data.obj_id, user_data.tpc_id,
                                   object_name, db_obj['title'])
コード例 #10
0
ファイル: obj_store_edit.py プロジェクト: jack139/pretty
    def POST(self):
        if not helper.logged(helper.PRIV_MCH, 'OBJ_STORE'):
            raise web.seeother('/')
        mch_id = helper.get_session_mch_id()
        render = helper.create_render()
        user_data=web.input(obj_id='', tpc_id='')

        if user_data.obj_name.strip()=='':
            return render.info('品名不能为空!')  

        if not user_data.has_key('obj_type'):
            return render.info('请选择商品类型!')

        if not user_data.has_key('media'):
            return render.info('请选择媒体类型!')


        if user_data['obj_id']=='n/a': # 新建
            db_pk = db.user.find_one_and_update(
                {'uname'    : 'settings'},
                {'$inc'     : {'sa_count' : 1}},
                {'sa_count' : 1}
            )
            obj_id = '1%07d' % db_pk['sa_count']
            message = '新建'
        else:
            obj_id = user_data['obj_id']
            message = '修改'

        try:
            update_set={
                'obj_id'      : obj_id,
                'obj_name'    : user_data['obj_name'],
                'title'       : user_data['title'],
                'title2'      : user_data['title2'],
                'speaker'     : user_data['speaker'],
                'speaker_media' : user_data['speaker_media'],
                'description' : user_data['description'],
                'price'       : int(float(user_data['price'])*100), # 单位: 分
                'volume'      : int(user_data['volume']),
                'media'       : user_data['media'],
                'obj_type'    : user_data['obj_type'],
                'tpc_id'      : user_data['tpc_id'] if user_data['obj_type']=='topic' else '', # 如果 obj_type=='course',此字段应该为空
                'length'      : int(user_data['length']),
                'try_time'    : int(user_data['try_time']),
                'note'        : user_data['note'],
                'exam_note'   : user_data['exam_note'],
                'last_tick'   : int(time.time()),  # 更新时间戳
                'image'       : user_data['image'].split(','), # 图片
                'media_file'  : user_data['media_file'],
                'status'      : 'SAVED', # 审核状态: SAVED 已修改未提交 WAIT 提交等待审核  PASS 审核通过 NOGO 审核拒绝
            }
        except ValueError:
            return render.info('请在相应字段输入数字!')

        # 取当前数据,如果存在的,用于比较修改
        r2 = db.obj_store.find_one({'obj_id':obj_id, 'mch_id':mch_id},{'media_file':1})

        # 更新数据
        db.obj_store.update_one({'obj_id':obj_id, 'mch_id':mch_id}, {
            '$set'  : update_set,
            '$push' : {
                'history' : (helper.time_str(), helper.get_session_uname(), message), 
            }  # 纪录操作历史
        }, upsert=True)

        if user_data['obj_type']=='topic':
            # 专辑课程,需要将专辑状态设置为已保存
            object_helper.topic_change_status(user_data['tpc_id'], 'SAVED',u'课程%s修改'%obj_id)

        # 检查媒体文件是否有更改,如果视频有更改,需要转码
        if r2 and update_set['media']=='video' and r2.get('media_file')!=update_set['media_file']:
            print '视频转码', obj_id, update_set['media_file']
            db.obj_store.update_one({'obj_id':obj_id, 'mch_id':mch_id}, {'$set':{'transcoded_filename':'CODING'}})
            transcoding.psuh_to_transcoding(obj_id, update_set['media_file'])

        return render.info('成功保存!', '/mch/obj_store')