From c7a3fcf4c7098fb4e3cde3993742c182a255bd0b Mon Sep 17 00:00:00 2001 From: Raelon Masters Date: Sat, 27 Jun 2020 15:31:44 -0400 Subject: [PATCH] Sending data from python to javascript --- requirements.txt | 2 ++ src/interface/static/css/main.css | 2 +- src/interface/static/js/pyshelf_ux.js | 2 +- src/interface/templates/index.html | 10 +++++----- src/interface/views.py | 24 +++++++++++++++++------- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/requirements.txt b/requirements.txt index 89974a9..3a0357d 100755 --- a/requirements.txt +++ b/requirements.txt @@ -18,3 +18,5 @@ prompt_toolkit psutil pyfiglet mobi-python +pudb +jsonpickle diff --git a/src/interface/static/css/main.css b/src/interface/static/css/main.css index 77a8d98..a41bcb4 100644 --- a/src/interface/static/css/main.css +++ b/src/interface/static/css/main.css @@ -264,7 +264,7 @@ body { display: flex; grid-area: horiz_nav_main; align-items: center; - justify-content: center; + /* justify-content: center; */ padding: 5px 5px 0px 5px; min-width: max-content; color: deepskyblue; diff --git a/src/interface/static/js/pyshelf_ux.js b/src/interface/static/js/pyshelf_ux.js index 8bad8e5..5c3aa47 100755 --- a/src/interface/static/js/pyshelf_ux.js +++ b/src/interface/static/js/pyshelf_ux.js @@ -12,7 +12,7 @@ $(document).ready(function(){ var scr_height = window.outerHeight; var scr_width = window.outerWidth; var hdr_height = $('.app_hdr').height(); // Get our header height - var ftr_height = $('.app_footer').height(); // Get our footer height + var ftr_height = $('.app_footer').height(); // Get our footer height var nav_width = $('.nav_l').width(); // Get the width of our nav items var cmp_height = window.screen.availHeight; var max_height = win_height - (hdr_height + ftr_height) - (scr_height - win_height); // Set our available height diff --git a/src/interface/templates/index.html b/src/interface/templates/index.html index 8ac4923..7315e55 100755 --- a/src/interface/templates/index.html +++ b/src/interface/templates/index.html @@ -11,13 +11,13 @@ pyShelf E-Book Server - - - - + + @@ -44,7 +44,7 @@
- {{ BookStats }} books | {{ CollectionStats }} collections + {{ BookStats }} books | collections
diff --git a/src/interface/views.py b/src/interface/views.py index 28fdb84..fe4b300 100755 --- a/src/interface/views.py +++ b/src/interface/views.py @@ -8,12 +8,14 @@ from django.db import models from django.http import JsonResponse from django.shortcuts import HttpResponse, render # render_to_response from django.utils.text import slugify +import json +import jsonpickle from .models import Books, Collections, Navigation config = Config(Path("../")) - +collections = Collections.objects.all() def index(request): """ Return template index @@ -29,8 +31,8 @@ def index(request): "LeftNavCollections": menu("collections"), "LeftNavMenu0": menu("nav_l_0"), "BookStats": Books.objects.all().count, - "CollectionStats": Collections.objects.all().count - + "CollectionStats": Collections.objects.all().count, + "CollectionObject": collections_list() }, ) @@ -48,6 +50,7 @@ def show_collection(request, _collection, _colset): "Version": config.VERSION, "LeftNavCollections": menu("collections"), "LeftNav": menu("collections"), + "Collections": collections_list() }, ) @@ -239,8 +242,8 @@ def format_list(list_in): def menu(which, _set=1, parent=None): if which == "collections": - collection_list = Collections.objects.all() - collections, collection_key, x = [], [], 0 + collection_list = collections + _collections, collection_key, x = [], [], 0 for i in collection_list: if i.collection not in collection_key: # Using c as the alternating row identifier @@ -259,12 +262,19 @@ def menu(which, _set=1, parent=None): else: collection_string = i.collection - collections.append( + _collections.append( {"string": collection_string, "link": i.collection, "class": c} ) collection_key.append(i.collection) - return collections + return _collections elif which == "nav_lvl_0": navigation_list = Navigation.objects.all() breakpoint() return navigation_list + +def collections_list(): + collection_key = [] + for i in collections: + if i.collection not in collection_key: + collection_key.append(i.collection) + return json.dumps(list(set(collection_key)))