def test_unknown(self): """ Test that when the current locale is not supported by Babel, it defaults to en-US. """ activate('fy') eq_(Locale('en', 'US'), current_locale())
def babel_date(date, format='long'): """ Format a date properly for the current locale. Format can be one of 'short', 'medium', 'long', or 'full'. """ locale = current_locale() return format_date(date, format, locale)
def dashboard(request, template, context=None): """ Performs common operations needed by pages using the 'dashboard' template. """ if context is None: context = {} locale = current_locale() # Set context variables needed by all dashboard pages context['newsitem'] = NewsItem.objects.current() context['user_has_created_badges'] = request.user.has_created_badges() if context['user_has_created_badges']: clicks_total = ClickStats.objects.total_for_user(request.user) # Add Facebook clicks to total fb_user = request.user.get_linked_account() if fb_user is not None: clicks_total += FacebookClickStats.objects.total_for_user(fb_user) context['user_clicks_total'] = format_number(clicks_total, locale=locale) # Leaderboard try: context['show_leaderboard'] = True context['leaderboard'] = (Leaderboard.objects .top_users(settings.LEADERBOARD_SIZE)) context['user_standing'] = (Leaderboard.objects .get(user=request.user)) except Leaderboard.DoesNotExist: context['show_leaderboard'] = False return jingo.render(request, template, context)
def month_year_picker(request): """Adds localized date info for the month-year picker widget.""" locale = current_locale() return { 'mypicker_months_short': get_month_names('abbreviated', locale=locale), 'mypicker_months_long': get_month_names('wide', locale=locale) }
def month_year_picker(request): """Adds localized date info for the month-year picker widget.""" locale = current_locale() return { "mypicker_months_short": get_month_names("abbreviated", locale=locale), "mypicker_months_long": get_month_names("wide", locale=locale), }
def month_stats_ajax(request): user_total = ClickStats.objects.total_for_user_period( request.user, request.POST['month'], request.POST['year']) site_avg = ClickStats.objects.average_for_period( request.POST['month'], request.POST['year']) locale = current_locale() results = {'user_total': format_number(user_total, locale=locale), 'site_avg': format_number(site_avg, locale=locale)} return HttpResponse(json.dumps(results), mimetype='application/json')
def month_stats_ajax(request): user_total = ClickStats.objects.total_for_user_period( request.user, request.POST['month'], request.POST['year']) site_avg = ClickStats.objects.average_for_period(request.POST['month'], request.POST['year']) locale = current_locale() results = { 'user_total': format_number(user_total, locale=locale), 'site_avg': format_number(site_avg, locale=locale) } return HttpResponse(json.dumps(results), mimetype='application/json')
def month_stats_ajax(request, month, year): user_total = ClickStats.objects.total_for_user_period(request.user, month, year) site_avg = ClickStats.objects.average_for_period(month, year) locale = current_locale() results = {'user_total': format_number(user_total, locale=locale), 'site_avg': format_number(site_avg, locale=locale)} # Get linked Facebook click count if available. facebook_user = request.user.get_linked_account() if facebook_user is not None: fb_total = FacebookClickStats.objects.total_for_month(facebook_user, year, month) results['fb_total'] = format_number(fb_total, locale=locale) return HttpResponse(json.dumps(results), mimetype='application/json')
def month_stats_ajax(request, month, year): # Check for placeholder values and return a 400 if they are present. if month == ':month:' or year == ':year:': return JSONResponseBadRequest({'error': 'Invalid year/month value.'}) user_total = ClickStats.objects.total_for_user_period(request.user, month, year) site_avg = ClickStats.objects.average_for_period(month, year) locale = current_locale() results = {'user_total': format_number(user_total, locale=locale), 'site_avg': format_number(site_avg, locale=locale)} # Get linked Facebook click count if available. facebook_user = request.user.get_linked_account() if facebook_user is not None: fb_total = FacebookClickStats.objects.total_for_month(facebook_user, year, month) results['fb_total'] = format_number(fb_total, locale=locale) return JSONResponse(results)
def dashboard(request, template, context=None): """ Performs common operations needed by pages using the 'dashboard' template. """ if context is None: context = {} locale = current_locale() # Set context variables needed by all dashboard pages context['newsitem'] = NewsItem.objects.current() context['user_has_created_badges'] = request.user.has_created_badges() if context['user_has_created_badges']: clicks_total = ClickStats.objects.total_for_user(request.user) context['user_clicks_total'] = format_number(clicks_total, locale=locale) # Statistics Summary months_short = get_month_names('abbreviated', locale=locale) months_full = get_month_names('wide', locale=locale) months_short_list = [name for k, name in months_short.items()] months_full_list = [name for k, name in months_full.items()] context['months_short'] = months_short.items() context['months_full_list_json'] = json.dumps(months_full_list) context['months_short_list_json'] = json.dumps(months_short_list) # Leaderboard try: context['show_leaderboard'] = True context['leaderboard'] = (Leaderboard.objects .top_users(settings.LEADERBOARD_SIZE)) context['user_standing'] = (Leaderboard.objects .get(user=request.user)) except Leaderboard.DoesNotExist: context['show_leaderboard'] = False return jingo.render(request, template, context)
def dashboard(request, template, context=None): """ Performs common operations needed by pages using the 'dashboard' template. """ if context is None: context = {} locale = current_locale() # Set context variables needed by all dashboard pages context['newsitem'] = NewsItem.objects.current() context['user_has_created_badges'] = request.user.has_created_badges() if context['user_has_created_badges']: clicks_total = ClickStats.objects.total_for_user(request.user) context['user_clicks_total'] = format_number(clicks_total, locale=locale) # Statistics Summary months_short = get_month_names('abbreviated', locale=locale) months_full = get_month_names('wide', locale=locale) months_short_list = [name for k, name in months_short.items()] months_full_list = [name for k, name in months_full.items()] context['months_short'] = months_short.items() context['months_full_list_json'] = json.dumps(months_full_list) context['months_short_list_json'] = json.dumps(months_short_list) # Leaderboard try: context['show_leaderboard'] = True context['leaderboard'] = (Leaderboard.objects.top_users( settings.LEADERBOARD_SIZE)) context['user_standing'] = (Leaderboard.objects.get( user=request.user)) except Leaderboard.DoesNotExist: context['show_leaderboard'] = False return jingo.render(request, template, context)
def month_stats_ajax(request, month, year): # Check for placeholder values and return a 400 if they are present. if month == ':month:' or year == ':year:': return JSONResponseBadRequest({'error': 'Invalid year/month value.'}) user_total = ClickStats.objects.total_for_user_period( request.user, month, year) site_avg = ClickStats.objects.average_for_period(month, year) locale = current_locale() results = { 'user_total': format_number(user_total, locale=locale), 'site_avg': format_number(site_avg, locale=locale) } # Get linked Facebook click count if available. facebook_user = request.user.get_linked_account() if facebook_user is not None: fb_total = FacebookClickStats.objects.total_for_month( facebook_user, year, month) results['fb_total'] = format_number(fb_total, locale=locale) return JSONResponse(results)
def dashboard(request, template, context=None): """ Performs common operations needed by pages using the 'dashboard' template. """ if context is None: context = {} locale = current_locale() # Set context variables needed by all dashboard pages context['newsitem'] = NewsItem.objects.current() context['user_has_created_badges'] = request.user.has_created_badges() context['newsletter_form'] = NewsletterForm() if context['user_has_created_badges']: clicks_total = ClickStats.objects.total_for_user(request.user) # Add Facebook clicks to total fb_user = request.user.get_linked_account() if fb_user is not None: clicks_total += FacebookClickStats.objects.total_for_user(fb_user) context['user_clicks_total'] = format_number(clicks_total, locale=locale) # Leaderboard try: context['show_leaderboard'] = True context['leaderboard'] = (Leaderboard.objects.top_users( settings.LEADERBOARD_SIZE)) context['user_standing'] = (Leaderboard.objects.get( user=request.user)) except Leaderboard.DoesNotExist: context['show_leaderboard'] = False return jingo.render(request, template, context)
def babel_number(number): """Format a number properly for the current locale.""" locale = current_locale() return format_number(number, locale)
def test_basic(self): """Test that the currently locale is correctly returned.""" activate('fr') eq_(Locale('fr'), current_locale())