# HG changeset patch # User veltr # Date 1349972565 -7200 # Node ID a46461f8a74fce493baf1f0efd46e3a7da51fa5c # Parent e6675a5b21954f3965e897c4b88360e7878fa2b6 Separated Thesaurus and WP Categories diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/static/hdalab/css/cattree.css --- a/web/hdalab/static/hdalab/css/cattree.css Thu Oct 11 15:49:57 2012 +0200 +++ b/web/hdalab/static/hdalab/css/cattree.css Thu Oct 11 18:22:45 2012 +0200 @@ -19,10 +19,6 @@ background: #ffffff; width: 260px; font-size: 14px; font-weight: bold; margin: 5px 0; } -.hidden { - display: none; -} - .results { margin-top: 30px; } @@ -54,119 +50,3 @@ div.cattree { margin: 10px 0 0 320px; } - -.cattree p.theme { - color: #000080; -} - -.cattree .content p.title { - font-weight: bold; cursor: pointer; -} - -.cattree .content p.title:before { - font-weight: normal; -} - -.cattree .score_0, .cattree .score_1 { - color: #80d080; -} - -.cattree .score_2, .cattree .score_3, .cattree .score_4 { - color: #409840; -} - -.cattree .score_5, .cattree .score_6, .cattree .score_7 { - color: #006000; -} - -.cattree .score_0:before, .cattree .score_1:before { - content: "★☆☆ "; -} - -.cattree .score_2:before, .cattree .score_3:before, .cattree .score_4:before { - content: "★★☆ "; -} - -.cattree .score_5:before, .cattree .score_6:before, .cattree .score_7:before { - content: "★★★ "; -} - -.cattree .img-container { - float: left; margin: 10px 0 0; width: 60px; height: 50px; background: #dddddd; -} - -.cattree .img-container img { - min-width: 30px; max-width: 60px; max-height: 50px; margin: 0px auto; -} - -.cattree .content p.description { - margin: 4px 0 4px 64px; font-size: 12px; min-height: 50px; -} - -.cattree li, .cattree p.theme { - margin: 4px 0; font-size: 13px; position: relative; -} - -.cattree p.theme { - font-weight: bold; cursor: pointer; -} - -.cattree p.theme:after { - content: " [-]" -} - -.cattree .folded p.theme:after { - content: " [+]" -} - -.cattree ul { - list-style: none; position: relative; padding: 0; margin: 0; -} - -.cattree .folded ul { - display: none; -} - -.cattree .foldedcontent { - height: 0px; overflow: hidden; -} - -.cattree .show_more { - color: #800000; font-style: italic; cursor: pointer; -} - -.cattree li { - list-style: none; -} - -.cattree ul li { - margin-left: 38px; -} - -.cattree ul li:after { - content: ""; position: absolute; left: -50px; top: 9px; width: 40px; bottom: 0; border-style: solid none none solid; border-width: 1px; border-color: #333; -} - -.cattree ul li:before { - content: ""; position: absolute; left: -50px; top: -10px; height: 19px; width: 1px; background: #333; -} - -.cattree ul li:last-child:after { - border-style: solid none none; -} - -.cattree .eltype { - font-style: italic; display: none; -} - -li.themeli { - list-style: square; -} - -li.content { - list-style: disc; -} - -.loading { - height: 128px; background: url(../img/loader.gif) no-repeat center; -} diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/static/hdalab/css/common.css --- a/web/hdalab/static/hdalab/css/common.css Thu Oct 11 15:49:57 2012 +0200 +++ b/web/hdalab/static/hdalab/css/common.css Thu Oct 11 18:22:45 2012 +0200 @@ -105,6 +105,7 @@ #nav li { float: left; font-size: 14px; margin-left: 15px; font-weight: bold; + color: #CCCCCC; } #nav a { diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/static/hdalab/css/index.css --- a/web/hdalab/static/hdalab/css/index.css Thu Oct 11 15:49:57 2012 +0200 +++ b/web/hdalab/static/hdalab/css/index.css Thu Oct 11 18:22:45 2012 +0200 @@ -49,15 +49,15 @@ } .bloc-appli { - width: 475px; float: left; + width: 310px; float: left; } .separateur-applis { - width: 10px; height: 100px; float: left; + width: 15px; height: 100px; float: left; } .fond-bloc { - cursor: pointer; height: 295px; margin: 5px 0 15px; padding: 5px; + cursor: pointer; height: 290px; margin: 5px 0 15px; padding: 5px; } .overlay-bloc { @@ -76,8 +76,8 @@ background: url(../img/categories-thumb.jpg); } -#bloc-completion { - background: url(../img/completion-thumb.jpg); +#bloc-thesaurus { + background: url(../img/thesaurus-thumb.jpg); } .mini-table { diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/static/hdalab/css/thesaurus.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/hdalab/static/hdalab/css/thesaurus.css Thu Oct 11 18:22:45 2012 +0200 @@ -0,0 +1,13 @@ +.column { + float: left; width: 449px; + padding-left: 20px; +} + +.separator { + float: left; width: 1px; height: 500px; margin: 30px 10px 0; background: #666; +} + +.column h3 { + font-size: 14px; font-weight: bold; + margin: 10px 0; +} diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/static/hdalab/css/trees.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/hdalab/static/hdalab/css/trees.css Thu Oct 11 18:22:45 2012 +0200 @@ -0,0 +1,121 @@ +.hidden { + display: none; +} + +.cattree .content p.title { + font-weight: bold; cursor: pointer; +} + +.cattree .content p.title:before { + font-weight: normal; +} + +.cattree .score_0, .cattree .score_1 { + color: #80d080; +} + +.cattree .score_2, .cattree .score_3, .cattree .score_4 { + color: #409840; +} + +.cattree .score_5, .cattree .score_6, .cattree .score_7 { + color: #006000; +} + +.cattree .score_0:before, .cattree .score_1:before { + content: "★☆☆ "; +} + +.cattree .score_2:before, .cattree .score_3:before, .cattree .score_4:before { + content: "★★☆ "; +} + +.cattree .score_5:before, .cattree .score_6:before, .cattree .score_7:before { + content: "★★★ "; +} + +.cattree .img-container { + float: left; margin: 10px 0 0; width: 60px; height: 50px; background: #dddddd; +} + +.cattree .img-container img { + min-width: 30px; max-width: 60px; max-height: 50px; margin: 0px auto; +} + +.cattree .content p.description { + margin: 4px 0 4px 64px; font-size: 12px; min-height: 50px; +} + +.cattree li, .cattree p.theme { + margin: 4px 0; font-size: 12px; position: relative; +} + +.cattree p.theme { + color: #000080; height: 20px; cursor: pointer; +} + +.cattree p.theme:after { + font-weight: bold; + content: " [-]" +} + +.cattree .folded p.theme:after { + font-weight: bold; + content: " [+]" +} + +.cattree .theme span { + font-weight: bold; line-height: 12px; +} + +.cattree ul { + list-style: none; position: relative; padding: 0; margin: 0; +} + +.cattree .folded ul { + display: none; +} + +.cattree .foldedcontent { + height: 0px; overflow: hidden; +} + +.cattree .show_more { + color: #800000; font-style: italic; cursor: pointer; +} + +.cattree li { + list-style: none; +} + +.cattree ul li { + margin-left: 38px; +} + +.cattree ul li:after { + content: ""; position: absolute; left: -50px; top: 9px; width: 40px; bottom: 0; border-style: solid none none solid; border-width: 1px; border-color: #333; +} + +.cattree ul li:before { + content: ""; position: absolute; left: -50px; top: -10px; height: 19px; width: 1px; background: #333; +} + +.cattree ul li:last-child:after { + border-style: solid none none; +} + +.cattree .eltype { + font-style: italic; display: none; +} + +.cattree li.themeli { + list-style: square; +} + +.cattree li.content { + list-style: disc; +} + +.loading { + height: 128px; background: url(../img/loader.gif) no-repeat center; +} \ No newline at end of file diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/static/hdalab/img/categories-thumb.jpg Binary file web/hdalab/static/hdalab/img/categories-thumb.jpg has changed diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/static/hdalab/img/completion-thumb.jpg Binary file web/hdalab/static/hdalab/img/completion-thumb.jpg has changed diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/static/hdalab/img/facettes-preview.jpg Binary file web/hdalab/static/hdalab/img/facettes-preview.jpg has changed diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/static/hdalab/img/facettes-thumb.jpg Binary file web/hdalab/static/hdalab/img/facettes-thumb.jpg has changed diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/static/hdalab/img/thesaurus-thumb.jpg Binary file web/hdalab/static/hdalab/img/thesaurus-thumb.jpg has changed diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/static/hdalab/js/cattree.js --- a/web/hdalab/static/hdalab/js/cattree.js Thu Oct 11 15:49:57 2012 +0200 +++ b/web/hdalab/static/hdalab/js/cattree.js Thu Oct 11 18:22:45 2012 +0200 @@ -1,235 +1,12 @@ -var trees = [ - { - title: "Thésaurus de l'Architecture et de l'Urbanisme : Secteur urbain", - tree: { - label: "secteur urbain", - contents: [ - { - label: "banlieue", - contents: [ - { - label: "faubourg" - } - ] - }, - { - label: "îlot" - }, - { - label: "quartier", - contents: [ - { - label: "centre-ville" - } - ] - }, - { - label: "secteur urbain concerté", - contents: [ - { - label: "grand ensemble" - }, - { - label: "lotissement", - contents: [ - { - label: "lotissement concerté", - contents: [ - { - label: "cité-jardin" - }, - { - label: "cité ouvrière" - }, - { - label: "courée" - }, - ] - } - ] - } - ] - }, - ] - } - }, - { - title: "Thésaurus Garnier : Architecture d'habitation", - tree: { - label: "architecture d'habitation", - contents: [ - { - label: "cité-jardin" - }, - { - label: "édifice d'habitation", - contents: [ - { - label: "demeure", - contents: [ - { - label: "chalet" - }, - { - label: "château" - }, - { - label: "château-fort", - contents: [ - { - label: "chemin de ronde" - }, - { - label: "donjon" - } - ] - }, - { - label: "hôtel particulier" - }, - { - label: "maison" - }, - { - label: "manoir" - }, - { - label: "palais" - } - ] - }, - { - label: "abri", - contents: [ - { - label: "buron" - }, - { - label: "cabane" - }, - { - label: "campement", - contents: [ - { - label: "tente" - }, - { - label: "tipi" - }, - { - label: "igloo" - } - ] - } - ] - } - ] - } - ] - } - }, - { - title: "Thésaurus Garnier : Sciences occultes", - tree: { - label: "sciences occultes", - contents: [ - { - label: "alchimie" - }, - { - label: "astrologie" - }, - { - label: "divination" - }, - { - label: "magie", - contents: [ - { - label: "sorcellerie" - }, - { - label: "sorcière" - } - ] - } - ] - } - } -] - -function render(_data, _level) { - _data.theme_count = - (typeof _data.sub_categories == "object" && typeof _data.sub_categories.slice == "function" ? _data.sub_categories.length : 0) - + (typeof _data.tags == "object" && typeof _data.tags.slice == "function" ? _data.tags.length : 0); - _data.contents_count = (typeof _data.contents == "object" && typeof _data.contents.slice == "function" ? _data.contents.length : 0); - _data.level = !!_level; - _(_data.tags).each(function(_tag) { - _(_tag.contents).each(function(_content, _key) { - _content.trimmed_description = _content.description.trim().replace(/(\n|\r|\r\n)/mg,' ').replace(/(^.{150,200})[\s].+$/m,'$1…'); - _content.hidden = (_key >= 5); - }); - _tag.show_more = _tag.contents && _tag.contents.length > 5 ? _tag.contents.length - 5 : 0; - }); - _(_data.contents).each(function(_content, _key) { - _content.trimmed_description = _content.description.trim().replace(/(\n|\r|\r\n)/mg,' ').replace(/(^.{150,200})[\s].+$/m,'$1…'); - _content.hidden = (_key >= 5); - }); - _data.show_more = _data.contents && _data.contents.length > 5 ? _data.contents.length - 5 : 0; - var _prefix = '
  • {{category}} — {{#theme_count}}{{theme_count}} thème(s){{#contents_count}}, {{/contents_count}}{{/theme_count}}{{#contents_count}}{{contents_count}} ressource(s){{/contents_count}}

  • ', - _html = Mustache.to_html(_prefix, _data); - if (typeof _data.sub_categories == "object" && typeof _data.sub_categories.slice == "function") { - for (var _i = 0; _i < _data.sub_categories.length; _i++) { - _html += render(_data.sub_categories[_i], _level + 1); - } - } - _html += Mustache.to_html(_suffix, _data); - return _html; -} - function showData(_label, _data) { - $(".disciplist li, .theslist li").each(function() { + $(".disciplist li").each(function() { if ($(this).text().trim().toLowerCase() === _label.toLowerCase()) { $(this).addClass("selected"); } }) $(".label-name").html(_label); if (_data) { - $("#tree").html(render(_data, 0)); - $(".cattree p.theme").click(function() { - $(this).parent().toggleClass("folded") - return false; - }); - $("li.content").mouseenter(function() { - $(this).find(".foldedcontent") - .dequeue() - .animate({ - height: 5 + $(this).find("p.description").outerHeight() - }, - 500); - }).mouseleave(function() { - $(this).find(".foldedcontent") - .dequeue() - .animate({ - height: "0" - }, - 500); - }); - $(".show_more").click(function() { - $(this).siblings(".hidden:lt(5)").removeClass("hidden"); - var _l = $(this).siblings(".hidden").length; - $(this).find(".show_more_count").html(_l); - if (!_l) { - $(this).detach(); - } - }) + renderData($("#tree"), _data); $(".results").show(); $(".content-count").html($(".cattree a.content").length); $(".category-count").html(Math.max(0, $("p.category").length - 1)); @@ -241,7 +18,7 @@ } function gettree(_label) { - $(".disciplist li, .theslist li").removeClass("selected"); + $(".disciplist li").removeClass("selected"); $("#tree").html('
    '); $.getJSON( endpoints.cat_tree, @@ -280,21 +57,4 @@ $(".disciplist li").click(function() { gettree($(this).text().trim()); }); - _(trees).each(function(_tree) { - $("
  • ") - .html($('').text(_tree.title)) - .appendTo(".theslist") - .click(function() { - $(".disciplist li, .theslist li").removeClass("selected"); - $("#tree").html('
    '); - $.getJSON( - endpoints.fill_tree, - { tree: JSON.stringify(_tree.tree) }, - function(_data) { - showData(_tree.title, _data); - } - ); - return false; - }); - }); }); \ No newline at end of file diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/static/hdalab/js/thesaurus.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/hdalab/static/hdalab/js/thesaurus.js Thu Oct 11 18:22:45 2012 +0200 @@ -0,0 +1,173 @@ +var trees = [ + { + title: "Thésaurus de l'Architecture et de l'Urbanisme : Secteur urbain", + tree: { + label: "secteur urbain", + contents: [ + { + label: "banlieue", + contents: [ + { + label: "faubourg" + } + ] + }, + { + label: "îlot" + }, + { + label: "quartier", + contents: [ + { + label: "centre-ville" + } + ] + }, + { + label: "secteur urbain concerté", + contents: [ + { + label: "grand ensemble" + }, + { + label: "lotissement", + contents: [ + { + label: "lotissement concerté", + contents: [ + { + label: "cité-jardin" + }, + { + label: "cité ouvrière" + }, + { + label: "courée" + }, + ] + } + ] + } + ] + }, + ] + } + }, + { + title: "Thésaurus Garnier : Architecture d'habitation", + tree: { + label: "architecture d'habitation", + contents: [ + { + label: "cité-jardin" + }, + { + label: "édifice d'habitation", + contents: [ + { + label: "demeure", + contents: [ + { + label: "chalet" + }, + { + label: "château" + }, + { + label: "château-fort", + contents: [ + { + label: "chemin de ronde" + }, + { + label: "donjon" + } + ] + }, + { + label: "hôtel particulier" + }, + { + label: "maison" + }, + { + label: "manoir" + }, + { + label: "palais" + } + ] + }, + { + label: "abri", + contents: [ + { + label: "buron" + }, + { + label: "cabane" + }, + { + label: "campement", + contents: [ + { + label: "tente" + }, + { + label: "tipi" + }, + { + label: "igloo" + } + ] + } + ] + } + ] + } + ] + } + }, + { + title: "Thésaurus Garnier : Sciences occultes", + tree: { + label: "sciences occultes", + contents: [ + { + label: "alchimie" + }, + { + label: "astrologie" + }, + { + label: "divination" + }, + { + label: "magie", + contents: [ + { + label: "sorcellerie" + }, + { + label: "sorcière" + } + ] + } + ] + } + } +]; +$(function() { + $(".column").each(function(_key) { + var _tree = trees[_key], + _el = $(this); + _el.find("h3").text(_tree.title); + $.getJSON( + endpoints.fill_tree, + { tree: JSON.stringify(_tree.tree) }, + function(_data) { + renderData(_el.find(".cattree"), _data); + } + ); + }); +}); diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/static/hdalab/js/trees.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/hdalab/static/hdalab/js/trees.js Thu Oct 11 18:22:45 2012 +0200 @@ -0,0 +1,76 @@ + +function countContentsAndThemes(_data) { + _data.counts = { + contents: (typeof _data.contents == "object" && typeof _data.contents.slice == "function" ? _data.contents.length : 0), + themes: (typeof _data.themes == "object" && typeof _data.themes.slice == "function" ? _data.themes.length : 0) + } + if (typeof _data.themes == "object" && typeof _data.themes.slice == "function") { + for (var _i = 0; _i < _data.themes.length; _i++) { + countContentsAndThemes(_data.themes[_i]); + var _subres = _data.themes[_i].counts; + _data.counts.contents += _subres.contents; + _data.counts.themes += _subres.themes; + } + } +} + +function renderTemplate(_data, _level, _scale) { + _data.level = !!_level; + _(_data.tags).each(function(_tag) { + _(_tag.contents).each(function(_content, _key) { + _content.trimmed_description = _content.description.trim().replace(/(\n|\r|\r\n)/mg,' ').replace(/(^.{150,200})[\s].+$/m,'$1…'); + _content.hidden = (_key >= 5); + }); + _tag.show_more = _tag.contents && _tag.contents.length > 5 ? _tag.contents.length - 5 : 0; + }); + _(_data.contents).each(function(_content, _key) { + _content.trimmed_description = _content.description.trim().replace(/(\n|\r|\r\n)/mg,' ').replace(/(^.{150,200})[\s].+$/m,'$1…'); + _content.hidden = (_key >= 5); + }); + _data.show_more = _data.contents && _data.contents.length > 5 ? _data.contents.length - 5 : 0; + _data.font_size = (10+Math.log(_data.counts.contents)*_scale); + var _prefix = '
  • {{label}} — {{#counts.themes}}{{counts.themes}} thème(s){{#counts.contents}}, {{/counts.contents}}{{/counts.themes}}{{#counts.contents}}{{counts.contents}} notice(s){{/counts.contents}}

  • ', + _html = Mustache.to_html(_prefix, _data); + if (typeof _data.themes == "object" && typeof _data.themes.slice == "function") { + for (var _i = 0; _i < _data.themes.length; _i++) { + _html += renderTemplate(_data.themes[_i], _level + 1, _scale); + } + } + _html += Mustache.to_html(_suffix, _data); + return _html; +} + +function renderData(_selector, _data) { + countContentsAndThemes(_data); + var _scale = 8 / Math.max(1,Math.log(_data.counts.contents)); + _selector.html(renderTemplate(_data, 0, _scale)); + _selector.find("p.theme").click(function() { + $(this).parent().toggleClass("folded") + return false; + }); + _selector.find("li.content").mouseenter(function() { + $(this).find(".foldedcontent") + .dequeue() + .animate({ + height: 5 + $(this).find("p.description").outerHeight() + }, + 500); + }).mouseleave(function() { + $(this).find(".foldedcontent") + .dequeue() + .animate({ + height: "0" + }, + 500); + }); + _selector.find(".show_more").click(function() { + $(this).siblings(".hidden:lt(5)").removeClass("hidden"); + var _l = $(this).siblings(".hidden").length; + $(this).find(".show_more_count").html(_l); + if (!_l) { + $(this).detach(); + } + }); +} \ No newline at end of file diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/templates/base.html --- a/web/hdalab/templates/base.html Thu Oct 11 15:49:57 2012 +0200 +++ b/web/hdalab/templates/base.html Thu Oct 11 18:22:45 2012 +0200 @@ -25,10 +25,12 @@ - +

    À propos de HdA Lab

    diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/templates/thesaurus.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/hdalab/templates/thesaurus.html Thu Oct 11 18:22:45 2012 +0200 @@ -0,0 +1,42 @@ +{% extends "base.html" %} + +{% block title %}{{block.super}} > Recherche par arbre{% endblock %} + +{% block css_import %} +{{block.super}} + + + +{% endblock %} + +{% block js_import %} +{{block.super}} + + + + + + +{% endblock %} + +{% block thesaurus_actif %}actif{% endblock %} + +{% block main_content %} +
    +

    Arborescence 1

    +
    + +
    +
    +
    +
    +

    Arborescence 2

    +
    + +
    +
    +{% endblock %} \ No newline at end of file diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/urls.py --- a/web/hdalab/urls.py Thu Oct 11 15:49:57 2012 +0200 +++ b/web/hdalab/urls.py Thu Oct 11 18:22:45 2012 +0200 @@ -25,6 +25,7 @@ url(r'^facettes/', TemplateView.as_view(template_name="facettes.html"), name='facettes'), url(r'^categories/', TemplateView.as_view(template_name="categories.html"), name='categories'), + url(r'^thesaurus/', TemplateView.as_view(template_name="thesaurus.html"), name='thesaurus'), url(r'^$', TemplateView.as_view(template_name="index.html"), name='home'), ) diff -r e6675a5b2195 -r a46461f8a74f web/hdalab/views/ajax.py --- a/web/hdalab/views/ajax.py Thu Oct 11 15:49:57 2012 +0200 +++ b/web/hdalab/views/ajax.py Thu Oct 11 18:22:45 2012 +0200 @@ -49,21 +49,21 @@ tags = Tag.objects.filter(wp_categories__wp_category = category).distinct() taglabels = [k for k in dict([(t.label,t.label) for t in tags])] resobj = { - 'category': category.label, - 'tags': [], + 'label': category.label, + 'themes': [], 'contents': [] - } + } for label in taglabels: if label == catlabel: globtags[label] = {'level': level, 'access': resobj } else: tag_in_list = {'label' : label, 'contents': []} - resobj['tags'].append(tag_in_list) + resobj['themes'].append(tag_in_list) globtags[label] = {'level': (level + 1), 'access': tag_in_list } if level < max_level: subcats = WpCategory.objects.filter(parent_categories__parent_category = category) - resobj['sub_categories'] = [subcat(subcats[i], globtags, level + 1, max_level ) for i in range(len(subcats))] + resobj['themes'] += [subcat(subcats[i], globtags, level + 1, max_level ) for i in range(len(subcats))] return resobj def cleantags(category): @@ -71,21 +71,15 @@ del category['contents'] if category.has_key('contents'): category['contents'] = sorted(category['contents'], key=lambda content: -content['score']) - if category.has_key('tags'): - category['tags'] = [cleantags(tag) for tag in category['tags'] if len(tag['contents'])] - if len(category['tags']) == 0: - del category['tags'] - else: - category['tags'] = sorted(category['tags'], key=lambda tag: tag['label']) - if category.has_key('sub_categories'): - sub_cats = [] - for sub_cat in category['sub_categories']: - cat = cleantags(sub_cat) - if cat.has_key('tags') or cat.has_key('sub_categories') or cat.has_key('contents'): - sub_cats.append(cat) - category['sub_categories'] = sorted(sub_cats, key=lambda cat: cat['category']) - if len(category['sub_categories']) == 0: - del category['sub_categories'] + if category.has_key('themes'): + themes = [] + for theme in category['themes']: + clean_theme = cleantags(theme) + if clean_theme.has_key('themes') or clean_theme.has_key('contents'): + themes.append(clean_theme) + category['themes'] = sorted(themes, key=lambda cat: cat['label']) + if len(category['themes']) == 0: + del category['themes'] return category def cattree(request): @@ -434,15 +428,15 @@ contents = sorted(contents, key=lambda e: -e['score']) - res = { 'category': label } + res = { 'label': label } if len(contents): res['contents'] = contents if len(sub): subcats = [subtree(st) for st in sub] - subcats = [sc for sc in subcats if len(sc.get('contents',[])) or len(sc.get('sub_categories',[]))] - res['sub_categories'] = subcats + subcats = [sc for sc in subcats if len(sc.get('contents',[])) or len(sc.get('themes',[]))] + res['themes'] = subcats return res