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

    name = request.form.get('name')
    type = request.form.get('type')
    brief = request.form.get('brief')

    ChannelService.add(name, type, brief)

    return redirect(url_for('admin.list_channels'))
def edit_channel(channel_id):

    channel = ChannelService.get_one(channel_id)
    if request.method == 'GET':
        return render_template('admin/channel/edit.html', channel=channel)

    name = request.form.get('name')
    type = request.form.get('type')
    brief = request.form.get('brief')

    ChannelService.edit(channel_id, name, type, brief)

    return redirect(url_for('admin.list_channels'))
def edit_web_slide(slide_id):
    channel_id = int(request.args.get('channel_id', 0))
    channels = ChannelService.get_shown_all()
    slide = SlideService.get_one(slide_id)
    if request.method == 'GET':
        return render_template('admin/slide/edit_web.html',
                               slide=slide,
                               channel_id=channel_id,
                               channels=channels)

    slide_dict = request.form.to_dict()
    if not slide_dict['bgcolor']:
        slide_dict['bgcolor'] = "#000000"
    slide_dict['target_id'] = 0
    display_order = slide_dict['display_order'] or 0
    slide_dict['image'] = slide_dict['cover']
    if slide_dict.has_key("covermin"):
        slide_dict['thumbnail'] = slide_dict['covermin']
        del (slide_dict['covermin'])
    slide_dict['display_order'] = display_order
    del (slide_dict['cover'])

    SlideService.edit(slide_id, slide_dict)

    return redirect(
        url_for('admin.list_slides', platform='web', channel_id=channel_id))
def add_web_slide():
    channel_id = int(request.args.get('channel_id', 0))
    channels = ChannelService.get_shown_all()
    if request.method == 'GET':
        return render_template('admin/slide/add_web.html',
                               channel_id=channel_id,
                               channels=channels)

    platform = request.args.get('platform', 'web')
    slide_dict = request.form.to_dict()

    slide_dict['target_id'] = 0
    if not slide_dict['display_order']:
        slide_dict['display_order'] = 0
    slide_dict['image'] = slide_dict['cover']
    if slide_dict.has_key("covermin"):
        slide_dict['thumbnail'] = slide_dict['covermin']
        del (slide_dict['covermin'])
    slide_dict['platform'] = platform
    del (slide_dict['cover'])

    SlideService.add(slide_dict)

    return redirect(
        url_for('admin.list_slides', platform=platform, channel_id=channel_id))
def list_new_channels():

    if request.method == 'GET':
        channels = NewChannelService.get_filter_all()
        events = ChannelService.get_all()
        eventsName = {}
        for item in events:
            eventsName[item['id']] = item['name']

        return render_template('admin/channel/channel_list.html',
                               eventName=eventsName,
                               events=events,
                               channels=channels)

    name = request.form.get('name')
    alias = request.form.get('alias')
    type = request.form.get('type')
    platform = request.form.get('platform')
    ref_id = request.form.get('ref_id', 0, type=int)

    # desplay order inc
    display_order = NewChannelService.count() + 1

    NewChannelService.add(name, alias, type, platform, ref_id, display_order)

    return redirect(url_for('admin.list_new_channels'))
Beispiel #6
0
def list_activitys():

    page = request.args.get('page', 1, type=int)
    count = request.args.get('count', 20, type=int)

    events = ChannelService.get_all()
    activitys = ActivityService.get_all((page - 1) * count, count)

    activity_count = ActivityService.count()

    pagination = Pagination(page, count, activity_count)

    return render_template('admin/activity/list.html',
                           events=events,
                           activitys=activitys,
                           pagination=pagination)
def mainboard_add_slide():
    channels = ChannelService.get_shown_all()
    if request.method == 'GET':
        return render_template('admin/mainboard/slide/add.html',
                               channels=channels)
    obj_dict = request.form.to_dict()
    if not obj_dict['position']:
        obj_dict['position'] = 0
    obj_dict['image'] = obj_dict['cover']
    obj_dict['large_image'] = obj_dict['cover_large']
    if any(obj_dict['ref_id']) == False:
        obj_dict['ref_id'] = 0
    del (obj_dict['cover'])
    del (obj_dict['cover_large'])
    MainBoardSlideService.add(obj_dict)
    return redirect(url_for('admin.mainboard_list_slides'))
Beispiel #8
0
def list_league_scoreboards():

    events = ChannelService.get_cups(iscup=0)

    if events:
        default_id = events[1]['id']
    else:
        return render_template('admin/scoreboard/league_list.html',
                               groups=[],
                               events=events)

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

    teams = EventTeamService.get_all(event_id=event_id)

    def get_selected_team(group):
        team_info = TeamService.get_one(group['team_id'])
        if team_info:
            group['name'] = team_info['name']
        return group

    teams = map(get_selected_team, teams)

    scoreboard_teams = ScoreboardService.get_all(event_id=event_id)

    def get_group_info(num, group):
        group['ranking'] = num
        group['section'] = group['wins'] + group['draws'] + group['loses']
        team_info = TeamService.get_one(group['team_id'])
        if team_info:
            group['team_name'] = team_info['name']
            group['team_badge'] = team_info['badge']
        return group

    groups = [
        get_group_info(num + 1, group)
        for num, group in enumerate(scoreboard_teams)
    ]

    return render_template('admin/scoreboard/league_list.html',
                           groups=groups,
                           teams=teams,
                           event_id=event_id,
                           events=events)
Beispiel #9
0
def list_topassist():

    events = ChannelService.get_all(type='football')

    if events:
        default_id = events[1]['id']

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

    scorers = TopassistService.get_all(event_id)

    def get_info(num, scorer):

        if scorer['player_id']:
            player = PlayerService.get_one(scorer['player_id'])
            scorer['player_photo'] = player['photo']
            scorer['player_name'] = player['name']
        team_info = TeamPlayerService.get_filter_one(scorer['player_id'])
        if team_info:
            scorer['team_id'] = team_info['team_id']
            team = TeamService.get_one(team_info['team_id'])
            if team:
                scorer['team_name'] = team['name']
        scorer['ranking'] = num

        return scorer

    scorers = [get_info(num + 1, scorer) for num, scorer in enumerate(scorers)]

    teams = EventTeamService.get_all(event_id)

    def get_team_info(team):
        team = TeamService.get_one(team['team_id'])
        team['name'] = team['name']
        return team

    teams = map(get_team_info, teams)

    return render_template('admin/scoreboard/list_assists.html',
                           events=events,
                           datas=scorers,
                           teams=teams,
                           event_id=event_id)
def mainboard_list_slides():
    platform = request.args.get('platform', 'app')

    channel_id = int(request.args.get('channel_id', 0))

    slides = MainBoardSlideService.get_all()

    if channel_id == 0:
        slides = MainBoardSlideService.get_all(channel_id=channel_id)

    if channel_id:
        slides = MainBoardSlideService.get_all(channel_id=channel_id)

    channels = ChannelService.get_all(type='football')

    return render_template('admin/mainboard/slide/list.html',
                           slides=slides,
                           channel_id=channel_id,
                           channels=channels)
def channel_entrance():

    # True is all and mobile
    events = ChannelService.get_all(type='football')

    if events:
        default_id = events[1]['id']
    else:
        return render_template('admin/scoreboard/cup_list.html', pages=[])

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

    pages = SubPageService.get_all(event_id=event_id)

    return render_template('admin/channel/channel_entrance.html',
                           events=events,
                           event_id=event_id,
                           pages=pages)
def edit_slide(slide_id):
    channels = ChannelService.get_shown_all()
    slide = SlideService.get_one(slide_id)
    if request.method == 'GET':
        return render_template('admin/slide/edit.html',
                               slide=slide,
                               channels=channels)

    slide_dict = request.form.to_dict()
    if slide_dict['type'] == "ad":
        slide_dict['target_id'] = 0
    elif slide_dict['type'] == 'html':
        slide_dict['target_id'] = 0
    else:
        slide_dict['target_id'] = int(slide_dict['target_id'])
    slide_dict['image'] = slide_dict['cover']
    slide_dict['display_order'] = int(slide_dict['display_order'])
    del (slide_dict['cover'])

    SlideService.edit(slide_id, slide_dict)

    return redirect(url_for('admin.list_slides', platform='app'))
def add_slide():
    channels = ChannelService.get_shown_all()
    if request.method == 'GET':
        return render_template('admin/slide/add.html', channels=channels)

    platform = request.args.get('platform', 'app')
    slide_dict = request.form.to_dict()

    if slide_dict['type'] == "ad":
        slide_dict['target_id'] = 0
    elif slide_dict['type'] == 'html':
        slide_dict['target_id'] = 0
    else:
        slide_dict['target_id'] = int(slide_dict['target_id'])
    if not slide_dict['display_order']:
        slide_dict['display_order'] = 0
    slide_dict['image'] = slide_dict['cover']
    slide_dict['platform'] = platform
    del (slide_dict['cover'])

    SlideService.add(slide_dict)

    return redirect(url_for('admin.list_slides', platform=platform))
def delete_channel(channel_id):
    ChannelService.delete(channel_id)
    return jsonify_with_data((200, 'OK'))
def hide_channel(channel_id):
    ChannelService.hide(channel_id)
    return jsonify_with_data((200, 'OK'))
def show_channel(channel_id):
    ChannelService.show(channel_id)
    return jsonify_with_data((200, 'OK'))
def relate_resource(resource_id):

    resource = PendingVideoService.get_one(resource_id)
    tmp = json.loads(resource['data'])
    if request.method == 'GET':
        if tmp['tags']:
            tags = list(set(tmp['tags']))
            lable = [s.split(';')[1] for s in tags]
        else:
            lable = []
        resource['lable'] = '/'.join(lable)
        events = ChannelService.get_all(type='football')
        programs = ProgramService.get_simple_all()

        return render_template('admin/media/relate.html',
                               events=events,
                               programs=programs,
                               resource=resource)

    type = request.form.get('type')
    isvr = request.form.get('isvr', 0, int)

    args_dict = {}
    args_dict['cid'] = tmp['cid']
    args_dict['size'] = tmp['size']
    args_dict = json.dumps(args_dict)

    if type == 'event_video':
        event_id = int(request.form.get('event_id'))
        # add to eventnews table
        EventNewsService.add(event_id, 'video', 'bfonline', '暴风体育',
                             tmp['title'], isvr, tmp['image'], '',
                             tmp['play_code'], tmp['play_code'], '', '',
                             args_dict, resource['created_at'])
    elif type == 'program':
        program_id = request.form.get('program_id')
        # add to program post table
        ProgramPostService.add(program_id, tmp['title'], isvr, 'bfonline',
                               '暴风体育', '', tmp['image'], '', tmp['play_code'],
                               tmp['play_code'], resource['created_at'],
                               args_dict)
    elif type == 'olympic':
        OGVideoService.add(tmp['title'], isvr, 'highlight', 'bfonline',
                           tmp['duration'], tmp['image'], '', tmp['play_code'],
                           args_dict, resource['created_at'])
    else:
        try:
            match_id = request.form.get('match_id')
        except:
            raise InvalidArgument()

        match = MatchService.get_one(match_id)
        if not match:
            raise NotFound()

        if type == 'match_video':
            MatchNewsService.add(match_id, 'video', 'bfonline', '暴风体育',
                                 tmp['title'], isvr, tmp['image'], '',
                                 tmp['play_code'], tmp['play_code'], '', '',
                                 args_dict, resource['created_at'])
        else:
            MatchVideoService.add(match_id, tmp['title'], isvr, type,
                                  'bfonline', tmp['duration'], tmp['image'],
                                  '', tmp['play_code'], tmp['play_code'],
                                  args_dict, resource['created_at'])

    PendingVideoService.relate(resource_id)

    return redirect(url_for('admin.list_resources'))
Beispiel #18
0
def list_cup_scoreboards():

    group_list = ['A', 'B', 'C', 'D', 'E', 'F']

    events = ChannelService.get_cups(iscup=1)

    if events:
        default_id = events[0]['id']
    else:
        return render_template('admin/scoreboard/cup_list.html',
                               groups=[],
                               events=events)

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

    teams = EventTeamService.get_all(event_id=event_id)

    def get_selected_team(group):
        team_info = TeamService.get_one(group['team_id'])
        if team_info:
            group['name'] = team_info['name']
        return group

    teams = map(get_selected_team, teams)

    team_groups = EventTeamService.get_all(event_id)

    def get_team_info(group):
        team_info = TeamService.get_one(group['team_id'])
        if team_info:
            group['team_name'] = team_info['name']
            group['team_badge'] = team_info['badge']

        score = ScoreboardService.get_filter_one(group['event_id'],
                                                 group['team_id'])
        if score:
            group['id'] = score['id']
            group['wins'] = score['wins']
            group['draws'] = score['draws']
            group['loses'] = score['loses']
            group['goals_differential'] = score['goals_differential']
            group['points'] = score['points']
            group['section'] = group['wins'] + group['draws'] + group['loses']

        return group

    team_groups = map(get_team_info, team_groups)

    groups = defaultdict(list)

    for item in team_groups:
        groups[item["group"]].append(item)

    count_len = len(groups.keys())

    group_list[0:count_len]

    # sort points
    for key in group_list:
        if groups[key]:
            for item in groups[key]:
                if 'points' in item.keys():
                    groups[key].sort(key=operator.itemgetter('points'),
                                     reverse=True)
                else:
                    item['points'] = 0

    return render_template('admin/scoreboard/cup_list.html',
                           groups=groups,
                           group_list=group_list,
                           teams=teams,
                           event_id=event_id,
                           events=events)
def list_channels():
    channels = ChannelService.get_shown_all()
    return render_template('admin/channel/list.html', channels=channels)
Beispiel #20
0
def layout_side():
    channels = ChannelService.get_all()
    return render_template('admin/side.html', channels=channels)