示例#1
0
文件: school.py 项目: realjade/match
def school_add():
    city_id = request.values.get('cityid',None)
    name = request.values.get('name',None)
    if not city_id or not name:
        return f.failed(*const.INVALID_PARAMS)
    school = f.load_school_by_name(name,city_id)
    if school:
        return f.failed(*const.SCHOOL_EXIST)
    school = School(city_id = city_id, name = name, created = int(time.time()*1000), updated = int(time.time()*1000))
    m.session.add(school)
    m.session.commit()
    return f.succeed(school.tojson())
示例#2
0
def school_add():
    city_id = request.values.get('cityid', None)
    name = request.values.get('name', None)
    if not city_id or not name:
        return f.failed(*const.INVALID_PARAMS)
    school = f.load_school_by_name(name, city_id)
    if school:
        return f.failed(*const.SCHOOL_EXIST)
    school = School(city_id=city_id,
                    name=name,
                    created=int(time.time() * 1000),
                    updated=int(time.time() * 1000))
    m.session.add(school)
    m.session.commit()
    return f.succeed(school.tojson())
示例#3
0
def school_update():
    school_id = request.values.get('schoolid', None)
    name = request.values.get('name', None)
    if not school_id or not name:
        return f.failed(*const.INVALID_PARAMS)
    school = m.session.query(School).filter(School.id == school_id).first()
    if not school:
        return f.failed(*const.SCHOOL_NOT_EXIST)
    if school.name == name:
        return f.failed(*const.INVALID_PARAMS)
    hasSchool = f.load_school_by_name(name, school.city_id)
    if hasSchool:
        return f.failed(*const.SCHOOL_NOT_EXIST)
    school.name = name
    school.updated = time.time() * 1000
    m.session.commit()
    return f.succeed(school.tojson())
示例#4
0
文件: school.py 项目: realjade/match
def school_update():
    school_id = request.values.get('schoolid',None)
    name = request.values.get('name',None)
    if not school_id or not name:
        return f.failed(*const.INVALID_PARAMS)
    school = m.session.query(School).filter(School.id == school_id).first()
    if not school:
        return f.failed(*const.SCHOOL_NOT_EXIST)
    if school.name == name:
        return f.failed(*const.INVALID_PARAMS)
    hasSchool = f.load_school_by_name(name,school.city_id)
    if hasSchool:
        return f.failed(*const.SCHOOL_NOT_EXIST)
    school.name = name
    school.updated = time.time()*1000
    m.session.commit()
    return f.succeed(school.tojson())
示例#5
0
def server_internal_error(error):
    import traceback
    errormsg = traceback.format_exc()
    errormsg = errormsg.replace('\n', '\r')
    logutil.log(level='ERROR', msg={'statuscode':500, 'description':errormsg})
    if request.path[:4] == '/up/' or request.path[:5] == '/api/':
        return f.failed(*const.SERVER_INTERNAL_ERROR)
    else:
        return f.web_failed(*const.SERVER_INTERNAL_ERROR)
示例#6
0
def upload_attachment():
    file = request.files.get('file')
    if not file:
        name = request.args.get('name')
        file = FileStorage(request.stream, filename=name, name=name, headers=request.headers)
    if file:
        fh = FileHelper(file)
        fh.save()
        if fh.savepath:
            return f.succeed({'filepath':fh.savepath})
    return f.failed(*const.UPLOAD_FAIL)
示例#7
0
def upload_attachment():
    file = request.files.get('file')
    if not file:
        name = request.args.get('name')
        file = FileStorage(request.stream,
                           filename=name,
                           name=name,
                           headers=request.headers)
    if file:
        fh = FileHelper(file)
        fh.save()
        if fh.savepath:
            return f.succeed({'filepath': fh.savepath})
    return f.failed(*const.UPLOAD_FAIL)
示例#8
0
def delete_attachment():
    filepath = request.form.get('filepath',None)
    if not filepath:
        return f.failed(*const.INVALID_PARAMS)
    os.remove(filepath)
    return f.succeed('ok')
示例#9
0
def delete_attachment():
    filepath = request.form.get('filepath', None)
    if not filepath:
        return f.failed(*const.INVALID_PARAMS)
    os.remove(filepath)
    return f.succeed('ok')