# HG changeset patch # User Marcin Kuzminski # Date 2012-01-12 22:18:10 # Node ID a3efaaa6ed4fccaae7b868d7354e2bb038f7c42d # Parent 10e6c850d4cc5f007041d794f92ed269dd2b0926 fixes issue #271 - OrderedDict serialization sometimes failed due to how odict is implemented. Dropped usage of it for a simple tuple diff --git a/rhodecode/controllers/summary.py b/rhodecode/controllers/summary.py --- a/rhodecode/controllers/summary.py +++ b/rhodecode/controllers/summary.py @@ -154,11 +154,9 @@ class SummaryController(BaseRepoControll "desc": LANGUAGES_EXTENSIONS_MAP.get(x)}) for x, y in lang_stats_d.items()) - c.trending_languages = json.dumps(OrderedDict( - sorted(lang_stats, reverse=True, - key=lambda k: k[1])[:10] - ) - ) + c.trending_languages = json.dumps( + sorted(lang_stats, reverse=True, key=lambda k: k[1])[:10] + ) last_rev = stats.stat_on_revision + 1 c.repo_last_rev = c.rhodecode_repo.count()\ if c.rhodecode_repo.revisions else 0 diff --git a/rhodecode/lib/compat.py b/rhodecode/lib/compat.py --- a/rhodecode/lib/compat.py +++ b/rhodecode/lib/compat.py @@ -87,6 +87,7 @@ class _Nil(object): _nil = _Nil() + class _odict(object): """Ordered dict data structure, with O(1) complexity for dict operations that modify one element. @@ -146,7 +147,7 @@ class _odict(object): dict_impl = self._dict_impl() try: dict_impl.__getitem__(self, key)[1] = val - except KeyError, e: + except KeyError: new = [dict_impl.__getattribute__(self, 'lt'), val, _nil] dict_impl.__setitem__(self, key, new) if dict_impl.__getattribute__(self, 'lt') == _nil: @@ -158,7 +159,7 @@ class _odict(object): def __delitem__(self, key): dict_impl = self._dict_impl() - pred, _ , succ = self._dict_impl().__getitem__(self, key) + pred, _, succ = self._dict_impl().__getitem__(self, key) if pred == _nil: dict_impl.__setattr__(self, 'lh', succ) else: @@ -351,6 +352,7 @@ class _odict(object): dict_impl.__getattribute__(self, 'lt'), dict_impl.__repr__(self)) + class OrderedDict(_odict, dict): def _dict_impl(self): diff --git a/rhodecode/templates/summary/summary.html b/rhodecode/templates/summary/summary.html --- a/rhodecode/templates/summary/summary.html +++ b/rhodecode/templates/summary/summary.html @@ -295,33 +295,35 @@ YUE.on(['download_options','archive_subr var data = ${c.trending_languages|n}; var total = 0; var no_data = true; -for (k in data){ - total += data[k].count; - no_data = false; -} var tbl = document.createElement('table'); tbl.setAttribute('class','trending_language_tbl'); var cnt = 0; -for (k in data){ + +for (var i=0;i2; var tr = document.createElement('tr'); if (hide){ tr.setAttribute('style','display:none'); tr.setAttribute('class','stats_hidden'); } - var percentage = Math.round((data[k].count/total*100),2); - var value = data[k].count; + var k = data[i][0]; + var obj = data[i][1]; + var percentage = Math.round((obj.count/total*100),2); + var td1 = document.createElement('td'); td1.width = 150; var trending_language_label = document.createElement('div'); - trending_language_label.innerHTML = data[k].desc+" ("+k+")"; + trending_language_label.innerHTML = obj.desc+" ("+k+")"; td1.appendChild(trending_language_label); var td2 = document.createElement('td'); td2.setAttribute('style','padding-right:14px !important'); var trending_language = document.createElement('div'); - var nr_files = value+" ${_('files')}"; + var nr_files = obj.count+" ${_('files')}"; trending_language.title = k+" "+nr_files;