예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
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)
예제 #6
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)
예제 #7
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)
예제 #8
0
def news():

    bb_cli = BigbroCache()
    rtp = 'news'

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

        cnt['nlang'] = request.form.get('nlang', '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,
            '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,
                               lang=cnt['nlang'])

        return render_template('news_create.html')

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

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

    news_total = bb_cli.get_resource_len(res_type=rtp, lang=lang)
    total_pg = int(ceil(news_total / 10.0))

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

    rst = []
    for n_id in n_ids:
        slz = {}
        nc = bb_cli.get_resource(res_type=rtp, res_id=n_id)
        if not nc:
            continue

        slz['res_id'] = nc['res_id']
        slz['bb'] = nc['bb']
        slz['created'] = timestamp_to_strftime(nc['created'])
        slz['online'] = nc['online']
        for k in news_keys:
            slz[k] = nc['content'][k]
        slz['nlang'] = nc['content'].get('nlang', 'zh')

        rst.append(slz)

    return render_template('hh_news_v11.html',
                           news=rst,
                           news_total=news_total,
                           total_pg=total_pg,
                           pg=pg)