def add_event_news():

    redirect_url = request.args.get('redirect', '')
    event_id = request.args.get('event_id')
    if request.method == 'GET':
        sites = EventNewsService.get_sites()
        return render_template('admin/event/news_add.html',
                               sites=sites,
                               event_id=event_id,
                               url=redirect_url)

    eid = request.form.get('event_id', type=int)
    type = request.form.get('type')
    source = request.form.get('site')
    source_name = request.form.get('site_name')
    title = request.form.get('title')
    image = request.form.get('cover')
    play_url = request.form.get('play_url', '')
    subtitle = request.form.get('subtitle')
    content = request.form.get('content')

    EventNewsService.add(eid, type, source, source_name, title, image,
                         play_url, subtitle, content)

    return redirect(url_for('admin.list_event_news'))
def edit_event_news(news_id):

    redirect_url = request.args.get('redirect', '')

    if request.method == 'GET':
        sites = EventNewsService.get_sites()
        news = EventNewsService.get_one(news_id).to_dict()
        return render_template('admin/event/news_edit.html',
                               sites=sites,
                               news=news)

    eid = request.form.get('event_id', type=int)
    type = request.form.get('type')
    source = request.form.get('site')
    source_name = request.form.get('site_name')
    title = request.form.get('title')
    image = request.form.get('cover')
    play_url = request.form.get('play_url', '')
    subtitle = request.form.get('subtitle')
    content = request.form.get('content')

    EventNewsService.edit(news_id, eid, type, source, source_name, title,
                          image, play_url, subtitle, content)

    if redirect_url == '':
        return redirect(url_for('admin.list_event_news'))
    else:
        return redirect(redirect_url)
Exemple #3
0
def add_event_news():

    redirect_url = request.args.get('redirect', '')
    event_id = request.args.get('event_id')
    if request.method == 'GET':
        sites = EventNewsService.get_sites()
        return render_template(
            'admin/event/news_add.html', sites=sites, event_id=event_id, url=redirect_url)

    try:
        eid = int(request.form.get('event_id'))
        type = request.form.get('type')
        source = request.form.get('site')
        source_name = request.form.get('site_name')
        title = request.form.get('title')
        isvr = request.form.get('isvr', 0, int)
        image = request.form.get('cover')
        play_url = request.form.get('play_url', '')
        play_code = request.form.get('play_code', '')
        play_html = request.form.get('play_html', '')
        subtitle = request.form.get('subtitle')
        content = request.form.get('content')
    except:
        raise InvalidArgument()

    EventNewsService.add(
        eid, type, source, source_name, title, isvr,
        image, play_url, play_code, play_html, subtitle, content)

    return redirect(url_for('admin.list_event_news', event_id=event_id))
def list_event_news():

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

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

    if request.method == 'POST':
        search_id = request.form.get('search')
        return redirect(
            url_for('admin.list_event_news', event_id=search_id, type=type))

    news = EventNewsService.get_all(event_id, type, (page - 1) * count, count)

    if event_id and type:
        news_count = EventNewsService.count(event_id, type=type)
    elif event_id:
        news_count = EventNewsService.count(event_id)
    elif type:
        news_count = EventNewsService.count(type=type)
    else:
        news_count = EventNewsService.count()

    pagination = Pagination(page, count, news_count)

    return render_template('admin/event/news_list.html',
                           news=news,
                           pagination=pagination,
                           current_id=event_id,
                           current_type=type,
                           url=request.url)
Exemple #5
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'))
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'))
Exemple #7
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'))
Exemple #8
0
def sync_olympics_news(news_id):

    news = OGNewsService.get_one(news_id)
    try:
        event_id = 14
        EventNewsService.add(
            event_id, 'literal', news.site, '',
            news.title, 0, news.image, '', '',
            '', news.subtitle, news.content, '', news.created_at)
    except:
        raise InvalidArgument()

    return redirect(url_for('admin.list_olympics_news'))
def delete_event_news(news_id):
    EventNewsService.delete(news_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'))
Exemple #11
0
 def add_info_sync(news):
     value = EventNewsService.search_by_title(news['title'])
     news['sync'] = bool(value)
     return news
Exemple #12
0
def hide_event_news(news_id):
    EventNewsService.hide(news_id)
    return jsonify_with_data((200, 'OK'))
Exemple #13
0
def show_event_news(news_id):
    EventNewsService.show(news_id)
    return jsonify_with_data((200, 'OK'))