def create_activity_cache(): hours = 24 if not settings.DEBUG else 1000 print('activity.1') view = 'activity' keyword = '24hcount' data = Activity.objects.filter(created_on__gt=timezone.now() - timezone.timedelta(hours=hours)).count() JSONStore.objects.filter(view=view, key=keyword).all().delete() JSONStore.objects.create( view=view, key=keyword, data=json.loads(json.dumps(data, cls=EncodeAnything)), ) print('activity.2') for tag in tags: keyword = tag[2] data = get_specific_activities( keyword, False, None, None).filter(created_on__gt=timezone.now() - timezone.timedelta(hours=hours)).count() JSONStore.objects.filter(view=view, key=keyword).all().delete() JSONStore.objects.create( view=view, key=keyword, data=json.loads(json.dumps(data, cls=EncodeAnything)), )
def latest_activities(user): from retail.views import get_specific_activities from townsquare.tasks import increment_view_counts cutoff_date = timezone.now() - timezone.timedelta(days=1) activities = get_specific_activities('connect', 0, user, 0)[:4] activities_pks = list(activities.values_list('pk', flat=True)) increment_view_counts.delay(activities_pks) return activities
def create_activity_cache(): print('activity') view = 'activity' from retail.views import get_specific_activities from townsquare.views import tags all_tags = tags + [ [None, None, 'everywhere'], [None, None, 'kudos'], [None, None, 'connects'], ] hackathons = HackathonEvent.objects.all() for hackathon in hackathons: tab = f'hackathon:{hackathon.pk}' all_tags.append([None, None, tab]) for tag in all_tags: keyword = tag[2] data = get_specific_activities(keyword, False, None, None) JSONStore.objects.filter(view=view, key=keyword).all().delete() JSONStore.objects.create( view=view, key=keyword, data=list(data.order_by('-pk').values_list('pk', flat=True)[:10]), )
def get_sidebar_tabs(request): # setup tabs hours = 24 hackathon_tabs = [] tabs = [{ 'title': f"Everywhere", 'slug': 'everywhere', 'helper_text': f'The activity feed items everywhere in the Gitcoin network', 'badge': get_amount_unread('everywhere', request), }] default_tab = 'everywhere' if request.user.is_authenticated: num_business_relationships = len( set(get_my_earnings_counter_profiles(request.user.profile.pk))) if num_business_relationships: key = 'my_tribes' new_tab = { 'title': f"Relationships", 'slug': key, 'helper_text': f'Activity from the users who you\'ve done business with Gitcoin', 'badge': max_of_ten( get_specific_activities(key, False, request.user, request.session.get(key, 0)).count()) if request.GET.get('tab') != key else 0 } tabs = [new_tab] + tabs default_tab = 'my_tribes' num_grants_relationships = (len( set(get_my_grants(request.user.profile)))) if num_grants_relationships: key = 'grants' new_tab = { 'title': f'Grants', 'slug': key, 'helper_text': f'Activity on the Grants you\'ve created or funded.', 'badge': max_of_ten( get_specific_activities(key, False, request.user, request.session.get(key, 0)).count()) if request.GET.get('tab') != key else 0 } tabs = [new_tab] + tabs default_tab = 'grants' num_favorites = request.user.favorites.all().count() if num_favorites: key = 'my_favorites' activities = get_specific_activities(key, False, request.user, request.session.get( key, 0)).count() new_tab = { 'title': f"My Favorites", 'slug': key, 'helper_text': f'Activity that you marked as favorite', 'badge': max_of_ten(activities) if request.GET.get('tab') != key else 0 } tabs = [new_tab] + tabs default_tab = 'my_favorites' threads_last_24_hours = max_of_ten( request.user.profile.subscribed_threads.filter( pk__gt=request.session.get('my_threads', 0)).count() ) if request.GET.get('tab') != 'my_threads' else 0 threads = { 'title': f"My Threads", 'slug': f'my_threads', 'helper_text': f'The Threads that you\'ve liked, commented on, or sent a tip upon on Gitcoin since you last checked.', 'badge': threads_last_24_hours } tabs = [threads] + tabs default_tab = 'connect' connect = { 'title': f"Connect", 'slug': f'connect', 'helper_text': f'The announcements, requests for help, kudos jobs, mentorship, or other connective requests on Gitcoin.', 'badge': get_amount_unread('connect', request), } tabs = [connect] + tabs connect = { 'title': f"Kudos", 'slug': f'kudos', 'helper_text': f'The Kudos that have been sent by Gitcoin community members, to show appreciation for one aother.', 'badge': get_amount_unread('kudos', request), } tabs = tabs + [connect] start_date = timezone.now() + timezone.timedelta(days=10) end_date = timezone.now() - timezone.timedelta(days=7) hackathons = HackathonEvent.objects.filter(start_date__lt=start_date, end_date__gt=end_date, visible=True) if hackathons.count(): for hackathon in hackathons: connect = { 'title': hackathon.name, 'slug': f'hackathon:{hackathon.pk}', 'helper_text': f'Activity from the {hackathon.name} Hackathon.', } hackathon_tabs = [connect] + hackathon_tabs # set tab if request.COOKIES.get('tab'): all_tabs = [tab.get('slug') for tab in tabs] if request.COOKIES.get('tab') in all_tabs: default_tab = request.COOKIES.get('tab') tab = request.GET.get('tab', default_tab) is_search = "activity:" in tab or "search-" in tab if is_search: tabs.append({ 'title': "Search", 'slug': tab, }) search = '' if "search-" in tab: search = tab.split('-')[1] return tabs, tab, is_search, search, hackathon_tabs