Ejemplo n.º 1
0
def news_list():

    pg = int(request.args.get('pg', 1))
    num = int(request.args.get('num', 6))
    lang = request.args.get('lang', 'zh')

    res_type = 'news'

    bb_cli = BigbroCache()

    start_ = (pg - 1) * num
    end_ = start_ + num

    ne_li = bb_cli.get_resource_list(res_type=res_type, lang=lang)

    rst = []
    for ne_id in ne_li:

        slz = {}
        ne = bb_cli.get_resource(res_type=res_type, res_id=ne_id)
        if not ne or ne['online'] != 'on':
            continue

        slz['news_id'] = ne['res_id']
        slz['ndate'] = ne['content']['ndate']
        slz['ntitle'] = ne['content']['ntitle']
        slz['nsubtitle'] = ne['content']['nsubtitle']
        slz['ncover'] = ne['content']['ncover']

        rst.append(slz)

    tpg = int(ceil(len(rst) / 6.0))

    return json.dumps({'news_li': rst[start_:end_], 'total_pg': tpg, 'pg': pg})
Ejemplo n.º 2
0
def movie_recommend():

    bb_cli = BigbroCache()
    res_type = 'movie'
    lang = request.args.get('lang', 'zh')

    mid = bb_cli.get_recommend_movie(lang)
    if not mid:
        return '{}'

    mc = bb_cli.get_resource(res_type=res_type, res_id=mid)
    if not mc or mc['online'] == 'off':
        return '{}'

    return json.dumps({
        'title': mc['content']['title'],
        'director': mc['content']['director'],
        'writer': mc['content']['writer'],
        'poster': mc['content']['pmajor'],
        'release_date': mc['content']['release_date'],
        'release_vision': mc['content']['release_vision'],
        'stars': mc['content']['stars'],
        'lang': mc['content']['lang'],
        'duration': mc['content']['duration'],
        'country': mc['content']['country'],
        'genre': mc['content']['genre'],
        'producer': mc['content']['producer'],
        'movie_id': mc['res_id']
    })
Ejemplo n.º 3
0
def friend_list():

    # pg = int(request.args.get('pg', 1))
    # num = int(request.args.get('num', 10))

    res_type = 'webroll'

    bb_cli = BigbroCache()

    # start_ = (pg - 1) * num
    # end_ = start_ + num

    r_li = bb_cli.get_resource_list(res_type=res_type)

    rst = []
    for r_id in r_li:

        slz = {}
        rc = bb_cli.get_resource(res_type=res_type, res_id=r_id)
        if not rc or rc['online'] != 'on':
            continue

        # slz['friend_id'] = rc['res_id']
        for k in webroll_keys:
            slz[k] = rc['content'][k]

        rst.append(slz)

    rst.sort(key=lambda r: r['rrank'])

    return json.dumps({'friend_li': rst})
Ejemplo n.º 4
0
def project_unit(project_id):

    bb_cli = BigbroCache()
    res_type = 'project'

    p_ids = bb_cli.get_resource_list(res_type=res_type)

    rst = {}
    this_ix = p_ids.index(project_id)
    rst['pre_id'] = p_ids[this_ix - 1] if this_ix > 0 else ''
    rst['next_id'] = p_ids[this_ix + 1] if this_ix < len(p_ids) - 1 else ''

    if rst['next_id']:
        next_pc = bb_cli.get_resource(res_type, rst['next_id'])
        if next_pc['online'] == 'off':
            rst['next_id'] = ''

    pc = bb_cli.get_resource(res_type=res_type, res_id=project_id)
    if not pc:
        rst['cnt'] = '<h1>nothing</h1>'
        rst['ptitle'] = 'nothing'
        rst['psubtitle'] = 'nothing'
    else:
        for k in project_keys:
            rst[k] = pc['content'][k]

    return json.dumps(rst)
Ejemplo n.º 5
0
def banner_edit(res_id):

    res_tp = 'banner'

    bb_cli = BigbroCache()
    bc = bb_cli.get_resource(res_type=res_tp, res_id=res_id)

    if request.method == 'GET':

        slz = {}
        slz['res_id'] = bc['res_id']
        for k in banner_keys:
            slz[k] = bc['content'][k]

        return render_template('banner_edit.html', b=slz)

    pre_cover = bc['content']['bcover']

    for k in banner_keys:
        bc['content'][k] = request.form[k]
    bc['bb'] = request.username

    if pre_cover and pre_cover != bc['content']['bcover']:
        delete_resource(pre_cover)

    bb_cli.update_resource(bc)

    Resources.update_up(res_tp=res_tp,
                        res_id=res_id,
                        content=bc['content'],
                        update_bb=request.username)

    return render_template('banner_create.html')
Ejemplo n.º 6
0
def news_edit(res_id):

    res_tp = 'news'

    bb_cli = BigbroCache()
    nc = bb_cli.get_resource(res_type=res_tp, res_id=res_id)

    if request.method == 'GET':

        slz = {}
        slz['res_id'] = nc['res_id']
        for k in news_keys:
            slz[k] = nc['content'][k]

        return render_template('news_edit.html', news=slz)

    pre_cover = nc['content']['ncover']

    cnt = {}
    for k in news_keys:
        cnt[k] = request.form[k]

    nc['content'] = cnt
    nc['bb'] = request.username
    bb_cli.update_resource(nc)

    Resources.update_up(res_tp=res_tp,
                        res_id=res_id,
                        content=cnt,
                        update_bb=request.username)

    if pre_cover and pre_cover != nc['content']['ncover']:
        delete_resource(pre_cover)

    return render_template('news_create.html')
Ejemplo n.º 7
0
def project_edit(res_id):

    res_tp = 'project'

    bb_cli = BigbroCache()
    pc = bb_cli.get_resource(res_type=res_tp, res_id=res_id)

    if request.method == 'GET':

        slz = {}
        slz['res_id'] = pc['res_id']
        for k in project_keys:
            slz[k] = pc['content'][k]

        return render_template('project_edit.html', project=slz)

    pre_cover = pc['content']['pcover']

    cnt = {}
    for k in project_keys:
        cnt[k] = request.form[k]

    pc['content'] = cnt
    pc['bb'] = request.username
    bb_cli.update_resource(pc)

    if pre_cover and pre_cover != pc['content']['pcover']:
        delete_resource(pre_cover)

    return render_template('project_create.html')
Ejemplo n.º 8
0
def news_unit(news_id):

    bb_cli = BigbroCache()
    res_type = 'news'

    # n_ids = bb_cli.get_resource_list(res_type=res_type)

    rst = {}
    # this_ix = n_ids.index(news_id)
    # rst['pre_id'] = n_ids[this_ix-1] if this_ix > 0 else ''
    # rst['next_id'] = n_ids[this_ix+1] if this_ix < len(n_ids) - 1 else ''

    # if rst['next_id']:
    #    next_nc = bb_cli.get_resource(res_type, rst['next_id'])
    #    if next_nc['online'] == 'off':
    #        rst['next_id'] = ''

    nc = bb_cli.get_resource(res_type=res_type, res_id=news_id)
    if not nc:
        rst['cnt'] = '<h1>nothing</h1>'
        rst['ntitle'] = 'nothing'
        rst['nsubtitle'] = 'nothing'
    else:
        for k in news_keys:
            rst[k] = nc['content'][k]

    return json.dumps(rst)
Ejemplo n.º 9
0
def webroll_edit(res_id):

    res_tp = 'webroll'

    bb_cli = BigbroCache()
    rc = bb_cli.get_resource(res_type=res_tp, res_id=res_id)

    if request.method == 'GET':

        slz = {}
        slz['res_id'] = rc['res_id']
        for k in webroll_keys:
            slz[k] = rc['content'].get(k, 50)

        return render_template('webroll_edit.html', r=slz)

    pre_logo = rc['content']['rlogo']

    for k in webroll_keys:
        rc['content'][k] = request.form[k]
    rc['bb'] = request.username

    if pre_logo and pre_logo != rc['content']['rlogo']:
        delete_resource(pre_logo)

    bb_cli.update_resource(rc)

    Resources.update_up(res_tp=res_tp,
                        res_id=res_id,
                        content=rc['content'],
                        update_bb=request.username)

    # return render_template('webroll_create.html')

    return redirect(url_for('.webrolls'))
Ejemplo n.º 10
0
def movie_unit(movie_id):

    bb_cli = BigbroCache()
    res_type = 'movie'
    # lang = request.args.get('lang', 'zh')

    # m_ids = bb_cli.get_resource_list(res_type=res_type, lang=lang)

    rst = {}
    # this_ix = m_ids.index(movie_id)
    # rst['pre_id'] = m_ids[this_ix-1] if this_ix > 0 else ''
    # rst['next_id'] = m_ids[this_ix+1] if this_ix < len(m_ids) - 1 else ''

    # if rst['next_id']:
    #    next_mc = bb_cli.get_resource(res_type, rst['next_id'])
    #    if next_mc['online'] == 'off':
    #        rst['next_id'] = ''

    mc = bb_cli.get_resource(res_type=res_type, res_id=movie_id)
    if not mc:
        rst['title'] = 'nothing'
    else:
        for k in movie_keys:
            rst[k] = mc['content'].get(k, '')

    return json.dumps(rst)
Ejemplo n.º 11
0
def webroll():

    act = request.form.get('act')
    rid = request.form.get('rid')
    rtp = 'webroll'

    if not (act and rid):
        return 'thx_for_request_0'

    bb_cli = BigbroCache()
    rc = bb_cli.get_resource(res_type=rtp, res_id=rid)
    if not rc:
        return 'thx_for_request'

    if act in ['on', 'off']:
        rc['online'] = act
        bb_cli.update_resource(rc)
    elif act == 'fst':
        bb_cli.top_resource(res_type=rtp, res_id=rid)
    elif act == 'del':
        bb_cli.rem_resource_id(res_type=rtp, res_id=rid)
        Resources.bb_delete(res_tp=rtp, res_id=rid, update_bb=request.username)
        if rc['content']['rlogo']:
            delete_resource(rc['content']['rlogo'])

    return 'ok'
Ejemplo n.º 12
0
def news_unit():

    act = request.form.get('act')
    nid = request.form.get('nid')
    rtp = 'news'

    if not (act and nid):
        return 'thx_for_request_0'

    bb_cli = BigbroCache()
    nc = bb_cli.get_resource(res_type=rtp, res_id=nid)
    if not nc:
        return 'thx_for_request'

    if act in ['on', 'off']:
        nc['online'] = act
        bb_cli.update_resource(nc)
    elif act == 'fst':
        bb_cli.top_resource(res_type=rtp, res_id=nid)
    elif act == 'del':
        bb_cli.rem_resource_id(res_type=rtp, res_id=nid)
        Resources.bb_delete(res_tp=rtp, res_id=nid, update_bb=request.username)
        if nc['content']['ncover']:
            delete_resource(nc['content']['ncover'])

    return 'ok'
Ejemplo n.º 13
0
def project_unit():

    act = request.form.get('act')
    proid = request.form.get('proid')
    rtp = 'project'

    if not (act and proid):
        return 'thx_for_request_0'

    bb_cli = BigbroCache()
    pc = bb_cli.get_resource(res_type=rtp, res_id=proid)
    if not pc:
        return 'thx_for_request'

    if act in ['on', 'off']:
        pc['online'] = act
        bb_cli.update_resource(pc)
    elif act == 'fst':
        bb_cli.top_resource(res_type=rtp, res_id=proid)
    elif act == 'del':
        bb_cli.rem_resource_id(res_type=rtp, res_id=proid)
        Resources.bb_delete(res_tp=rtp,
                            res_id=proid,
                            update_bb=request.username)
        if pc['content']['pcover']:
            delete_resource(pc['content']['pcover'])

    return 'ok'
Ejemplo n.º 14
0
def banner():

    act = request.form.get('act')
    bid = request.form.get('bid')
    rtp = 'banner'

    if not (act and bid):
        return 'thx_for_request_0'

    bb_cli = BigbroCache()
    bc = bb_cli.get_resource(res_type=rtp, res_id=bid)
    if not bc:
        return 'thx_for_request'

    if act in ['on', 'off']:
        bc['online'] = act
        bb_cli.update_resource(bc)
    elif act == 'fst':
        bb_cli.top_resource(res_type=rtp, res_id=bid)
    elif act == 'del':
        bb_cli.rem_resource_id(res_type=rtp, res_id=bid)
        Resources.bb_delete(res_tp=rtp, res_id=bid, update_bb=request.username)
        if bc['content']['bcover']:
            delete_resource(bc['content']['bcover'])

    return 'ok'
Ejemplo n.º 15
0
def projects():

    bb_cli = BigbroCache()
    rtp = 'project'

    if request.method == 'POST':
        cnt = {}
        for k in project_keys:
            cnt[k] = request.form[k]

        r = Resources.create(res_tp=rtp,
                             content=json.dumps(cnt),
                             create_bb=request.username)

        bb_cli.update_resource({
            'res_tp': r.res_tp,
            'res_id': r.res_id,
            'content': cnt,
            'online': 'off',
            'bb': r.create_bb,
            'created': r.created
        })
        bb_cli.add_resource_id(res_type=r.res_tp, res_id=r.res_id)

        return render_template('project_create.html')

    pg = int(request.args.get('pg', 1))

    start_ = (pg - 1) * 10
    end_ = start_ + 10 - 1

    project_total = bb_cli.get_resource_len(res_type=rtp)
    total_pg = int(ceil(project_total / 10.0))

    p_ids = bb_cli.get_resource_list(res_type=rtp, start=start_, end=end_)

    rst = []
    for p_id in p_ids:
        slz = {}
        pc = bb_cli.get_resource(res_type=rtp, res_id=p_id)
        if not pc:
            continue

        slz['res_id'] = pc['res_id']
        slz['bb'] = pc['bb']
        slz['created'] = timestamp_to_strftime(pc['created'])
        slz['online'] = pc['online']
        slz['res_tp'] = ''
        for k in project_keys:
            slz[k] = pc['content'][k]

        rst.append(slz)

    return render_template('hh_projects_v11.html',
                           projects=rst,
                           project_total=project_total,
                           total_pg=total_pg,
                           pg=pg)
Ejemplo n.º 16
0
def webrolls():

    bb_cli = BigbroCache()
    rtp = 'webroll'

    if request.method == 'POST':
        cnt = {}
        for k in webroll_keys:
            cnt[k] = request.form[k]

        r = Resources.create(res_tp=rtp,
                             content=json.dumps(cnt),
                             create_bb=request.username)

        bb_cli.update_resource({
            'res_tp': r.res_tp,
            'res_id': r.res_id,
            'online': 'off',
            'bb': request.username,
            'content': cnt,
            'created': r.created
        })
        bb_cli.add_resource_id(res_type=r.res_tp, res_id=r.res_id)

        return render_template('webroll_create.html')

    pg = int(request.args.get('pg', 1))

    start_ = (pg - 1) * 20
    end_ = start_ + 20 - 1

    webroll_total = bb_cli.get_resource_len(res_type=rtp)
    total_pg = int(ceil(webroll_total / 20.0))

    r_ids = bb_cli.get_resource_list(res_type=rtp, start=start_, end=end_)

    rst = []
    for r_id in r_ids:
        slz = {}
        rc = bb_cli.get_resource(res_type=rtp, res_id=r_id)
        if not rc:
            continue

        slz['res_id'] = rc['res_id']
        slz['bb'] = rc['bb']
        slz['created'] = timestamp_to_strftime(rc['created'])
        slz['online'] = rc['online']
        for k in webroll_keys:
            slz[k] = rc['content'].get(k, 50)

        rst.append(slz)

    return render_template('hh_webrolls_v11.html',
                           webrolls=rst,
                           webroll_total=webroll_total,
                           total_pg=total_pg,
                           pg=pg)
Ejemplo n.º 17
0
def update_from_cache():

    bc_cli = BigbroCache()

    for r in Resources.query.yield_per(10):
        if r.deleted:
            continue
        bc = bc_cli.get_resource(res_type=r.res_tp, res_id=r.res_id)
        if not bc:
            continue
        r.content = json.dumps(bc['content'])
        r.update_bb = bc['bb']
        r.update()
        print r.id
Ejemplo n.º 18
0
def movie_edit(res_id):

    res_tp = 'movie'

    bb_cli = BigbroCache()
    mc = bb_cli.get_resource(res_type=res_tp, res_id=res_id)

    if request.method == 'GET':

        slz = {}
        slz['res_id'] = mc['res_id']
        for k in movie_keys:
            slz[k] = mc['content'].get(k, '')
        slz['mlang'] = mc['content'].get('mlang', 'zh')

        return render_template('movie_edit.html', movie=slz)

    pre_cover = mc['content'].get('mcover', '')
    pre_lang = mc['content'].get('mlang', 'zh')

    cnt = {}
    for k in movie_keys:
        if k == 'clips':
            cnt[k] = request.form.getlist('clips[]')
        elif k == 'posters':
            cnt[k] = request.form.getlist('posters[]')
        elif k == 'videos':
            v_links = request.form.getlist('vdo_links[]')
            v_covers = request.form.getlist('vdo_covers[]')
            v_titles = request.form.getlist('vdo_titles[]')
            cnt[k] = []
            for l, c, t in zip(v_links, v_covers, v_titles):
                cnt[k].append({'vlink': l, 'vcover': c, 'vtitle': t})
        else:
            cnt[k] = request.form[k]
    cnt['mlang'] = request.form.get('mlang', 'zh')

    mc['content'] = cnt
    mc['bb'] = request.username
    bb_cli.update_resource(mc)

    Resources.update_up(res_tp=res_tp,
                        res_id=res_id,
                        content=cnt,
                        update_bb=request.username)

    if pre_lang != mc['content']['mlang']:
        bb_cli.rem_id_from_list(res_tp, res_id, pre_lang)
        bb_cli.add_resource_id(res_tp, res_id, mc['content']['mlang'])

    if pre_cover and pre_cover != mc['content']['mcover']:
        delete_resource(pre_cover)

    return render_template('movie_create.html')
Ejemplo n.º 19
0
def banner_list():

    pg = int(request.args.get('pg', 1))
    num = int(request.args.get('num', 10))
    lang = request.args.get('lang', 'zh')

    res_type = 'banner'

    bb_cli = BigbroCache()

    start_ = (pg - 1) * num
    end_ = start_ + num

    b_li = bb_cli.get_resource_list(res_type=res_type)

    rst = []
    #     for b_id in b_li:

    #         slz = {}
    #         bc = bb_cli.get_resource(res_type=res_type, res_id=b_id)
    #         if not bc or bc['online'] != 'on':
    #             continue

    #         slz['banner_id'] = bc['res_id']
    #         for k in banner_keys:
    #             slz[k] = bc['content'][k]

    #         rst.append(slz)

    for mid in b_li:
        slz = {}
        mc = bb_cli.get_resource(res_type='movie', res_id=mid)
        if not mc or mc['online'] != 'on':
            continue
        if mc['content'].get('mlang', 'zh') != lang:
            continue

        slz['movie_id'] = mc['res_id']
        slz['mcover'] = mc['content']['mcover']
        slz['title'] = mc['content']['title']
        slz['description'] = mc['content']['description']
        slz['director'] = mc['content']['director']
        slz['writer'] = mc['content']['writer']
        slz['producer'] = mc['content']['producer']

        rst.append(slz)

    return json.dumps({'banner_li': rst[start_:end_]})
Ejemplo n.º 20
0
def login():

    if request.method == 'GET':
        return render_template('hh_login.html')

    username = request.form.get('username', None)
    password = request.form.get('password', None)
    if not username or not password:
        return render_template('hh_login.html')

    bbs = HEHE_BB_MANAGERS

    if username not in bbs:
        return render_template('hh_login.html')

    if bbs[username] != sha1(password).hexdigest():
        return render_template('hh_login.html')

    session['username'] = username

    BigbroCache().set_sign_info(username=username,
                                bb_ip=get_client_ip(request),
                                bb_agent=request.user_agent.string)

    return render_template('hh_home.html')
Ejemplo n.º 21
0
def about_me():

    lang = request.args.get('lang', 'zh')

    bb_cli = BigbroCache()
    res_type = 'about'

    a_ids = bb_cli.get_resource_list(res_type=res_type, lang=lang)

    rst = {}
    if a_ids:
        ac = bb_cli.get_resource(res_type=res_type, res_id=a_ids[0])
        for k in about_keys:
            rst[k] = ac['content'][k]
        rst['lang'] = ac['content'].get('lang', 'zh')

    return json.dumps(rst)
Ejemplo n.º 22
0
def movie_list():

    pg = int(request.args.get('pg', 1))
    num = int(request.args.get('num', 10))
    lang = request.args.get('lang', 'zh')

    res_type = 'movie'

    bb_cli = BigbroCache()

    start_ = (pg - 1) * num
    end_ = start_ + num

    m_li = bb_cli.get_resource_list(res_type=res_type, lang=lang)

    rst = []
    for m_id in m_li:

        slz = {}
        mc = bb_cli.get_resource(res_type=res_type, res_id=m_id)
        if not mc or mc['online'] != 'on':
            continue

        slz['movie_id'] = mc['res_id']
        slz['title'] = mc['content']['title']
        slz['description'] = mc['content']['description']
        slz['poster'] = mc['content']['pmajor']
        slz['release_date'] = mc['content']['release_date']
        slz['mcover'] = mc['content']['mcover']

        rst.append(slz)

    rst.sort(key=lambda m: m['release_date'], reverse=True)

    total_pg = int(ceil(len(rst) * 1.0 / num))

    return json.dumps({
        'movie_li': rst[start_:end_],
        'pg': pg,
        'total_pg': total_pg
    })
Ejemplo n.º 23
0
def movie_recommend():

    bb_cli = BigbroCache()
    rtp = 'movie'

    pg = int(request.args.get('pg', 1))

    movie_total = 0
    total_pg = 0

    m_id = bb_cli.get_recommend_movie()
    m_id_en = bb_cli.get_recommend_movie(lang='en')

    rst = []
    for mid in [m_id, m_id_en]:
        if not mid:
            continue
        movie_total += 1
        total_pg = 1
        mc = bb_cli.get_resource(res_type=rtp, res_id=mid)
        if mc and mc['online'] == 'on':
            slz = {}

            slz['res_id'] = mc['res_id']
            slz['bb'] = mc['bb']
            slz['created'] = timestamp_to_strftime(mc['created'])
            slz['online'] = mc['online']
            for k in movie_keys:
                slz[k] = mc['content'].get(k, '')

            slz['videos'] = mc['content']['videos']

            rst.append(slz)

    return render_template('movie_recommend.html',
                           movies=rst,
                           movie_total=movie_total,
                           total_pg=total_pg,
                           pg=pg)
Ejemplo n.º 24
0
def about_me(lang):

    rtp = 'about'
    bb_cli = BigbroCache()

    if request.method == 'POST':
        cnt = {}
        for k in about_keys:
            cnt[k] = request.form[k]
        cnt['lang'] = lang

        r = Resources.create(res_tp=rtp,
                             content=json.dumps(cnt),
                             create_bb=request.username)

        bb_cli.update_resource({
            'res_tp': r.res_tp,
            'res_id': r.res_id,
            'content': cnt,
            'bb': r.create_bb,
            'created': r.created
        })
        bb_cli.add_resource_id(res_type=r.res_tp, res_id=r.res_id, lang=lang)

        a = {
            'res_id': r.res_id,
            'bb': r.create_bb,
            'created': timestamp_to_strftime(r.created),
            'adetail': cnt['adetail'],
            'lang': lang
        }

        return render_template('hh_about.html', about=a)

    a_li = bb_cli.get_resource_list(res_type=rtp, lang=lang)
    if not a_li:
        return render_template('about_edit.html', about={'lang': lang})

    ac = bb_cli.get_resource(res_type=rtp, res_id=a_li[0])
    rst = {
        'res_id': ac['res_id'],
        'bb': ac['bb'],
        'created': timestamp_to_strftime(ac['created']),
        'adetail': ac['content']['adetail'],
        'lang': lang
    }

    return render_template('hh_about.html', about=rst)
Ejemplo n.º 25
0
def about_edit(res_id):

    res_tp = 'about'

    bb_cli = BigbroCache()
    ac = bb_cli.get_resource(res_type=res_tp, res_id=res_id)

    if request.method == 'GET':

        slz = {}
        slz['res_id'] = ac['res_id']
        for k in about_keys:
            slz[k] = ac['content'][k]

        return render_template('about_edit.html', about=slz)

    cnt = {}
    for k in about_keys:
        cnt[k] = request.form[k]

    cnt['lang'] = ac['content'].get('lang', 'zh')
    ac['content'] = cnt
    ac['bb'] = request.username
    bb_cli.update_resource(ac)

    Resources.update_up(res_tp=res_tp,
                        res_id=res_id,
                        content=cnt,
                        update_bb=request.username)

    a = {
        'res_id': ac['res_id'],
        'bb': ac['bb'],
        'created': timestamp_to_strftime(ac['created']),
        'adetail': ac['content']['adetail']
    }

    return render_template('hh_about.html', about=a)
Ejemplo n.º 26
0
def project_list():

    pg = int(request.args.get('pg', 1))
    num = int(request.args.get('num', 6))

    res_type = 'project'

    bb_cli = BigbroCache()

    start_ = (pg - 1) * num
    end_ = start_ + num

    p_li = bb_cli.get_resource_list(res_type=res_type)

    rst = []
    for p_id in p_li:

        slz = {}
        pc = bb_cli.get_resource(res_type=res_type, res_id=p_id)
        if not pc or pc['online'] != 'on':
            continue

        slz['project_id'] = pc['res_id']
        slz['pdate'] = pc['content']['pdate']
        slz['ptitle'] = pc['content']['ptitle']
        slz['psubtitle'] = pc['content']['psubtitle']
        slz['pcover'] = pc['content']['pcover']

        rst.append(slz)

    tpg = int(ceil(len(rst) / 6.0))

    return json.dumps({
        'project_li': rst[start_:end_],
        'total_pg': tpg,
        'pg': pg
    })
Ejemplo n.º 27
0
    def decorate_function(*args, **kargs):

        username = session.get('username', None)
        if not username:
            return 'login_first'

        sign_info = BigbroCache().get_sign_info(username)
        if not sign_info:
            return 'login_first'

        if sign_info['bb_ip'] != get_client_ip(request) or \
                sign_info['bb_agent'] != request.user_agent.string:
            return 'thx_for_request_1'

        request.username = username

        return f(*args, **kargs)
Ejemplo n.º 28
0
def banners():

    bb_cli = BigbroCache()
    rtp = 'banner'

    if request.method == 'POST':
        cnt = {}
        for k in banner_keys:
            cnt[k] = request.form[k]

        r = Resources.create(res_tp=rtp,
                             content=json.dumps(cnt),
                             create_bb=request.username)

        bb_cli.update_resource({
            'res_tp': r.res_tp,
            'res_id': r.res_id,
            'online': 'off',
            'bb': request.username,
            'content': cnt,
            'created': r.created
        })
        bb_cli.add_resource_id(res_type=r.res_tp, res_id=r.res_id)

        return render_template('banner_create.html')

    pg = int(request.args.get('pg', 1))

    start_ = (pg - 1) * 20
    end_ = start_ + 20 - 1

    banner_total = bb_cli.get_resource_len(res_type=rtp)
    total_pg = int(ceil(banner_total / 20.0))

    b_ids = bb_cli.get_resource_list(res_type=rtp, start=start_, end=end_)

    rst = []
    for b_id in b_ids:
        # slz = {}
        # bc = bb_cli.get_resource(res_type=rtp, res_id=b_id)
        # if not bc:
        #    continue

        # slz['res_id'] = bc['res_id']
        # slz['bb'] = bc['bb']
        # slz['created'] = timestamp_to_strftime(bc['created'])
        # slz['online'] = bc['online']
        # for k in banner_keys:
        #    slz[k] = bc['content'][k]

        # rst.append(slz)

        slz = {}
        mc = bb_cli.get_resource(res_type='movie', res_id=b_id)
        if not mc:
            continue

        slz['res_id'] = mc['res_id']
        slz['bb'] = mc['bb']
        slz['created'] = timestamp_to_strftime(mc['created'])
        slz['online'] = mc['online']
        slz['res_tp'] = mc['res_tp']
        for k in movie_keys:
            slz[k] = mc['content'].get(k, '')

        rst.append(slz)

    return render_template('banner_movies_v11.html',
                           movies=rst,
                           banner_total=banner_total,
                           total_pg=total_pg,
                           pg=pg)
Ejemplo n.º 29
0
def movies():

    bb_cli = BigbroCache()
    rtp = 'movie'

    if request.method == 'POST':
        cnt = {}
        for k in movie_keys:
            if k == 'clips':
                cnt[k] = request.form.getlist('clips[]')
            elif k == 'posters':
                cnt[k] = request.form.getlist('posters[]')
            elif k == 'videos':
                v_links = request.form.getlist('vdo_links[]')
                v_covers = request.form.getlist('vdo_covers[]')
                v_titles = request.form.getlist('vdo_titles[]')
                cnt[k] = []
                for l, c, t in zip(v_links, v_covers, v_titles):
                    cnt[k].append({'vlink': l, 'vcover': c, 'vtitle': t})
            else:
                cnt[k] = request.form[k]
        cnt['mlang'] = request.form.get('mlang', 'zh')

        r = Resources.create(res_tp=rtp,
                             content=json.dumps(cnt),
                             create_bb=request.username)

        bb_cli.update_resource({
            'res_tp': r.res_tp,
            'res_id': r.res_id,
            'online': 'off',
            'bb': request.username,
            'content': cnt,
            'created': r.created
        })
        bb_cli.add_resource_id(res_type=r.res_tp,
                               res_id=r.res_id,
                               lang=cnt['mlang'])

        return render_template('movie_create.html')

    pg = int(request.args.get('pg', 1))
    lang = request.args.get('lang', 'zh')

    start_ = (pg - 1) * 20
    end_ = start_ + 20 - 1

    movie_total = bb_cli.get_resource_len(res_type=rtp, lang=lang)
    total_pg = int(ceil(movie_total / 20.0))

    m_ids = bb_cli.get_resource_list(res_type=rtp,
                                     start=start_,
                                     end=end_,
                                     lang=lang)

    rst = []
    for m_id in m_ids:
        slz = {}
        mc = bb_cli.get_resource(res_type=rtp, res_id=m_id)
        if not mc:
            continue

        slz['res_id'] = mc['res_id']
        slz['bb'] = mc['bb']
        slz['created'] = timestamp_to_strftime(mc['created'])
        slz['online'] = mc['online']
        slz['res_tp'] = mc['res_tp']
        for k in movie_keys:
            slz[k] = mc['content'].get(k, '')
        slz['mlang'] = mc['content'].get('mlang', 'zh')

        rst.append(slz)

    return render_template('hh_movies_v11.html',
                           movies=rst,
                           movie_total=movie_total,
                           total_pg=total_pg,
                           pg=pg)
Ejemplo n.º 30
0
def movie():

    act = request.form.get('act')
    mid = request.form.get('mid')
    rtp = 'movie'

    if not (act and mid):
        return 'thx_for_request_0'

    bb_cli = BigbroCache()
    mc = bb_cli.get_resource(res_type=rtp, res_id=mid)
    if not mc:
        return 'thx_for_request'

    if act in ['on', 'off']:
        mc['online'] = act
        bb_cli.update_resource(mc)
    elif act == 'fst':
        bb_cli.top_resource(res_type=rtp, res_id=mid)
    elif act == 'del':
        bb_cli.rem_resource_id(res_type=rtp, res_id=mid)
        Resources.bb_delete(res_tp=rtp, res_id=mid, update_bb=request.username)
        if mc['content']['posters']:
            for p in mc['content']['posters']:
                delete_resource(p)
        if mc['content']['clips']:
            for c in mc['content']['clips']:
                delete_resource(c)
        if mc['content']['mcover']:
            delete_resource(mc['content']['mcover'])
        if mc['content']['videos']:
            for v in mc['content']['videos']:
                delete_resource(v['vcover'])
    elif act == 'rcmd-on':
        bb_cli.set_recommend_movie(movie_id=mid,
                                   lang=mc['content'].get('mlang', 'zh'))
    elif act == 'rcmd-off':
        bb_cli.del_recommend_movie(lang=mc['content'].get('mlang', 'zh'))
    elif act == 'banner-on':
        bb_cli.add_resource_id(res_type='banner', res_id=mid)
    elif act == 'banner-off':
        bb_cli.rem_resource_id(res_type='banner', res_id=mid)

    return 'ok'