def index(request): # TODO: temporary until town square is approved for non-staff use if not is_user_townsquare_enabled(request.user): from retail.views import index as regular_homepage return regular_homepage(request) return town_square(request)
def index(request): # TODO: temporary until town square is approved for non-staff use if not is_user_townsquare_enabled(request.user): from retail.views import index as regular_homepage return regular_homepage(request) # setup tabas tabs = [{ 'title': "My Tribes", 'slug': 'my_tribes', }, { 'title': "Everywhere", 'slug': 'everywhere', }] add_keywords = False for keyword in request.user.profile.keywords: if add_keywords: tabs.append({ 'title': keyword.title(), 'slug': f'keyword-{keyword}', }) default_tab = 'my_tribes' if request.user.is_authenticated else 'everywhere' 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] # get offers offers_by_category = {} for key in ['daily', 'weekly', 'monthly']: next_time_available = get_next_time_available(key) offer = Offer.objects.current().filter(key=key).order_by('-pk').first() if request.user.is_authenticated: if request.user.profile.offeractions.filter(what='click', offer=offer): offer = None offers_by_category[key] = { 'offer': offer, 'time': next_time_available.strftime('%Y-%m-%dT%H:%M:%SZ'), } # subscriber info is_subscribed = False if request.user.is_authenticated: email_subscriber = request.user.profile.email_subscriptions.first() if email_subscriber: is_subscribed = email_subscriber.should_send_email_type_to( 'new_bounty_notifications') # announcements announcements = Announcement.objects.current() # title title = 'Home' desc = 'View the recent activity on the Gitcoin network' if "activity:" in tab: try: pk = int(tab.split(':')[1]) activity = Activity.objects.get(pk=pk) title = f"@{activity.profile.handle}'s comment on Gitcoin " desc = f"foo - {activity.text}" except: pass # render page context context = { 'title': title, 'card_desc': desc, 'nav': 'home', 'target': f'/activity?what={tab}', 'tab': tab, 'tabs': tabs, 'search': search, 'tags': [ ('#announce', 'bullhorn'), ('#mentor', 'terminal'), ('#jobs', 'code'), ('#help', 'laptop-code'), ('#other', 'briefcase'), ], 'announcements': announcements, 'is_subscribed': is_subscribed, 'offers_by_category': offers_by_category, } return TemplateResponse(request, 'townsquare/index.html', context)