From 7f81e731d07fa4bdd37887b77c0438395155ec91 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Rekucki?= Date: Tue, 29 Sep 2009 12:10:02 +0200 Subject: [PATCH] Fixed the index tree display. --- apps/api/handlers/library_handlers.py | 27 ++++++++++++++------------- apps/explorer/views.py | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/apps/api/handlers/library_handlers.py b/apps/api/handlers/library_handlers.py index 591d4e90..d2c6ec32 100644 --- a/apps/api/handlers/library_handlers.py +++ b/apps/api/handlers/library_handlers.py @@ -52,33 +52,32 @@ class LibraryHandler(BaseHandler): documents = {} for docid in lib.documents(): + docid = docid.decode('utf-8') documents[docid] = { 'url': reverse('document_view', args=[docid]), 'name': docid, 'parts': [] } - related = PartCache.objects.defer('part_id')\ + parts = PartCache.objects.defer('part_id')\ .values_list('part_id', 'document_id').distinct() + + document_tree = dict(documents) - for part, docid in related: + for part, docid in parts: # this way, we won't display broken links if not documents.has_key(part): + print "NOT FOUND:", part continue - child = documents[part] parent = documents[docid] + child = documents[part] + + # not top-level anymore + document_tree.pop(part) + parent['parts'].append(child) - if isinstance(parent, dict): # the parent is top-level - documents.pop(part) - parent['parts'].append(child) - documents[part] = child['parts'] - else: # not top-level - parent.append(child) - - return { - 'documents': [d for d in documents.itervalues() if isinstance(d, dict)] - } + return {'documents': sorted(document_tree.values()) } @validate_form(forms.DocumentUploadForm, 'POST') @hglibrary @@ -253,6 +252,8 @@ class DocumentTextHandler(BaseHandler): includes = [m.groupdict()['link'] for m in (re.finditer(\ XINCLUDE_REGEXP, data, flags=re.UNICODE) or []) ] + print "INCLUDES: ", includes + # TODO: provide useful routines to make this simpler def xml_update_action(lib, resolve): try: diff --git a/apps/explorer/views.py b/apps/explorer/views.py index eca439ca..28082e64 100644 --- a/apps/explorer/views.py +++ b/apps/explorer/views.py @@ -65,7 +65,7 @@ def file_list(request, repo): # short-circut the api document list doctree = library_resource.handler.read(request) - print doctree['documents'] + print "DOCTREE:", doctree['documents'] return direct_to_template(request, 'explorer/file_list.html', extra_context={ 'filetree': doctree['documents'], 'bookform': bookform, -- 2.20.1