#NEWLINE# def home( request ) : #NEWLINE# #INDENT# page_view . send ( request . user , page_path = request . get_full_path ( ) ) #NEWLINE# if request . user . is_authenticated ( ) : #NEWLINE# #INDENT# page_view_objs = request . user . pageview_set . get_videos ( ) [ : 6 ] #NEWLINE# recent_videos = [ ] #NEWLINE# for obj in page_view_objs : #NEWLINE# #INDENT# if ( not ( obj . primary_object in recent_videos ) ) : #NEWLINE# #INDENT# recent_videos . append ( obj . primary_object ) #NEWLINE# #UNINDENT# #UNINDENT# recent_comments = Comment . objects . recent ( ) #NEWLINE# video_type = ContentType . objects . get_for_model ( Video ) #NEWLINE# popular_videos_list = PageView . objects . filter ( primary_content_type = video_type ) . values ( 'primary_object_id' ) . annotate ( the_count = Count ( 'primary_object_id' ) ) . order_by ( '-the_count' ) [ : 4 ] #NEWLINE# popular_videos = [ ] #NEWLINE# for item in popular_videos_list : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# new_video = Video . objects . get ( id = item [ 'primary_object_id' ] ) #NEWLINE# popular_videos . append ( new_video ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# random_videos = Video . objects . all ( ) . order_by ( '?' ) [ : 6 ] #NEWLINE# context = { #NEWLINE# #INDENT# 'random_videos' : random_videos , #NEWLINE# 'recent_videos' : recent_videos , #NEWLINE# 'recent_comments' : recent_videos , #NEWLINE# 'popular_videos' : popular_videos , #NEWLINE# #UNINDENT# } #NEWLINE# template = 'accounts/home_logged_in.html' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# featured_categories = Category . objects . get_featured ( ) #NEWLINE# featured_videos = Video . objects . get_featured ( ) #NEWLINE# login_form = LoginForm ( ) #NEWLINE# register_form = RegisterForm ( ) #NEWLINE# template = 'accounts/home_visitor.html' #NEWLINE# context = { #NEWLINE# #INDENT# 'register_form' : register_form , #NEWLINE# 'login_form' : login_form , #NEWLINE# 'featured_videos' : featured_videos , #NEWLINE# 'featured_categories' : featured_categories , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# return render ( request , template , context )