Back to index

moin  1.9.0~rc2
Functions
MoinMoin.stats.languages Namespace Reference

Functions

def linkto
def get_data
def used_languages

Function Documentation

Definition at line 19 of file languages.py.

00019 
00020 def get_data(request):
00021     _ = request.getText
00022     data = {}
00023 
00024     users = user.getUserList(request)
00025     for userID in users:
00026         current_user = user.User(request, userID)
00027         if current_user.language == u'':
00028             # User is using <Browser setting>, attempting to look up if we've managed to store the real language...
00029             try:
00030                 data[current_user.real_language] = data.get(current_user.real_language, 0) + 1
00031             except AttributeError: # Couldn't find the used language at all...
00032                 data[u''] = data.get(u'', 0) + 1
00033         else:
00034             data[current_user.language] = data.get(current_user.language, 0) + 1
00035     if u'' in data:
00036         data[u'browser'] = data.pop(u'') # In case we have users whose languages aren't detectable.
00037     data = [(cnt, current_user_language) for current_user_language, cnt in data.items()]
00038     data.sort()
00039     data.reverse()
00040     return data
00041 

Here is the caller graph for this function:

def MoinMoin.stats.languages.linkto (   pagename,
  request,
  params = '' 
)

Definition at line 15 of file languages.py.

00015 
00016 def linkto(pagename, request, params=''):
00017     return used_languages(request)
00018 

Here is the call graph for this function:

Definition at line 42 of file languages.py.

00042 
00043 def used_languages(request):
00044     from MoinMoin.util.dataset import TupleDataset, Column
00045     from MoinMoin.widget.browser import DataBrowserWidget
00046 
00047     _ = request.getText
00048 
00049     data = get_data(request)
00050 
00051     total = 0.0
00052     for cnt, lang in data:
00053         total += cnt
00054 
00055 
00056     languages = TupleDataset()
00057     languages.columns = [Column('language', label=_("Language"), align='left'),
00058                          Column('value', label='%', align='right')]
00059 
00060     cnt_printed = 0
00061     data = data[:10]
00062 
00063     # Preparing "<Browser setting>"
00064     browserlang = _('<Browser setting>')
00065     browserlang = browserlang[1:len(browserlang) - 1].capitalize()
00066     if total:
00067         for cnt, lang in data:
00068             try:
00069                 if lang == u'browser':
00070                     languages.addRow((browserlang, "%(percent).2f%% (%(count)d)" % {
00071                         'percent': 100.0 * cnt / total,
00072                         'count': cnt}))
00073                 else:
00074                     lang = i18n.wikiLanguages()[lang]['x-language-in-english']
00075                     languages.addRow((lang, "%(percent).2f%% (%(count)d)" % {
00076                         'percent': 100.0 * cnt / total,
00077                         'count': cnt}))
00078                 cnt_printed += cnt
00079             except UnicodeError:
00080                 pass
00081         if total > cnt_printed:
00082             languages.addRow((_('Others'), "%(percent).2f%% (%(count)d)" % {
00083                 'percent': 100.0 * (total - cnt_printed) / total,
00084                 'count': total - cnt_printed}))
00085 
00086     else: # If we don't have any users, we can safely assume that the only real user is the visitor (who is normally ignored, though) who is using "Browser setting"
00087         languages.addRow((browserlang, "100% (1)"))
00088 
00089     table = DataBrowserWidget(request)
00090     table.setData(languages)
00091     return table.render(method="GET")
00092 

Here is the call graph for this function:

Here is the caller graph for this function: