def topic(request, topic_name, t='links'): ''' ''' pre_page, next_page, s, e = process_pager(request, limit=False) topic = get_object_or_404(Topic, name__iexact=topic_name) column = topic.get_column() followers_ship = FollowShip.objects.filter(column=column).all( )[:TAG_FOLLOWS_NUM].select_related('userdata__user__userprofile__avatar') followers = [obj.userdata.user.userprofile for obj in followers_ship] if t == 'links': datas = topic.topic_links.filter( is_visible=True).all()[s:e].select_related( 'user__userprofile__avatar', 'domain') elif t == 'links-super': datas = datas = topic.topic_links.filter(is_visible=True).filter( is_boutique=True).all()[s:e].select_related( 'user__userprofile__avatar', 'domain') elif t == 'discusses': datas = topic.topic_discusses.filter(is_visible=True).order_by( '-last_active_time').all()[s:e].select_related( 'user__userprofile__avatar', 'last_active_user__userprofile', ) elif t == 'discusses-super': datas = topic.topic_discusses.filter(is_visible=True).filter( is_boutique=True).order_by( '-last_active_time').all()[s:e].select_related( 'user__userprofile__avatar', 'last_active_user__userprofile', ) elif t == 'followers': followers_ship = FollowShip.objects.filter(column=column).all( )[s:e].select_related('userdata__user__userprofile__avatar') datas = [(obj.userdata.user.userprofile, \ obj.column) for obj in followers_ship] else: raise Http404 if len(datas) < MESSAGES_PER_PAGE: next_page = False return render_to_response('topic/topic_home.html', { 'topic': topic, 'column': column, 't': t, 'followers': followers, 'datas': datas, }, context_instance=RequestContext(request))
def domain(request, domain_name, t='links'): ''' ''' pre_page, next_page, s, e = process_pager(request, limit=False) domain = get_object_or_404(Domain, domain__iexact=domain_name) column = domain.get_column() followers_ship = FollowShip.objects.filter( column=column).all( )[:TAG_FOLLOWS_NUM].select_related( 'userdata__user__userprofile__avatar') followers = [obj.userdata.user.userprofile for obj in followers_ship] if t == 'links': datas = domain.domain_links.filter( is_visible=True).all( )[s:e].select_related( 'user__userprofile__avatar', 'domain', ).prefetch_related( 'topics') elif t == 'super': datas = domain.domain_links.filter( is_visible=True).filter( is_boutique=True).all( )[s:e].select_related( 'user__userprofile__avatar', 'domain', ).prefetch_related( 'topics') elif t == 'followers': followers_ship = FollowShip.objects.filter( column=column).all( )[s:e].select_related( 'userdata__user__userprofile__avatar') datas = [(obj.userdata.user.userprofile, \ obj.column) for obj in followers_ship] else: raise Http404 if len(datas) < MESSAGES_PER_PAGE: next_page = False return render_to_response('domain/domain_home.html', {'domain': domain, 'column': column, 't': t, 'followers': followers, 'datas': datas,}, context_instance=RequestContext(request))
def domain(request, domain_name, t="links"): """ """ pre_page, next_page, s, e = process_pager(request, limit=False) domain = get_object_or_404(Domain, domain__iexact=domain_name) column = domain.get_column() followers_ship = ( FollowShip.objects.filter(column=column) .all()[:TAG_FOLLOWS_NUM] .select_related("userdata__user__userprofile__avatar") ) followers = [obj.userdata.user.userprofile for obj in followers_ship] if t == "links": datas = ( domain.domain_links.filter(is_visible=True) .all()[s:e] .select_related("user__userprofile__avatar", "domain") .prefetch_related("topics") ) elif t == "super": datas = ( domain.domain_links.filter(is_visible=True) .filter(is_boutique=True) .all()[s:e] .select_related("user__userprofile__avatar", "domain") .prefetch_related("topics") ) elif t == "followers": followers_ship = ( FollowShip.objects.filter(column=column).all()[s:e].select_related("userdata__user__userprofile__avatar") ) datas = [(obj.userdata.user.userprofile, obj.column) for obj in followers_ship] else: raise Http404 if len(datas) < MESSAGES_PER_PAGE: next_page = False return render_to_response( "domain/domain_home.html", {"domain": domain, "column": column, "t": t, "followers": followers, "datas": datas}, context_instance=RequestContext(request), )
def people(request, username, t='links'): ''' ''' pre_page, next_page, s, e = process_pager(request, limit=False) people = get_object_or_404(User, username__iexact=username) follows = people_follows(request, people) datas = [] if t == 'followees': datas = follows[1][s:e] elif t == 'followers': followers_ship = FollowShip.objects.filter( column=follows[4]).order_by('-time').all()[s:e].prefetch_related( 'userdata__user__userprofile__avatar', 'userdata__user__userprofile__columns', ) followers_d = [f.userdata for f in followers_ship] datas = [] for d in followers_d: datas.append( (d.user.userprofile, d.user.userprofile.columns.all()[0])) elif t == 'topics': datas = follows[2][s:e] elif t == 'domains': datas = follows[3][s:e] else: pass if t == 'followees' or t == 'followers' or t == 'topics' or t == 'domains': if len(datas) < MESSAGES_PER_PAGE: next_page = False return render_to_response('people/follows.html', { 'people': people, 'follows': follows, 't': t, 'datas': datas, 'pre': pre_page, 'next': next_page, }, context_instance=RequestContext(request)) if t == 'links': datas = people.user_links.filter( is_visible=True).all()[s:e].prefetch_related('domain', 'topics') elif t == 'discusses': datas = people.user_discusses.filter( is_visible=True).all()[s:e].prefetch_related('topics') elif t == 'comments': datas = people.user_comments.filter( is_visible=True).all()[s:e].prefetch_related( 'content_object__domain', 'parent_comment') elif t == 'shares': datas = people.user_shares.all()[s:e].prefetch_related( 'content_object__domain', 'content_object__user__userprofile', 'comment_object__domain', ) elif t == 'collections' and people == request.user: datas = people.user_collections.all()[s:e].prefetch_related( 'content_object__domain', 'content_object__user__userprofile', 'comment_object__domain', ) else: raise Http404 if len(datas) < MESSAGES_PER_PAGE: next_page = False return render_to_response('people/homepage.html', { 'people': people, 'follows': follows, 't': t, 'datas': datas, 'pre': pre_page, 'next': next_page, }, context_instance=RequestContext(request))
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))
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))
def topic(request, topic_name, t='links'): ''' ''' pre_page, next_page, s, e = process_pager(request, limit=False) topic = get_object_or_404(Topic, name__iexact=topic_name) column = topic.get_column() followers_ship = FollowShip.objects.filter( column=column).all( )[:TAG_FOLLOWS_NUM].select_related( 'userdata__user__userprofile__avatar') followers = [obj.userdata.user.userprofile for obj in followers_ship] if t == 'links': datas = topic.topic_links.filter( is_visible=True).all( )[s:e].select_related( 'user__userprofile__avatar', 'domain') elif t == 'links-super': datas = datas = topic.topic_links.filter( is_visible=True).filter( is_boutique=True).all( )[s:e].select_related( 'user__userprofile__avatar', 'domain') elif t == 'discusses': datas = topic.topic_discusses.filter( is_visible=True).order_by( '-last_active_time').all( )[s:e].select_related( 'user__userprofile__avatar', 'last_active_user__userprofile',) elif t == 'discusses-super': datas = topic.topic_discusses.filter( is_visible=True).filter( is_boutique=True).order_by( '-last_active_time').all( )[s:e].select_related( 'user__userprofile__avatar', 'last_active_user__userprofile',) elif t == 'followers': followers_ship = FollowShip.objects.filter( column=column).all( )[s:e].select_related( 'userdata__user__userprofile__avatar') datas = [(obj.userdata.user.userprofile, \ obj.column) for obj in followers_ship] else: raise Http404 if len(datas) < MESSAGES_PER_PAGE: next_page = False return render_to_response('topic/topic_home.html', {'topic': topic, 'column': column, 't': t, 'followers': followers, 'datas': datas,}, context_instance=RequestContext(request))
def people(request, username, t='links'): ''' ''' pre_page, next_page, s, e = process_pager(request, limit=False) people = get_object_or_404(User, username__iexact=username) follows = people_follows(request, people) datas = [] if t == 'followees': datas = follows[1][s:e] elif t == 'followers': followers_ship = FollowShip.objects.filter( column=follows[4]).order_by( '-time').all( )[s:e].prefetch_related( 'userdata__user__userprofile__avatar', 'userdata__user__userprofile__columns',) followers_d = [f.userdata for f in followers_ship] datas =[] for d in followers_d: datas.append((d.user.userprofile, d.user.userprofile.columns.all()[0])) elif t == 'topics': datas = follows[2][s:e] elif t == 'domains': datas = follows[3][s:e] else: pass if t == 'followees' or t == 'followers' or t == 'topics' or t == 'domains': if len(datas) < MESSAGES_PER_PAGE: next_page = False return render_to_response('people/follows.html', {'people': people, 'follows': follows, 't': t, 'datas': datas, 'pre': pre_page, 'next': next_page,}, context_instance=RequestContext(request)) if t == 'links': datas = people.user_links.filter(is_visible=True).all( )[s:e].prefetch_related( 'domain', 'topics') elif t == 'discusses': datas = people.user_discusses.filter(is_visible=True).all( )[s:e].prefetch_related( 'topics') elif t == 'comments': datas = people.user_comments.filter(is_visible=True).all( )[s:e].prefetch_related( 'content_object__domain', 'parent_comment') elif t == 'shares': datas = people.user_shares.all()[s:e].prefetch_related( 'content_object__domain', 'content_object__user__userprofile', 'comment_object__domain', ) elif t == 'collections' and people == request.user: datas = people.user_collections.all()[s:e].prefetch_related( 'content_object__domain', 'content_object__user__userprofile', 'comment_object__domain', ) else: raise Http404 if len(datas) < MESSAGES_PER_PAGE: next_page = False return render_to_response('people/homepage.html', {'people': people, 'follows': follows, 't': t, 'datas': datas, 'pre': pre_page, 'next': next_page,}, context_instance=RequestContext(request))
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))
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))