Ejemplo n.º 1
0
def modify_honor():
    honor_form = form.HonorForm()
    file_form = form.FileUploadForm()
    honor_form.users.choices = user_server.get_user_choice()
    if honor_form.validate_on_submit():
        try:
            honor = honor_server.get_by_id(honor_form.id.data)
            from dao.dbResource import ResourceLevel, ResourceUsage
            resource_list = []
            for name, file in request.files.items(multi=True):
                if file.filename == '':
                    continue
                file_form.level.data = ResourceLevel.PUBLIC
                file_form.name.data = unicode(file.filename).split('.')[0]
                file_form.usage.data = ResourceUsage.HONOR_RES
                ret = resource_server.save_file(file_form, file, current_user, 'honor')
                if ret == 'OK':
                    resource = resource_server.get_by_name(file_form.name.data)
                    resource_list.append(resource)
            msg = honor_server.modify_honor(honor, honor_form, resource_list)
            return msg
        except:
            current_app.logger.error(traceback.format_exc())
            return 'failed'
    return u'数据填写有误'
Ejemplo n.º 2
0
def add_honor():
    honor_form = form.HonorForm()
    file_form = form.FileUploadForm()
    honor_form.users.choices = user_server.get_user_choice()
    if honor_form.validate_on_submit():
        try:
            from dao.dbResource import ResourceLevel, ResourceUsage
            resource_list = []
            for name, file in request.files.items(multi=True):
                file_form.level.data = ResourceLevel.PUBLIC
                file_form.name.data = unicode(file.filename).split('.')[0]
                file_form.usage.data = ResourceUsage.HONOR_RES
                resource_server.save_file(file_form, file, current_user)
                resource = resource_server.get_by_name(file_form.name.data)
                resource_list.append(resource)
            msg = honor_server.add_honor(honor_form, resource_list)
            return msg
        except Exception, e:
            print e
            return 'failed'
Ejemplo n.º 3
0
def upload():
    file_form = form.FileUploadForm()
    if file_form.validate_on_submit():
        try:
            if file_form.upload.data:
                file = request.files[file_form.upload.name]
                msg = resource_server.save_file(file_form, file, current_user)
                return msg
            else:
                return u'上传数据失败'
        except Exception, e:
            return u'错误: ' + e.message
Ejemplo n.º 4
0
def upload():
    file_form = form.FileUploadForm()
    if file_form.validate_on_submit():
        try:
            if file_form.upload.data:
                file = request.files[file_form.upload.name]
                msg = resource_server.save_file(file_form, file, current_user, 'other')
                return msg
            else:
                return u'上传数据失败'
        except Exception, e:
            current_app.logger.error(traceback.format_exc())
            return u'错误: ' + e.message
Ejemplo n.º 5
0
def upload_poster():
    from dao.dbResource import ResourceLevel, ResourceUsage
    file_form = form.FileUploadForm()
    file_form.level.data = str(ResourceLevel.PUBLIC)
    file_form.usage.data = str(ResourceUsage.POSTER_RES)
    if file_form.validate_on_submit():
        try:
            file_canvas = request.form.get('croppedImage')
            if file_canvas:
                file_string = re.sub('^data:image/.+;base64,', '', file_canvas).decode('base64')
                file_binary = cStringIO.StringIO(file_string)
                file = FileStorage(file_binary, file_form.name.data + '.jpg')
                msg = resource_server.save_file(file_form, file, current_user, 'poster')
                return msg
            else:
                return u'上传数据失败'
        except Exception, e:
            return u'错误: ' + e.message