def _get_stats(user, filter=filter): """ Helper to _get_stats """ if filter == "following": tot_time, num_history = profile_stat_gen( user, filter=filter, username="") else: tot_time, num_history = profile_stat_gen(user, username="") return tot_time, num_history
def notifications(request): user = get_object_or_404(User, username=request.user.username) userprof = UserProfile.objects.get(user=user) confirmed = userprof.confirmed if not confirmed: return redirect('/consent') empty_search_msg = EMPTY_SEARCH_MSG['notifications'] # stats tot_time, item_count = profile_stat_gen(user) fav_data = FavData.objects.get(user=user) num_history = EyeHistory.objects.filter(user=user).count() is_online = online_user(user=user) following_users = user.profile.follows.all() following_count = following_users.count() follower_count = UserProfile.objects.filter(follows=user.profile).count() notifications = notification_renderer(user, empty_search_msg) nots = Notification.objects.filter(recipient=user, seen=False) for n in nots: n.seen = True n.save() template_dict = { "username": user.username, "following_count": following_count, "follower_count": follower_count, "is_online": is_online, "num_history": num_history, "notifications": notifications, "tot_time": tot_time, "item_count": item_count, "fav_data": fav_data, } return _template_values(request, page_title="notifications", navbar='notify', sub_navbar="subnav_data", not_count=0, **template_dict)
def following_data(request, username=None): if request.user.username == username: username = None username, follows, profile_user, empty_search_msg, nav_bar = _profile_info( request.user, username, following=True) # stats tot_time, item_count = profile_stat_gen(profile_user) fav_data = FavData.objects.get(user=profile_user) num_history = EyeHistory.objects.filter(user=profile_user).count() is_online = online_user(user=profile_user) following_users = profile_user.profile.follows.all() following_count = following_users.count() follower_count = UserProfile.objects.filter( follows=profile_user.profile).count() follow = follow_list(following_users, profile_user, empty_search_msg) template_dict = { 'username': profile_user.username, 'following_count': following_count, 'follower_count': follower_count, "profile_user": profile_user, "empty_search_msg": empty_search_msg, "follows": str(follows), "is_online": is_online, 'follow_list': follow, "num_history": num_history, "tot_time": tot_time, "item_count": item_count, "fav_data": fav_data, } return _template_values(request, page_title="following list", navbar=nav_bar, sub_navbar="subnav_data", **template_dict)
def profile_data(request, username=None): if request.user.is_authenticated(): user = get_object_or_404(User, username=request.user.username) userprof = UserProfile.objects.get(user=user) confirmed = userprof.confirmed if not confirmed: return redirect('/consent') else: user = None userprof = None """ Own profile page """ username, follows, profile_user, empty_search_msg, nav_bar = _profile_info( user, username) get_dict, query, date, sort, filter = _get_query(request) get_dict["orderBy"] = "end_time" get_dict["direction"] = "hl" get_dict["filter"] = "" get_dict["page"] = request.GET.get("page", 1) get_dict["username"] = profile_user.username get_dict["sort"] = "time" hist, history_stream = live_stream_query_manager(get_dict, request.user, empty_search_msg=empty_search_msg) # stats tot_time, item_count = profile_stat_gen(profile_user) fav_data = FavData.objects.get(user=profile_user) num_history = EyeHistory.objects.filter(user=profile_user).count() is_online = online_user(user=profile_user) following_count = profile_user.profile.follows.count() follower_count = UserProfile.objects.filter( follows=profile_user.profile).count() today = datetime.now() - timedelta(hours=24) day_count = hist.filter( start_time__gt=today ).values('url', 'title').annotate( num_urls=Sum('total_time') ).order_by('-num_urls')[:3] day_domains = hist.filter( start_time__gt=today ).values('domain' ).annotate(num_domains=Sum('total_time') ).order_by('-num_domains')[:5] day_chart = {} for domain in day_domains: day_chart[domain['domain']] = domain['num_domains'] last_week = today - timedelta(days=7) week_count = hist.filter( start_time__gt=last_week ).values('url', 'title' ).annotate(num_urls=Sum('total_time') ).order_by('-num_urls')[:3] week_domains = hist.filter( start_time__gt=last_week ).values('domain' ).annotate(num_domains=Sum('total_time') ).order_by('-num_domains')[:5] week_chart = {} for domain in week_domains: week_chart[domain['domain']] = domain['num_domains'] template_dict = { 'username': profile_user.username, 'following_count': following_count, 'follower_count': follower_count, "profile_user": profile_user, "history_stream": history_stream, "empty_search_msg": empty_search_msg, "follows": str(follows), "is_online": is_online, "num_history": num_history, "tot_time": tot_time, "item_count": item_count, "fav_data": fav_data, "query": query, "date": date, 'day_articles': day_count, 'week_articles': week_count, 'day_chart': json.dumps(day_chart), 'week_chart': json.dumps(week_chart), } return _template_values(request, page_title="profile history", navbar=nav_bar, sub_navbar="subnav_data", **template_dict)
def profile_data(request, username=None): if request.user.is_authenticated(): user = get_object_or_404(User, username=request.user.username) userprof = UserProfile.objects.get(user=user) confirmed = userprof.confirmed if not confirmed: return redirect('/consent') else: user = None userprof = None """ Own profile page """ username, follows, profile_user, empty_search_msg, nav_bar = _profile_info( user, username) get_dict, query, date, sort, filter = _get_query(request) get_dict["orderBy"] = "end_time" get_dict["direction"] = "hl" get_dict["filter"] = "" get_dict["page"] = request.GET.get("page", 1) get_dict["username"] = profile_user.username get_dict["sort"] = "time" hist, history_stream = live_stream_query_manager( get_dict, request.user, empty_search_msg=empty_search_msg) # stats tot_time, item_count = profile_stat_gen(profile_user) fav_data = FavData.objects.get(user=profile_user) num_history = EyeHistory.objects.filter(user=profile_user).count() is_online = online_user(user=profile_user) following_count = profile_user.profile.follows.count() follower_count = UserProfile.objects.filter( follows=profile_user.profile).count() today = datetime.now() - timedelta(hours=24) day_count = hist.filter(start_time__gt=today).values( 'url', 'title').annotate(num_urls=Sum('total_time')).order_by('-num_urls')[:3] day_domains = hist.filter(start_time__gt=today).values('domain').annotate( num_domains=Sum('total_time')).order_by('-num_domains')[:5] day_chart = {} for domain in day_domains: day_chart[domain['domain']] = domain['num_domains'] last_week = today - timedelta(days=7) week_count = hist.filter(start_time__gt=last_week).values( 'url', 'title').annotate(num_urls=Sum('total_time')).order_by('-num_urls')[:3] week_domains = hist.filter( start_time__gt=last_week).values('domain').annotate( num_domains=Sum('total_time')).order_by('-num_domains')[:5] week_chart = {} for domain in week_domains: week_chart[domain['domain']] = domain['num_domains'] template_dict = { 'username': profile_user.username, 'following_count': following_count, 'follower_count': follower_count, "profile_user": profile_user, "history_stream": history_stream, "empty_search_msg": empty_search_msg, "follows": str(follows), "is_online": is_online, "num_history": num_history, "tot_time": tot_time, "item_count": item_count, "fav_data": fav_data, "query": query, "date": date, 'day_articles': day_count, 'week_articles': week_count, 'day_chart': json.dumps(day_chart), 'week_chart': json.dumps(week_chart), } return _template_values(request, page_title="profile history", navbar=nav_bar, sub_navbar="subnav_data", **template_dict)