示例#1
0
def get_posts():
    offset = request.args.get('offset', 0, int)
    limit = request.args.get('limit', 10, int)

    posts = PostService.get_posts()

    return jsonify_with_data(APIError.OK, posts=posts)
示例#2
0
def add_post():
    title = request.form.get('title')
    content = request.form.get('content')

    post = PostService.add_post(title, content)

    return jsonify_with_data(APIError.OK, post=post)
def edit_new_channel(channel_id):
    name = request.form.get('name')
    alias = request.form.get('alias')
    platform = request.form.get('platform')
    NewChannelService.edit(channel_id, name, alias, platform)

    return jsonify_with_data((200, 'OK'))
示例#4
0
def top_olympics_schedules(schedule_id):
    try:
        top = int(request.args.get('value'))
    except:
        raise InvalidArgument()
    OGScheduleService.top(schedule_id, top=top)
    return jsonify_with_data((200, 'OK'))
示例#5
0
def add_post():
    title = request.form.get("title")
    content = request.form.get("content")

    post = PostService.add_post(title, content)

    return jsonify_with_data(APIError.OK, post=post)
示例#6
0
def add_activity():

    add_dict = request.form.to_dict()
    add_dict['event_id'] = int(add_dict['event_id'])
    ActivityService.add(add_dict)

    return jsonify_with_data(APIError.OK)
示例#7
0
def update_post(post_id):
    title = request.form.get("title")
    content = request.form.get("content")

    post = PostService.update_post(post_id, {"title": title, "content": content})

    return jsonify_with_data(APIError.OK)
示例#8
0
def edit_activity(activity_id):
    add_dict = request.form.to_dict()
    add_dict['event_id'] = int(add_dict['event_id'])

    ActivityService.edit(activity_id, add_dict)

    return jsonify_with_data(APIError.OK)
示例#9
0
def get_posts():
    offset = request.args.get("offset", 0, int)
    limit = request.args.get("limit", 10, int)

    posts = PostService.get_posts()

    return jsonify_with_data(APIError.OK, posts=posts)
示例#10
0
def edit_channel_entrance(subpage_id):
    title = request.form.get('title')
    brief = request.form.get('brief')
    target = request.form.get('target')
    SubPageService.edit(subpage_id, title, target, brief)

    return jsonify_with_data((200, 'OK'))
示例#11
0
def delete_post(post_id):
    post = PostService.get_one(post_id)
    if not post:
        return jsonify_with_error(APIError.NOT_FOUND)

    PostService.delete_post(post_id)

    return jsonify_with_data(APIError.OK)
示例#12
0
def delete_post(post_id):
    post = PostService.get_one(post_id)
    if not post:
        return jsonify_with_error(APIError.NOT_FOUND)

    PostService.delete_post(post_id)

    return jsonify_with_data(APIError.OK)
示例#13
0
def get_team_class():

    teams = TeamClass.query.filter_by()\
                                         .order_by(TeamClass.display_order.asc())\
                                         .all()

    team_class = [team.to_dict() for team in teams]

    return jsonify_with_data(APIError.OK, team_class=team_class)
示例#14
0
def get_news_sites():
    sites = MatchNewsService.get_sites()
    sites_dict = {}

    def add_info_site(site):
        sites_dict[site.site] = site.live_title
        return True

    map(add_info_site, sites)
    return jsonify_with_data((200, 'OK'), sites=sites_dict)
示例#15
0
def edit_assist(scorer_id):

    try:
        assists = request.form.get('assists', type=int)
    except:
        raise InvalidArgument()

    TopassistService.edit(scorer_id, assists)

    return jsonify_with_data(APIError.OK)
示例#16
0
def edit_scorer(scorer_id):

    try:
        goals = request.form.get('goals', type=int)
    except:
        raise InvalidArgument()

    TopscorerService.edit(scorer_id, goals)

    return jsonify_with_data(APIError.OK)
示例#17
0
def top_olympics_news(news_id):

    try:
        top = int(request.args.get('value'))
    except:
        raise InvalidArgument()

    OGNewsService.top(news_id, top=top)

    return jsonify_with_data((200, 'OK'))
示例#18
0
def update_post(post_id):
    title = request.form.get('title')
    content = request.form.get('content')

    post = PostService.update_post(post_id, {
        'title': title,
        'content': content
    })

    return jsonify_with_data(APIError.OK)
示例#19
0
def get_team_player(team_id):
    items = TeamPlayerService.get_player_all(team_id=team_id)

    def get_info(item):
        team = PlayerService.get_one(item['player_id'])
        item['player_name'] = team['name']
        return item

    players = map(get_info, items)

    return jsonify_with_data(APIError.OK, players=players)
示例#20
0
def top_event_news(news_id):

    try:
        top = int(request.args.get('value'))
        type = request.args.get('type')
    except:
        raise InvalidArgument()

    EventNewsService.top(news_id, top=top, type=type)

    return jsonify_with_data((200, 'OK'))
示例#21
0
def relate_collections_videos(collection_id, video_id):
    video = OGVideoService.get_one(video_id)
    if not video:
        return jsonify_with_error((10001, u"该视频不存在!"))

    item = CollectionVideoService.get_filter_one(collection_id, video_id)
    if item:
        return jsonify_with_error((10001, u"该视频已关联到该合集!"))

    CollectionVideoService.add(collection_id, video_id)
    return jsonify_with_data((200, 'OK'))
示例#22
0
def top_event_news(news_id):

    try:
        top = int(request.args.get('value'))
    except:
        raise InvalidArgument()

    value = bool(top)

    EventNewsService.top(news_id, top=value)

    return jsonify_with_data((200, 'OK'))
示例#23
0
def add_scorer():

    try:
        event_id = request.args.get('event_id', type=int)
        player_id = request.form.get('player_id', type=int)
        goals = request.form.get('goals', type=int)
    except:
        raise InvalidArgument()

    TopscorerService.add(event_id, player_id, goals)

    return jsonify_with_data(APIError.OK)
示例#24
0
def edit_scoreboard(scoreboard_id):

    try:
        event_id = int(request.args.get('event_id'))
        add_dict = request.form.to_dict()
        add_dict['event_id'] = event_id
    except:
        raise InvalidArgument()

    ScoreboardService.edit(scoreboard_id, add_dict)

    return jsonify_with_data(APIError.OK)
示例#25
0
def add_assist():

    try:
        event_id = request.args.get('event_id', type=int)
        player_id = request.form.get('player_id', type=int)
        assists = request.form.get('assists', type=int)
    except:
        raise InvalidArgument()

    TopassistService.add(event_id, player_id, assists)

    return jsonify_with_data(APIError.OK)
示例#26
0
def top_olympics_video(video_id):

    try:
        top = int(request.args.get('value'))
    except:
        raise InvalidArgument()

    value = bool(top)

    OGVideoService.top(video_id, top=value)

    return jsonify_with_data((200, 'OK'))
示例#27
0
def pin_event_news(news_id):

    try:
        pin = int(request.args.get('value'))
    except:
        raise InvalidArgument()

    value = bool(pin)

    EventNewsService.pin(news_id, pin=value)

    return jsonify_with_data((200, 'OK'))
示例#28
0
def add_channel_entrance():

    try:
        event_id = int(request.args.get('event_id'))
    except:
        raise InvalidArgument()

    title = request.form.get('title')
    brief = request.form.get('brief')
    target = request.form.get('target')
    display_order = SubPageService.count(event_id=event_id) + 1
    SubPageService.add(event_id, title, target, brief, display_order)

    return jsonify_with_data((200, 'OK'))
示例#29
0
def sort_new_channel():

    try:
        channel_id = int(request.form.get('id'))
        current = int(request.form.get('current'))
        final = int(request.form.get('final'))
    except:
        raise InvalidArgument()

    try:
        NewChannelService.sort(channel_id, current, final)
    except:
        raise ServerError()

    return jsonify_with_data(APIError.OK)
示例#30
0
def edit_program(program_id):

    program = ProgramService.get_one(program_id)
    if request.method == 'GET':
        return render_template('admin/program/edit.html', program=program)

    title = request.form.get('title')
    display_order = int(request.form.get('display_order', 0))
    if display_order == 0:
        count = ProgramService.count()
        display_order = count + 1

    ProgramService.edit(program_id, title, display_order)

    return jsonify_with_data(APIError.OK)
示例#31
0
def sort_channel_entrance():

    try:
        subpage_id = int(request.form.get('id'))
        current = int(request.form.get('current'))
        final = int(request.form.get('final'))
    except:
        raise InvalidArgument()

    try:
        SubPageService.sort(subpage_id, current, final)
    except:
        raise ServerError()

    return jsonify_with_data(APIError.OK)
示例#32
0
def add_player():

    add_dict = request.form.to_dict()
    if add_dict['height']:
        height = int(add_dict['height'])
    else:
        height = 0
    if add_dict['weight']:
        weight = int(add_dict['weight'])
    else:
        weight = 0
    add_dict['height'] = height
    add_dict['weight'] = weight
    PlayerService.add(add_dict)
    return jsonify_with_data(APIError.OK)
示例#33
0
def add_lives():

    if request.method == 'GET':
        return render_template('admin/event/schedule_list.html')

    live_str = request.form.to_dict()['data']
    live_dict = eval(live_str)
    match_id = int(live_dict['id'])

    # delete the lives
    def delete_live(lives):
        MatchLiveService.delete(lives['id'])
        return True

    match_lives = MatchLiveService.get_all(match_id)
    match_delete= map(delete_live, match_lives)

    lives = live_dict['allSources']

    for live in lives:
        try:
            stream_time = live['stream_time']
            if stream_time:
                resault= re.search('/', stream_time)
                if resault:
                    tmp = time.strptime(live['stream_time'], "%Y/%m/%d %H:%M")
                    live['stream_time'] = time.strftime("%Y-%m-%d %H:%M:%S", tmp)
        except:
            raise InvalidArgument()
        live['match_id'] = int(live_dict['id'])
        live['site'] = live['sourcesName']
        live['play_url'] = live['sourcesUrl']
        live['play_code'] = live['playCode']
        live['feed_code'] = live['feedCode']
        live['play_html'] = live['playHtml']
        del(live['sourcesName'])
        del(live['sourcesUrl'])
        del(live['playCode'])
        del(live['feedCode'])
        del(live['playHtml'])

    # get match info
    def add_match_info(lives):
        MatchLiveService.add_dict(lives)
        return True
    matches = map(add_match_info, lives)

    return jsonify_with_data((200, 'OK'))
示例#34
0
def add_program():

    if request.method == 'GET':
        return render_template('admin/program/add.html')

    try:
        title = request.form.get('title')
        display_order = int(request.form.get('display_order', 0))
        if display_order == 0:
            count = ProgramService.count()
            display_order = count + 1
    except:
        raise InvalidArgument()

    ProgramService.add(title, display_order)

    return jsonify_with_data(APIError.OK)
示例#35
0
def comments_count(post_id):
    comments_count = CommentService.get_comments_count(post_id)

    return jsonify_with_data(APIError.OK, comments_count=comments_count)
示例#36
0
def get_post(post_id):
    post = PostService.get_one(post_id)
    if post is None:
        return jsonify_with_error(APIError.NOT_FOUNT)
    return jsonify_with_data(APIError.OK, post=post)