Esempio 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'数据填写有误'
Esempio 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'