def context_extra(request): # Get number of new messages, number of uploaded sounds pending moderation and number of sounds to moderate # variables so we can use them directly in base.html without a templatetag new_tickets_count = -1 # Initially set to -1 (to distinguish later users that can not moderate) num_pending_sounds = 0 num_messages = 0 if request.user.is_authenticated(): if request.user.has_perm('tickets.can_moderate'): new_tickets_count = new_sound_tickets_count() num_pending_sounds = request.user.profile.num_sounds_pending_moderation( ) num_messages = Message.objects.filter(user_to=request.user, is_archived=False, is_sent=False, is_read=False).count() return { 'media_url': settings.MEDIA_URL, 'request': request, 'GOOGLE_API_KEY': settings.GOOGLE_API_KEY, 'last_restart_date': settings.LAST_RESTART_DATE, 'new_tickets_count': new_tickets_count, 'num_pending_sounds': num_pending_sounds, 'num_messages': num_messages, }
def context_extra(request): # Get number of new messages, number of uploaded sounds pending moderation and number of sounds to moderate # variables so we can use them directly in base.html without a templatetag new_tickets_count = -1 # Initially set to -1 (to distinguish later users that can not moderate) num_pending_sounds = 0 num_messages = 0 if request.user.is_authenticated: if request.user.has_perm('tickets.can_moderate'): new_tickets_count = new_sound_tickets_count() num_pending_sounds = request.user.profile.num_sounds_pending_moderation( ) num_messages = Message.objects.filter(user_to=request.user, is_archived=False, is_sent=False, is_read=False).count() # Determine if anniversary special css and js content should be loaded # Animations will only be shown during the day of the anniversary # Special logo will be shown during 2 weeks after the anniversary load_anniversary_content = \ datetime.datetime(2020, 4, 5, 0, 0) <= datetime.datetime.today() <= datetime.datetime(2020, 4, 20) or \ request.GET.get('anniversary', '0') == '1' return { 'media_url': settings.MEDIA_URL, 'request': request, 'last_restart_date': settings.LAST_RESTART_DATE, 'new_tickets_count': new_tickets_count, 'num_pending_sounds': num_pending_sounds, 'num_messages': num_messages, 'recaptcha_public_key': settings.RECAPTCHA_PUBLIC_KEY, 'load_anniversary_content': load_anniversary_content }
def context_extra(request): # Get number of new messages, number of uploaded sounds pending moderation and number of sounds to moderate # variables so we can use them directly in base.html without a templatetag new_tickets_count = -1 # Initially set to -1 (to distinguish later users that can not moderate) num_pending_sounds = 0 num_messages = 0 if request.user.is_authenticated(): if request.user.has_perm('tickets.can_moderate'): new_tickets_count = new_sound_tickets_count() num_pending_sounds = request.user.profile.num_sounds_pending_moderation() num_messages = Message.objects.filter(user_to=request.user, is_archived=False, is_sent=False, is_read=False).count() return {'media_url': settings.MEDIA_URL, 'request': request, 'GOOGLE_API_KEY': settings.GOOGLE_API_KEY, 'last_restart_date': settings.LAST_RESTART_DATE, 'new_tickets_count': new_tickets_count, 'num_pending_sounds': num_pending_sounds, 'num_messages': num_messages, }
def home(request): user = request.user # expand tags because we will definitely be executing, and otherwise tags is called multiple times tags = list(user.profile.get_tagcloud()) latest_sounds = Sound.objects.select_related().filter(user=user,processing_state="OK",moderation_state="OK")[0:5] unprocessed_sounds = Sound.objects.select_related().filter(user=user).exclude(processing_state="OK") unmoderated_sounds = Sound.objects.select_related().filter(user=user,processing_state="OK").exclude(moderation_state="OK") latest_packs = Pack.objects.select_related().filter(user=user, sound__moderation_state="OK", sound__processing_state="OK").annotate(num_sounds=Count('sound'), last_update=Max('sound__created')).filter(num_sounds__gt=0).order_by("-last_update")[0:5] unmoderated_packs = Pack.objects.select_related().filter(user=user).exclude(sound__moderation_state="OK", sound__processing_state="OK").annotate(num_sounds=Count('sound'), last_update=Max('sound__created')).filter(num_sounds__gt=0).order_by("-last_update")[0:5] packs_without_sounds = Pack.objects.select_related().filter(user=user).annotate(num_sounds=Count('sound')).filter(num_sounds=0) # TODO: refactor: This list of geotags is only used to determine if we need to show the geotag map or not latest_geotags = Sound.public.filter(user=user).exclude(geotag=None)[0:10].exists() google_api_key = settings.GOOGLE_API_KEY home = True if home and request.user.has_perm('tickets.can_moderate'): new_sounds = new_sound_tickets_count() new_support = new_support_tickets_count() if home and request.user.has_perm('forum.can_moderate_forum'): new_posts = Post.objects.filter(moderation_state='NM').count() return render_to_response('accounts/account.html', locals(), context_instance=RequestContext(request))
def new_sound_tickets_count(): return TicketViews.new_sound_tickets_count()