Exemple #1
0
def modify_honor():
    if not current_user.is_admin and not current_user.is_coach:
        return redirect(url_for('main.index'))
    try:
        honor = honor_server.get_by_id(request.args['p'])
    except:
        return redirect(url_for('admin.manage_honor'))

    honor_form = form.HonorForm()
    honor_form.users.choices = user_server.get_user_choice()
    honor_form.id.data = honor.id
    honor_form.acquire_time.data = honor.acquire_time
    honor_form.contest_name.data = honor.contest_name
    honor_form.team_name.data = honor.team_name
    honor_form.contest_level.data = str(honor.contest_level)
    honor_form.users.data = [user.username for user in honor.users]
    upload_form = form.FileUploadForm()
    from dao.dbResource import ResourceLevel, ResourceUsage
    upload_form.level.data = str(ResourceLevel.PUBLIC)
    upload_form.usage.data = str(ResourceUsage.HONOR_RES)
    return render_template('edit_honor.html',
                           title = u'修改荣誉',
                           honor_form = honor_form,
                           upload_form = upload_form,
                           exist_res = honor.resources,
                           file_url = resource_server.file_url)
Exemple #2
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'数据填写有误'
Exemple #3
0
def modify_honor():
    honor_form = form.HonorForm()
    honor_form.users.choices = user_server.get_user_choice()
    if honor_form.validate_on_submit():
        try:
            msg = honor_server.modify_honor(honor_form)
            return msg
        except:
            return 'failed'
    return u'数据填写有误'
Exemple #4
0
def add_honor():
    if not current_user.is_admin and not current_user.is_coach:
        return redirect(url_for('main.index'))
    honor_form = form.HonorForm()
    honor_form.users.choices = user_server.get_user_choice()
    upload_form = form.FileUploadForm()
    from dao.dbResource import ResourceLevel, ResourceUsage
    upload_form.level.data = str(ResourceLevel.PUBLIC)
    upload_form.usage.data = str(ResourceUsage.HONOR_RES)
    return render_template('add_honor.html',
                           title = u'添加荣誉',
                           honor_form = honor_form,
                           upload_form = upload_form)
Exemple #5
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'