Exemple #1
0
def search(request):
    data = []
    ab = ArticleBase()

    title = request.REQUEST.get('title')

    objs = []
    if title:
        objs = ab.get_article_by_title(title)
    else:
        objs = ab.get_all_articles(state=None)

    page_index = int(request.REQUEST.get('page_index'))

    page_objs = page.Cpt(objs, count=10, page=page_index).info

    # 格式化json
    num = 10 * (page_index - 1)
    data = format_article(page_objs[0], num)

    return HttpResponse(json.dumps({
        'data': data,
        'page_count': page_objs[4],
        'total_count': page_objs[5]
    }),
                        mimetype='application/json')
Exemple #2
0
def get_article_by_id(request):
    article_id = request.REQUEST.get('article_id')

    obj = ArticleBase().get_article_by_id(article_id, need_state=False)

    data = format_article([obj], 1)[0]
    return HttpResponse(json.dumps(data), mimetype='application/json')
Exemple #3
0
def toutiao_hotest_articles(context):
    """
    @note: 头条最新热榜
    """
    from www.toutiao.interface import ArticleBase
    articles = ArticleBase().get_hotest_articles()[:10]

    return render_to_response('toutiao/_toutiao_hotest_articles.html', locals(), context_instance=context).content
Exemple #4
0
def add_article(request):
    title = request.REQUEST.get('title')
    content = request.REQUEST.get('content')
    city_id = request.REQUEST.get('belong_city')
    department_id = request.REQUEST.get('belong_department')
    sort_num = request.REQUEST.get('sort')

    # 如果设置了营业部,则使用营业部所属城市
    if department_id:
        city_id = DepartmentBase().get_department_by_id(department_id).city.id

    code, obj = ArticleBase().add_article(title, content, city_id,
                                          department_id, sort_num)

    return code, obj.id if code == 0 else ''
Exemple #5
0
def search(request):
    data = []
    ab = ArticleBase()

    title = request.REQUEST.get('title')

    objs = []
    if title:
        objs = ab.get_article_by_title(title)
    else:
        objs = ab.get_all_articles(state=None)

    page_index = int(request.REQUEST.get('page_index'))

    page_objs = page.Cpt(objs, count=10, page=page_index).info

    # 格式化json
    num = 10 * (page_index - 1)
    data = format_article(page_objs[0], num)

    return HttpResponse(
        json.dumps({'data': data, 'page_count': page_objs[4], 'total_count': page_objs[5]}),
        mimetype='application/json'
    )
Exemple #6
0
def latest_article(context):
    """
    @note: 最新资讯
    """
    import re
    from common import utils
    from www.kaihu.interface import ArticleBase, CityBase

    city_abbr = utils.get_sub_domain_from_http_host(context['request'].META.get('HTTP_HOST', ''))
    city = CityBase().get_city_by_pinyin_abbr(city_abbr)

    path = context['request'].path
    p = re.compile(u'\/kaihu/article\/?\d*', re.I)
    ps = dict(city_id=city.id)
    if p.findall(path):
        ps.update(dict(order_by="?"))
    articles = ArticleBase().get_articles_by_city_id(**ps)[:10]

    return render_to_response('kaihu/_latest_article.html', locals(), context_instance=context).content
Exemple #7
0
def modify_article(request):

    article_id = request.REQUEST.get('article_id')

    title = request.REQUEST.get('title')
    content = request.REQUEST.get('content')
    city_id = request.REQUEST.get('belong_city')
    department_id = request.REQUEST.get('belong_department')
    sort_num = request.REQUEST.get('sort')

    # 如果设置了营业部,则使用营业部所属城市
    if department_id:
        city_id = DepartmentBase().get_department_by_id(department_id).city.id

    return ArticleBase().modify_article(article_id,
                                        title=title,
                                        content=content,
                                        city_id=city_id,
                                        department_id=department_id,
                                        sort_num=sort_num)
Exemple #8
0
def remove_article(request):
    article_id = request.REQUEST.get('article_id')
    return ArticleBase().remove_article(article_id)