Exemple #1
0
def detail(request, tag, res_id):
    try:
        r = Resource.objects.get(id=res_id, status='enabled')
    except Resource.DoesNotExist:
        return render_to_response('miss/resource.htm', RequestContext(request))

    # 资源信息
    res = {
        'id': r.id,
        'create_date': r.gmt_create.strftime('%Y-%m-%d %H:%M:%S'),
        'user_id': r.user_id,
        'nickname': cache.get_user_nickname(r.user_id),
        'avatar': cache.get_user_avatar(r.user_id),
        'title': r.title,
        'type': r.type,
        'content': json.loads(r.content),
        'thumbnail': json.loads(r.thumbnail),  # jiathis
        'comments': r.comments,
        'vote_type': cache.resource_vote_type(r.id,
                                              _get_current_userid(request)),
        'up': r.up,
        'down': r.down
    }

    # 评论信息
    comment_list = []
    cl = Resource_Comment.objects.filter(
        res_id=res_id, status='enabled').order_by('-gmt_create')
    for comment in cl:
        comment_list.append({
            'comment_id':
            comment.id,
            'create_date':
            prettydate.convert(comment.gmt_create),
            'user_id':
            comment.user_id,
            'nickname':
            cache.get_user_nickname(comment.user_id),
            'avatar':
            cache.get_user_avatar(comment.user_id),
            'content':
            comment.content
        })

    # 上一个/下一个
    prev = not _first_resource_id(res_id)
    next = not _last_resource_id(res_id)

    context = RequestContext(
        request, {
            'res': res,
            'commentList': comment_list,
            'next': next,
            'prev': prev,
            'groups': cache.get_group_list()
        })
    return render_to_response('detail.htm', context)
Exemple #2
0
def detail(request, tag, res_id):
    try:
        r = Resource.objects.get(id=res_id, status='enabled')
    except Resource.DoesNotExist:
        return render_to_response('miss/resource.htm', RequestContext(request))

    # 资源信息
    res = {
        'id': r.id,
        'create_date': r.gmt_create.strftime('%Y-%m-%d %H:%M:%S'),
        'user_id': r.user_id,
        'nickname': cache.get_user_nickname(r.user_id),
        'avatar': cache.get_user_avatar(r.user_id),
        'title': r.title,
        'type': r.type,
        'content': json.loads(r.content),
        'thumbnail': json.loads(r.thumbnail),  # jiathis
        'comments': r.comments,
        'vote_type': cache.resource_vote_type(r.id, _get_current_userid(request)),
        'up': r.up,
        'down': r.down
    }

    # 评论信息
    comment_list = []
    cl = Resource_Comment.objects.filter(res_id=res_id, status='enabled').order_by('-gmt_create')
    for comment in cl:
        comment_list.append({
            'comment_id': comment.id,
            'create_date': prettydate.convert(comment.gmt_create),
            'user_id': comment.user_id,
            'nickname': cache.get_user_nickname(comment.user_id),
            'avatar': cache.get_user_avatar(comment.user_id),
            'content': comment.content})

    # 上一个/下一个
    prev = not _first_resource_id(res_id)
    next = not _last_resource_id(res_id)

    context = RequestContext(request, {
        'res': res,
        'commentList': comment_list,
        'next': next,
        'prev': prev,
        'groups': cache.get_group_list()})
    return render_to_response('detail.htm', context)
Exemple #3
0
def classify(request, tag):
    page_size = 10
    page = _get_page(request)
    offset = (int(page) - 1) * page_size

    rl = Resource.objects.filter(
        type=tag,
        status='enabled').order_by('-gmt_create')[offset:offset + page_size]
    res_count = Resource.objects.filter(type=tag, status='enabled').count()
    pages = int(math.ceil(res_count / (page_size * 1.0)))

    res_list = []
    for r in rl:
        res = {
            'id':
            r.id,
            'create_date':
            prettydate.convert(r.gmt_create),
            'user_id':
            r.user_id,
            'nickname':
            cache.get_user_nickname(r.user_id),
            'avatar':
            cache.get_user_avatar(r.user_id),
            'title':
            r.title,
            'type':
            r.type,
            'thumbnail':
            json.loads(r.thumbnail),  # json
            'comments':
            r.comments,
            'vote_type':
            cache.resource_vote_type(r.id, _get_current_userid(request)),
            'up':
            r.up,
            'down':
            r.down
        }
        res_list.append(res)
    # side bar
    group_list = cache.get_group_list()
    pageUrl = _get_page_url(config.get_config('SHAREHP_SERVER_HOST'),
                            request.path)
    context = RequestContext(
        request, {
            'tag': tag,
            'resList': res_list,
            'groups': group_list,
            'curPage': page,
            'pages': pages,
            'pageUrl': pageUrl
        })
    return render_to_response('tag.htm', context)
Exemple #4
0
def group(request, group_id, order):
    is_exist = Group.objects.filter(id=group_id).exists()
    if not is_exist:
        return render_to_response('miss/group.htm', RequestContext(request))

    # 每页显示10条
    page_size = 10
    page = _get_page(request)
    offset = (int(page) - 1) * page_size
    # 排序
    if order == 'hot':
        # FIXME 最热排序逻辑
        gts = []
    else:
        gts = Group_Topic.objects.filter(
            group_id=group_id,
            status='enabled').order_by('-gmt_create')[offset:offset +
                                                      page_size]
    topics = []
    for t in gts:
        topic = {
            'id': t.id,
            'topic_name': t.topic_name,
            'user_id': t.user_id,
            'nickname': cache.get_user_nickname(t.user_id),
            'avatar': cache.get_user_avatar(t.user_id),
            'comments': t.comments,
            'publish_date': prettydate.convert(t.gmt_create),
            'last_comment_date': prettydate.convert(t.gmt_modify)
        }
        topics.append(topic)

    topic_count = Group_Topic.objects.filter(group_id=group_id,
                                             status='enabled').count()
    pages = int(math.ceil(topic_count / (page_size * 1.0)))
    pageUrl = _get_page_url(config.get_config('SHAREHP_SERVER_HOST'),
                            request.path)
    group = cache.get_group_info(group_id)

    context = RequestContext(
        request, {
            'group': group,
            'topics': topics,
            'curPage': page,
            'pages': pages,
            'pageUrl': pageUrl
        })
    return render_to_response('group.htm', context)
Exemple #5
0
def group_topic(request, topic_id):
    is_exist = Group_Topic.objects.filter(id=topic_id).exists()
    if not is_exist:
        return render_to_response('miss/topic.htm', RequestContext(request))

    # 每页显示20楼
    page_size = 20
    page = _get_page(request)
    offset = (int(page) - 1) * page_size

    comment_count = Topic_Comment.objects.filter(topic_id=topic_id).count()
    pages = int(math.ceil(comment_count / (page_size * 1.0)))
    pageUrl = _get_page_url(config.get_config('SHAREHP_SERVER_HOST'),
                            request.path)

    tcs = Topic_Comment.objects.filter(topic_id=topic_id)[offset:offset +
                                                          page_size]
    topic_comments = []
    floor_base = page_size * (page - 1)
    for floor, tc in enumerate(tcs):
        topic_comment = {
            'floor': floor + 1 + floor_base,  # FIXME
            'create_date': tc.gmt_create.strftime('%Y-%m-%d %H:%M:%S'),
            'user_id': tc.user_id,
            'nickname': cache.get_user_nickname(tc.user_id),
            'avatar': cache.get_user_avatar(tc.user_id),
            'content': tc.content,
            'attachment': json.loads(tc.attachment),
        }
        topic_comments.append(topic_comment)

    topic = cache.get_topic_info(topic_id)
    group = cache.get_group_info_by_topicid(topic['id'])

    context = RequestContext(
        request, {
            'group': group,
            'topic': topic,
            'topicComments': topic_comments,
            'curPage': page,
            'pages': pages,
            'pageUrl': pageUrl
        })
    return render_to_response('group_topic.htm', context)
Exemple #6
0
def group(request, group_id, order):
    is_exist = Group.objects.filter(id=group_id).exists()
    if not is_exist:
        return render_to_response('miss/group.htm', RequestContext(request))

    # 每页显示10条
    page_size = 10
    page = _get_page(request)
    offset = (int(page) - 1) * page_size
    # 排序
    if order == 'hot':
        # FIXME 最热排序逻辑
        gts = []
    else:
        gts = Group_Topic.objects.filter(group_id=group_id, status='enabled').order_by('-gmt_create')[
              offset: offset + page_size]
    topics = []
    for t in gts:
        topic = {
            'id': t.id,
            'topic_name': t.topic_name,
            'user_id': t.user_id,
            'nickname': cache.get_user_nickname(t.user_id),
            'avatar': cache.get_user_avatar(t.user_id),
            'comments': t.comments,
            'publish_date': prettydate.convert(t.gmt_create),
            'last_comment_date': prettydate.convert(t.gmt_modify)
        }
        topics.append(topic)

    topic_count = Group_Topic.objects.filter(group_id=group_id, status='enabled').count()
    pages = int(math.ceil(topic_count / (page_size * 1.0)))
    pageUrl = _get_page_url(config.get_config('SHAREHP_SERVER_HOST'), request.path)
    group = cache.get_group_info(group_id)

    context = RequestContext(request, {'group': group,
                                       'topics': topics,
                                       'curPage': page,
                                       'pages': pages,
                                       'pageUrl': pageUrl})
    return render_to_response('group.htm', context)
Exemple #7
0
def index(request):
    rl = Resource.objects.filter(status='enabled').order_by('-gmt_create')[0:20]
    # 分发资源到瀑布中
    resListArray = [[], [], [], []]
    for i, r in enumerate(rl):
        res = {
            'id': r.id,
            'create_date': prettydate.convert(r.gmt_create),
            'user_id': r.user_id,
            'nickname': cache.get_user_nickname(r.user_id),
            'title': r.title,
            'type': r.type,
            'thumbnail': json.loads(r.thumbnail),
            'comments': r.comments
        }
        # 标题过长
        if len(res['title']) > 36:  #  TODO 优化
            res['title'] = res['title'][:36] + '...'
        resListArray[i % 4].append(res)

    context = RequestContext(request, {'resListArray': resListArray})
    return render_to_response('index.htm', context)
Exemple #8
0
def group_topic(request, topic_id):
    is_exist = Group_Topic.objects.filter(id=topic_id).exists()
    if not is_exist:
        return render_to_response('miss/topic.htm', RequestContext(request))

    # 每页显示20楼
    page_size = 20
    page = _get_page(request)
    offset = (int(page) - 1) * page_size

    comment_count = Topic_Comment.objects.filter(topic_id=topic_id).count()
    pages = int(math.ceil(comment_count / (page_size * 1.0)))
    pageUrl = _get_page_url(config.get_config('SHAREHP_SERVER_HOST'), request.path)

    tcs = Topic_Comment.objects.filter(topic_id=topic_id)[offset: offset + page_size]
    topic_comments = []
    floor_base = page_size * (page - 1)
    for floor, tc in enumerate(tcs):
        topic_comment = {
            'floor': floor + 1 + floor_base,  # FIXME
            'create_date': tc.gmt_create.strftime('%Y-%m-%d %H:%M:%S'),
            'user_id': tc.user_id,
            'nickname': cache.get_user_nickname(tc.user_id),
            'avatar': cache.get_user_avatar(tc.user_id),
            'content': tc.content,
            'attachment': json.loads(tc.attachment),
        }
        topic_comments.append(topic_comment)

    topic = cache.get_topic_info(topic_id)
    group = cache.get_group_info_by_topicid(topic['id'])

    context = RequestContext(request, {'group': group,
                                       'topic': topic,
                                       'topicComments': topic_comments,
                                       'curPage': page,
                                       'pages': pages,
                                       'pageUrl': pageUrl})
    return render_to_response('group_topic.htm', context)
Exemple #9
0
def index(request):
    rl = Resource.objects.filter(
        status='enabled').order_by('-gmt_create')[0:20]
    # 分发资源到瀑布中
    resListArray = [[], [], [], []]
    for i, r in enumerate(rl):
        res = {
            'id': r.id,
            'create_date': prettydate.convert(r.gmt_create),
            'user_id': r.user_id,
            'nickname': cache.get_user_nickname(r.user_id),
            'title': r.title,
            'type': r.type,
            'thumbnail': json.loads(r.thumbnail),
            'comments': r.comments
        }
        # 标题过长
        if len(res['title']) > 36:  #  TODO 优化
            res['title'] = res['title'][:36] + '...'
        resListArray[i % 4].append(res)

    context = RequestContext(request, {'resListArray': resListArray})
    return render_to_response('index.htm', context)
Exemple #10
0
def classify(request, tag):
    page_size = 10
    page = _get_page(request)
    offset = (int(page) - 1) * page_size

    rl = Resource.objects.filter(type=tag, status='enabled').order_by('-gmt_create')[offset: offset + page_size]
    res_count = Resource.objects.filter(type=tag, status='enabled').count()
    pages = int(math.ceil(res_count / (page_size * 1.0)))

    res_list = []
    for r in rl:
        res = {
            'id': r.id,
            'create_date': prettydate.convert(r.gmt_create),
            'user_id': r.user_id,
            'nickname': cache.get_user_nickname(r.user_id),
            'avatar': cache.get_user_avatar(r.user_id),
            'title': r.title,
            'type': r.type,
            'thumbnail': json.loads(r.thumbnail),  # json
            'comments': r.comments,
            'vote_type': cache.resource_vote_type(r.id, _get_current_userid(request)),
            'up': r.up,
            'down': r.down
        }
        res_list.append(res)
    # side bar
    group_list = cache.get_group_list()
    pageUrl = _get_page_url(config.get_config('SHAREHP_SERVER_HOST'), request.path)
    context = RequestContext(request, {'tag': tag,
                                       'resList': res_list,
                                       'groups': group_list,
                                       'curPage': page,
                                       'pages': pages,
                                       'pageUrl': pageUrl})
    return render_to_response('tag.htm', context)