From 579094ac18bb15d280052971916c18f34814c003 Mon Sep 17 00:00:00 2001 From: SDE Date: Thu, 11 Jul 2024 16:58:58 +0300 Subject: [PATCH] 0.5.5 documentation --- DocsApp/views.py | 54 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/DocsApp/views.py b/DocsApp/views.py index eb30b76..c5d1902 100644 --- a/DocsApp/views.py +++ b/DocsApp/views.py @@ -8,22 +8,66 @@ from django.conf import settings from GeneralApp.funcs import get_inter_http_respose from django.utils.translation import gettext_lazy as _ from django.urls import reverse +from collections import OrderedDict + + +def get_tree_arts(art, arts): + + docs_tree = OrderedDict() + docs_tree.update({ + art_item.name: { + 'url': art_item.url, + 'id': art_item.id, + 'children': get_tree_arts(art_item, arts), + } for art_item in arts.filter(parent=art) + }) + return docs_tree + + +# def get_tree_arts(art, arts): +# +# docs_tree = OrderedDict() +# docs_tree.update({ +# art['name']: { +# 'url': art['url'], +# 'id': art['id'], +# 'children': get_tree_arts(art, DocArt.objects.filter(parent=art)), +# } for art in arts.filter(parent=None) +# }) +# return docs_tree def DocsView(request, version=None, art_url=None): - art = None - kwargs = {} - if art_url: - kwargs['url'] = art_url + if art_url and version: + kwargs = { + 'url': art_url, + 'versions__url': version, + } try: art = DocArt.objects.get(**kwargs) - Dict = {'cur_article': art} + + try: + vers_obj = DocVersion.objects.get(url=version) + except DocVersion.DoesNotExist: + raise Http404 + + arts = DocArt.objects.filter(enable=True, versions=vers_obj).order_by('order') + doc_tree = get_tree_arts(None, arts) + + + Dict = { + 'cur_article': art, + 'cur_version': vers_obj, + 'doc_tree': doc_tree + } t = loader.get_template('pages/p_documentation.html') return get_inter_http_respose(t, Dict, request) except DocArt.DoesNotExist: raise Http404 + + if version: try: vers_obj = DocVersion.objects.get(url=version)