Ejemplo n.º 1
0
def list_olympics_news():

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

    try:
        type = request.args.get('type', 'all')
    except:
        raise InvalidArgument()

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

    if type == 'all':
        news_count = OGNewsService.count()
    else:
        news_count = OGNewsService.count(type=type)

    pagination = Pagination(page, count, news_count)

    def add_info_sync(news):
        value = EventNewsService.search_by_title(news['title'])
        news['sync'] = bool(value)
        return news

    news = map(add_info_sync, news)

    return render_template(
        'admin/olympics/news/news_list.html',
        news=news,
        pagination=pagination,
        type=type)
Ejemplo n.º 2
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'))
Ejemplo n.º 3
0
def edit_olympics_news(news_id):

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

    type = request.form.get('type')
    title = request.form.get('title')
    subtitle = request.form.get('subtitle')
    content = request.form.get('content')
    image = request.form.get('cover')

    OGNewsService.edit(news_id, type, title, subtitle, content, image)

    return redirect(url_for('admin.list_olympics_news'))
Ejemplo n.º 4
0
def add_olympics_news():

    if request.method == 'GET':
        sites = MatchNewsService.get_sites()
        return render_template(
            'admin/olympics/news/news_add.html', sites=sites)

    try:
        type = request.form.get('type')
        title = request.form.get('title')
        site = request.form.get('site')
        subtitle = request.form.get('subtitle')
        content = request.form.get('content')
        image = request.form.get('cover')
    except:
        raise InvalidArgument()

    OGNewsService.add(type, title, subtitle, content, image, site)

    return redirect(url_for('admin.list_olympics_news'))
Ejemplo n.º 5
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'))
Ejemplo n.º 6
0
def hide_olympics_news(news_id):
    OGNewsService.hide(news_id)
    return jsonify_with_data((200, 'OK'))
Ejemplo n.º 7
0
def show_olympics_news(news_id):
    OGNewsService.show(news_id)
    return jsonify_with_data((200, 'OK'))
Ejemplo n.º 8
0
def delete_olympics_news(news_id):
    OGNewsService.delete(news_id)
    return jsonify_with_data((200, 'OK'))