예제 #1
0
def people_follows(request, people):
    '''
	'''
    follows = get_follows(people)

    user = request.user
    has_followed = False
    if request.user.is_authenticated() and user != people:
        if follows[4] in request.user.userdata.follows.all():
            has_followed = True

    follows.append(has_followed)

    key = str(people.id) + 'bf'
    cache_bf = cache.get(key)
    if cache_bf:
        followers = cache_bf
    else:
        followers_ship = FollowShip.objects.filter(column=follows[4]).order_by(
            '-time').all()[:MESSAGES_PER_PAGE].prefetch_related(
                'userdata__user__userprofile__avatar')
        followers = [f.userdata for f in followers_ship]
        cache.set(key, followers, FOLLOWS_CACHE_AGE)

    follows.append(followers)

    return follows
예제 #2
0
파일: views.py 프로젝트: haipome/Newsnavig
def people_follows(request, people):
	'''
	'''
	follows = get_follows(people)
	
	user = request.user
	has_followed = False
	if request.user.is_authenticated() and user != people:
		if follows[4] in request.user.userdata.follows.all():
			has_followed = True
	
	follows.append(has_followed)
	
	key = str(people.id) + 'bf'
	cache_bf = cache.get(key)
	if cache_bf:
		followers = cache_bf
	else:
		followers_ship = FollowShip.objects.filter(
		            column=follows[4]).order_by(
		            '-time').all(
		            )[:MESSAGES_PER_PAGE].prefetch_related(
		            'userdata__user__userprofile__avatar')
		followers = [f.userdata for f in followers_ship]
		cache.set(key, followers, FOLLOWS_CACHE_AGE)
	
	follows.append(followers)
	
	return follows
예제 #3
0
파일: views.py 프로젝트: haipome/Newsnavig
def choose(request):
	'''
	'''
	follows_user = get_follows(request.user)[1]
	
	return render_to_response('messages/choose.html',
	                         {'follows_user': follows_user,},
	                          context_instance=RequestContext(request))
예제 #4
0
def choose(request):
    '''
	'''
    follows_user = get_follows(request.user)[1]

    return render_to_response('messages/choose.html', {
        'follows_user': follows_user,
    },
                              context_instance=RequestContext(request))
예제 #5
0
파일: views.py 프로젝트: mawang82/Newsnavig
def index(request):
    '''
	'''
    pre_page, next_page, s, e = process_pager(request)

    if pre_page:
        page = pre_page + 1
    else:
        page = 1
    today = date.today()
    local = tz.gettz(TIME_ZONE)

    user = request.user
    if not user.is_authenticated():

        topics = get_hot_topic(MESSAGES_PER_PAGE)

        d_types = ['a', 'e', 'h', 'i']
        dynamics = Dynamic.objects.filter(is_visible=True).filter(
            way__in=d_types).order_by('-id').all()[s:e].prefetch_related(
                'content_object__user__userprofile__avatar',
                'content_object__domain',
                'column__content_object',
                'comment_object__domain',
            )

        for d in dynamics:
            d.time = d.time.astimezone(local)

        if len(dynamics) < MESSAGES_PER_PAGE:
            next_page = False

        return render_to_response('dynamic.html', {
            'dynamics': dynamics,
            'topics': topics,
            'today': today,
            'pre': pre_page,
            'next': next_page,
        },
                                  context_instance=RequestContext(request))

    user_topics = get_user_topics(user)

    follow = get_follows(user)
    dynamics, has_next_page = get_dynamics(user, follow[0], page)

    for d in dynamics:
        d.time = d.time.astimezone(local)

    if not has_next_page:
        next_page = False

    return render_to_response('dynamic.html', {
        'user_topics': user_topics,
        'follow': follow,
        'dynamics': dynamics,
        'today': today,
        'pre': pre_page,
        'next': next_page,
    },
                              context_instance=RequestContext(request))
예제 #6
0
파일: views.py 프로젝트: mawang82/Newsnavig
def discuss(request, t='follow'):
    '''
	'''
    pre_page, next_page, s, e = process_pager(request)

    user = request.user
    if pre_page:
        page = pre_page + 1
    else:
        page = 1
    today = date.today()
    local = tz.gettz(TIME_ZONE)

    if not user.is_authenticated() and t == 'follow':
        t = 'all'
        topics = get_hot_topic(MESSAGES_PER_PAGE)

        discusses = Discuss.objects.filter(is_visible=True).order_by(
            '-last_active_time').all()[s:e].prefetch_related(
                'user__userprofile__avatar',
                'last_active_user__userprofile',
            )

        if len(discusses) < MESSAGES_PER_PAGE:
            next_page = False

        for d in discusses:
            if d.last_active_time:
                d.last_active_time = d.last_active_time.astimezone(local)

        return render_to_response('discuss.html', {
            'discusses': discusses,
            'topics': topics,
            't': t,
            'today': today,
            'pre': pre_page,
            'next': next_page,
        },
                                  context_instance=RequestContext(request))

    if not user.is_authenticated():
        return HttpResponseRedirect(reverse('login'))

    user_topics = get_user_topics(user)
    follow = get_follows(user)

    if t == 'follow':
        discusses, has_next_page = get_discusses(user, follow[0], page)
        if not has_next_page:
            next_page = False
    elif t == 'reply':
        discusses = user.userdata.discusses.order_by(
            '-last_active_time').all()[s:e].prefetch_related(
                'user__userprofile__avatar',
                'last_active_user__userprofile',
            )
        if len(discusses) < MESSAGES_PER_PAGE:
            next_page = False
    elif t == 'me':
        discusses = user.user_discusses.order_by(
            '-last_active_time').all()[s:e].prefetch_related(
                'user__userprofile__avatar',
                'last_active_user__userprofile',
            )
        if len(discusses) < MESSAGES_PER_PAGE:
            next_page = False
    else:
        raise Http404

    for d in discusses:
        if d.last_active_time:
            d.last_active_time = d.last_active_time.astimezone(local)

    return render_to_response('discuss.html', {
        'user_topics': user_topics,
        'follow': follow,
        'discusses': discusses,
        'today': today,
        't': t,
        'pre': pre_page,
        'next': next_page,
    },
                              context_instance=RequestContext(request))
예제 #7
0
파일: views.py 프로젝트: haipome/Newsnavig
def index(request):
	'''
	'''
	pre_page, next_page, s, e = process_pager(request)
	
	if pre_page:
		page = pre_page + 1
	else:
		page = 1
	today = date.today()
	local = tz.gettz(TIME_ZONE)
	
	user = request.user
	if not user.is_authenticated():
		
		topics = get_hot_topic(MESSAGES_PER_PAGE)
		
		d_types = ['a', 'e', 'h', 'i']
		dynamics = Dynamic.objects.filter(
		           is_visible=True).filter(
		           way__in=d_types).order_by(
		           '-id').all(
		           )[s:e].prefetch_related(
		           'content_object__user__userprofile__avatar',
		           'content_object__domain',
		           'column__content_object',
		           'comment_object__domain',)
		
		for d in dynamics:
			d.time = d.time.astimezone(local)
		
		if len(dynamics) < MESSAGES_PER_PAGE:
			next_page = False
		
		return render_to_response('dynamic.html', 
		                         {'dynamics':dynamics,
		                          'topics': topics,
		                          'today': today,
		                          'pre': pre_page,
		                          'next': next_page,},
		                           context_instance=RequestContext(request))
	
	user_topics = get_user_topics(user)
	
	follow = get_follows(user)
	dynamics, has_next_page = get_dynamics(user, follow[0], page)
	
	for d in dynamics:
		d.time = d.time.astimezone(local)
	
	if not has_next_page:
		next_page = False
	
	return render_to_response('dynamic.html', 
	                         {'user_topics': user_topics,
	                          'follow': follow,
	                          'dynamics':dynamics,
	                          'today': today,
	                          'pre': pre_page,
	                          'next': next_page,},
	                           context_instance=RequestContext(request))
예제 #8
0
파일: views.py 프로젝트: haipome/Newsnavig
def discuss(request, t='follow'):
	'''
	'''
	pre_page, next_page, s, e = process_pager(request)
	
	user = request.user
	if pre_page:
		page = pre_page + 1
	else:
		page = 1
	today = date.today()
	local = tz.gettz(TIME_ZONE)
	
	if not user.is_authenticated() and t == 'follow':
		t = 'all'
		topics = get_hot_topic(MESSAGES_PER_PAGE)
		
		discusses = Discuss.objects.filter(
		            is_visible=True).order_by(
		            '-last_active_time').all(
		            )[s:e].prefetch_related(
		            'user__userprofile__avatar',
		            'last_active_user__userprofile',)
		
		if len(discusses) < MESSAGES_PER_PAGE:
			next_page = False
		
		for d in discusses:
			if d.last_active_time:
				d.last_active_time = d.last_active_time.astimezone(local)
		
		return render_to_response('discuss.html',
		                         {'discusses':discusses,
		                          'topics': topics,
		                          't': t,
		                          'today': today,
		                          'pre': pre_page,
		                          'next': next_page,},
		                           context_instance=RequestContext(request))
		
	if not user.is_authenticated():
		return HttpResponseRedirect(reverse('login'))
	
	user_topics = get_user_topics(user)
	follow = get_follows(user)
	
	if t == 'follow':
		discusses, has_next_page = get_discusses(user, follow[0], page)
		if not has_next_page:
			next_page = False
	elif t == 'reply':
		discusses = user.userdata.discusses.order_by(
		            '-last_active_time').all(
		            )[s:e].prefetch_related(
		            'user__userprofile__avatar',
		            'last_active_user__userprofile',)
		if len(discusses) < MESSAGES_PER_PAGE:
			next_page = False
	elif t == 'me':
		discusses = user.user_discusses.order_by(
		            '-last_active_time').all(
		            )[s:e].prefetch_related(
		            'user__userprofile__avatar',
		            'last_active_user__userprofile',)
		if len(discusses) < MESSAGES_PER_PAGE:
			next_page = False
	else:
		raise Http404
	
	for d in discusses:
		if d.last_active_time:
			d.last_active_time = d.last_active_time.astimezone(local)
	
	return render_to_response('discuss.html', 
	                         {'user_topics': user_topics,
	                          'follow': follow,
	                          'discusses':discusses,
	                          'today': today,
	                          't': t,
	                          'pre': pre_page,
	                          'next': next_page,},
	                           context_instance=RequestContext(request))