Ejemplo n.º 1
0
def tvIndex(request, *args, **kwargs):
    ret = {
        'logined': False,
        'show': '',
        'pagelist': '',
        'search_ok': False,
        'counts': 0
    }
    #判断用户是否登录,获取用户信息
    ret, user_obj = loginInfo(request, ret)
    ret['user_info'] = user_obj
    bill_obj = models.Tv.objects.all().order_by('-week_visit_count')
    billboard1 = bill_obj[0]
    billboard2 = bill_obj[1:10]
    ret['billboard1'] = billboard1
    if not path.exists(BASE_DIR + ret['billboard1'].poster):
        ret['billboard1'].poster = '/static/images/default/poster/p_200x284.png'
    ret['billboard2'] = billboard2
    for item in ret['billboard2']:
        if not path.exists(BASE_DIR + item.poster):
            item.poster = '/static/images/default/poster/p_200x284.png'
    '''
    内容显示及分页
    '''

    page = try_int(request.GET.get('p', 1), 1)
    target_focus = request.GET.get('focus', 'af')
    target_type = request.GET.get('type', 'at')
    target_region = request.GET.get('region', 'ar')

    #type
    if target_type == 'at':
        type_result = models.Tv.objects.all()
    else:
        typedict = {
            'juqing': '剧情',
            'xiju': '喜剧',
            'aiqing': '爱情',
            'qihuan': '奇幻',
            'guzhuang': '古装',
            'dongzuo': '动作',
            'maoxian': '冒险',
            'kehuan': '科幻',
            'xuanyi': '悬疑',
            'jingsong': '惊悚',
            'kongbu': '恐怖',
            'fanzui': '犯罪',
            'zhanzheng': '战争',
            'donghua': '动画',
            'jilupian': '纪录片',
            'tongxing': '同性',
            'qingse': '情色',
            'jiating': '家庭',
            'ertong': '儿童',
            'lishi': '历史',
            'yundong': '运动',
            'zhuanji': '传记'
        }
        for item in typedict:
            if target_type == item:
                type_result = models.Tv.objects.filter(
                    types__contains=typedict[item])
        if not 'type_result' in dir():
            raise Http404
            return render_to_response('404.html')

    #region
    if target_region == 'ar':
        region_result = type_result

    elif target_region == 'otherregion':
        region_result = type_result.exclude(
            Q(region__contains='中国大陆') | Q(region__contains='香港')
            | Q(region__contains='台湾') | Q(region__contains='美国')
            | Q(region__contains='英国') | Q(region__contains='法国')
            | Q(region__contains='日本') | Q(region__contains='韩国')
            | Q(region__contains='泰国') | Q(region__contains='印度'))
    else:
        regiondict = {
            'mainland': '中国大陆',
            'hongkong': '香港',
            'taiwan': '台湾',
            'america': '美国',
            'uk': '英国',
            'french': '法国',
            'japan': '日本',
            'korea': '韩国',
            'thailand': '泰国',
            'india': '印度'
        }

        for item in regiondict:
            if target_region == item:
                region_result = type_result.filter(
                    region__contains=regiondict[item])
        #print region_result_tv
        if not 'region_result' in dir():
            raise Http404
            return render_to_response('404.html')

    #focus
    if target_focus == 'af':
        focus_result = region_result.filter().order_by('-release_date')
    elif target_focus == 'guonei':
        focus_result = region_result.filter(
            release_date_show__contains='中国').exclude(
                score=0).order_by('-release_date')
    elif target_focus == 'guowai':
        focus_result = region_result.exclude(
            Q(release_date_show__contains='中国')
            | Q(score=0)).order_by('-release_date')
    elif target_focus == 'gaofen':
        focus_result = region_result.filter(score__gte=8).order_by('-score')
    elif target_focus == 'gengxin':
        focus_result = region_result.all().order_by('-create_date')
    elif target_focus == 'not_released':
        today = datetime.datetime.now().strftime('%Y-%m-%d')
        focus_result = region_result.filter(
            release_date__gt=today).order_by('release_date')
    if not 'focus_result' in dir():
        raise Http404
        return render_to_response('404.html')
    items_per_page = try_int(request.COOKIES.get('page_num', 20), 20)
    try:
        all_item_counts = focus_result.count()
    except Exception:
        all_item_counts = 0
    ret['counts'] = all_item_counts

    pageObj = html_helper.PageInfo(page, all_item_counts, items_per_page)

    try:
        final_result = focus_result[pageObj.start:pageObj.end]
    except Exception:
        final_result = ''
    filter_url = '/tv/?focus=' + target_focus + '&type=' + target_type + '&region=' + target_region + '&p='
    page_list = html_helper.Pager(page, pageObj.total_page_counts, filter_url)

    #popular
    popular_id_list = []
    popular = bill_obj[:30]
    for item in popular:
        popular_id_list.append(item.id)

    #判断图片是否存在,不存在替换为默认图片
    ret['show'] = final_result
    for item in ret['show']:
        if not path.exists(BASE_DIR + item.poster):
            item.poster = '/static/images/default/poster/p_200x284.png'
        for p in popular_id_list:
            if p == item.id:
                item.popular = True

    ret['pages'] = pageObj.total_page_counts

    if pageObj.total_page_counts == 1:
        ret['page_list'] = ''
    elif pageObj.total_page_counts == 0:
        ret['no_result'] = True
    else:
        ret['page_list'] = page_list
    '''
    *标签云
    '''
    tags_obj = models.Tv.objects.all().order_by('-week_visit_count').values(
        'id', 'ch_name', 'director', 'actor')[:50]
    da_dict, mn_list = movie_helper.tagsCloud(tags_obj, 'tv')
    ret['da_dict'] = json.dumps(da_dict)
    ret['mn_list'] = json.dumps(mn_list)

    thumb_switch = request.COOKIES.get('switch', 't1')
    if thumb_switch == 't1':
        response = render_to_response('tv/tv_index.html',
                                      ret,
                                      context_instance=RequestContext(request))
    elif thumb_switch == 't2':
        response = render_to_response('tv/tv_index_t2.html',
                                      ret,
                                      context_instance=RequestContext(request))
    elif thumb_switch == 't3':
        response = render_to_response('tv/tv_index_t3.html',
                                      ret,
                                      context_instance=RequestContext(request))
    response.set_cookie('page_num', items_per_page)
    return response
Ejemplo n.º 2
0
def tvDetail(request, *args, **kwargs):
    ret = {'logined': False, 'user_info': '', 'has_rated': False}
    ret, user_obj = loginInfo(request, ret)
    ret['user_info'] = user_obj
    if user_obj:
        uid = user_obj.id

    #右侧边栏
    billboard1 = models.Tv.objects.all().order_by('-week_visit_count')[0]
    billboard2 = models.Tv.objects.all().order_by('-week_visit_count')[1:10]
    ret['billboard1'] = billboard1
    if not path.exists(BASE_DIR + ret['billboard1'].poster):
        ret['billboard1'].poster = '/static/images/default/poster/p_200x284.png'
    ret['billboard2'] = billboard2
    for item in ret['billboard2']:
        if not path.exists(BASE_DIR + item.poster):
            item.poster = '/static/images/default/poster/p_200x284.png'

    #电视剧信息
    tid = args[0]
    ret['tid'] = tid
    try:
        tv_obj = models.Tv.objects.get(id=tid)
    except Exception:
        raise Http404
        #return render_to_response('404.html')

    tv_obj.visit_count += 1
    tv_obj.week_visit_count += 1
    tv_obj.month_visit_count += 1
    tv_obj.save()

    ret['detail'] = movie_helper.replaceWrongImg([tv_obj], 'ps')[0]

    down_list = []
    if tv_obj.down_urls and not tv_obj.down_urls == '无下载':
        name_list = tv_obj.down_names.splitlines()
        url_list = tv_obj.down_urls.splitlines()
        for i in range(len(name_list)):
            try:
                down_list.append([name_list[i], url_list[i]])
            except IndexError:
                break

        ret['urls'] = down_list
        print down_list[0]
    else:
        ret['urls'] = None

    #ret['face_id'] = str(randint(1,11))   #卡通头像文件名编号

    reply_obj = models.TvReply.objects.filter(
        tv__id=tid).order_by('-create_date')
    reply_counts = tv_obj.tv_r.all().count()
    ret['reply_counts'] = reply_counts
    ret['reply'] = reply_obj

    #判断是否已评过分
    if user_obj:
        has_rated = models.TvReply.objects.filter(tv__id=tid,
                                                  user__id=user_obj.id,
                                                  rating__gt=0)
        has_rated_counts = has_rated.count()
        if has_rated_counts == 1:
            ret['has_rated'] = True
            ret['cur_user_rating'] = has_rated[0].rating
        elif has_rated_counts > 1:
            ret['has_rated'] = 'error'

    #收藏
    if user_obj:
        collect_obj = models.Collect_Tv.objects.filter(tv__id=tid,
                                                       user__id=uid)
        if collect_obj:
            ret['collected'] = True
    '''
        猜你喜欢
    '''
    all_tv_obj = models.Tv.objects.exclude(id=tid)
    tv_related_obj = movie_helper.relatedMovies(tv_obj, all_tv_obj)
    ret['related'] = movie_helper.replaceWrongImg(tv_related_obj, 'p')

    #标签云
    tags_obj = models.Tv.objects.all().order_by('-week_visit_count').values(
        'id', 'ch_name', 'director', 'actor')[:50]
    da_dict, mn_list = movie_helper.tagsCloud(tags_obj, 'tv')
    ret['da_dict'] = json.dumps(da_dict)
    ret['mn_list'] = json.dumps(mn_list)
    response = render_to_response('tv/tv_detail.html',
                                  ret,
                                  context_instance=RequestContext(request))

    #cookie
    if user_obj:
        response.set_cookie('logined', 'yes')
    else:
        response.set_cookie('logined', 'no')
    return response
Ejemplo n.º 3
0
def movieDetail(request, *args, **kwargs):
    ret = {'logined': False, 'user_info': '', 'has_rated': False}
    ret, user_obj = loginInfo(request, ret)
    ret['user_info'] = user_obj
    if user_obj:
        uid = user_obj.id
    #右侧边栏
    billboard1 = models.Movie.objects.all().order_by('-week_visit_count')[0]
    billboard2 = models.Movie.objects.all().order_by('-week_visit_count')[1:10]
    ret['billboard1'] = billboard1
    if not path.exists(BASE_DIR + ret['billboard1'].poster):
        ret['billboard1'].poster = '/static/images/default/poster/p_200x284.png'
    ret['billboard2'] = billboard2
    for item in ret['billboard2']:
        if not path.exists(BASE_DIR + item.poster):
            item.poster = '/static/images/default/poster/p_200x284.png'

    #电影信息
    mid = args[0]
    ret['mid'] = mid
    try:
        movie_obj = models.Movie.objects.get(id=mid)
    except Exception:
        raise Http404
        #return render_to_response('404.html')

    movie_obj.visit_count += 1
    movie_obj.week_visit_count += 1
    movie_obj.month_visit_count += 1
    movie_obj.save()

    #ret['detail'] = movie_obj
    ret['detail'] = movie_helper.replaceWrongImg([movie_obj], 'ps')[0]
    #ret['face_id'] = str(randint(1,11))   #卡通头像文件名编号

    reply_obj = models.MovieReply.objects.filter(
        movie__id=mid).order_by('-create_date')[:10]
    reply_counts = movie_obj.movie_r.all().count()
    ret['reply_counts'] = reply_counts
    ret['reply'] = reply_obj

    #判断是否已评过分
    if user_obj:
        has_rated = models.MovieReply.objects.filter(movie__id=mid,
                                                     user__id=user_obj.id,
                                                     rating__gt=0)
        has_rated_counts = has_rated.count()
        if has_rated_counts == 1:
            ret['has_rated'] = True
            ret['cur_user_rating'] = has_rated[0].rating
        elif has_rated_counts > 1:
            ret['has_rated'] = 'error'

    #收藏
    if user_obj:
        collect_obj = models.Collect_Movie.objects.filter(movie__id=mid,
                                                          user__id=uid)
        if collect_obj:
            ret['collected'] = True
    '''
        猜你喜欢
    '''
    all_movie_obj = models.Movie.objects.exclude(id=mid)
    movie_related_obj = movie_helper.relatedMovies(movie_obj, all_movie_obj)
    ret['related'] = movie_helper.replaceWrongImg(movie_related_obj, 'p')

    #标签云
    tags_obj = models.Movie.objects.all().order_by('-week_visit_count').values(
        'id', 'ch_name', 'director', 'actor')[:50]
    da_dict, mn_list = movie_helper.tagsCloud(tags_obj, 'movie')
    ret['da_dict'] = json.dumps(da_dict)
    ret['mn_list'] = json.dumps(mn_list)
    response = render_to_response('movie/movie_detail.html',
                                  ret,
                                  context_instance=RequestContext(request))

    #cookie
    """
    if user_obj:
        response.set_cookie('logined', 'yes')
    else:
        response.set_cookie('logined', 'no')
    """
    return response