Sending data from python to javascript

This commit is contained in:
Raelon Masters
2020-06-27 15:31:44 -04:00
parent 9a055d7660
commit c7a3fcf4c7
5 changed files with 26 additions and 14 deletions

2
requirements.txt vendored
View File

@@ -18,3 +18,5 @@ prompt_toolkit
psutil psutil
pyfiglet pyfiglet
mobi-python mobi-python
pudb
jsonpickle

View File

@@ -264,7 +264,7 @@ body {
display: flex; display: flex;
grid-area: horiz_nav_main; grid-area: horiz_nav_main;
align-items: center; align-items: center;
justify-content: center; /* justify-content: center; */
padding: 5px 5px 0px 5px; padding: 5px 5px 0px 5px;
min-width: max-content; min-width: max-content;
color: deepskyblue; color: deepskyblue;

View File

@@ -12,7 +12,7 @@ $(document).ready(function(){
var scr_height = window.outerHeight; var scr_height = window.outerHeight;
var scr_width = window.outerWidth; var scr_width = window.outerWidth;
var hdr_height = $('.app_hdr').height(); // Get our header height 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 nav_width = $('.nav_l').width(); // Get the width of our nav items
var cmp_height = window.screen.availHeight; var cmp_height = window.screen.availHeight;
var max_height = win_height - (hdr_height + ftr_height) - (scr_height - win_height); // Set our available height var max_height = win_height - (hdr_height + ftr_height) - (scr_height - win_height); // Set our available height

View File

@@ -11,13 +11,13 @@
<link type="text/css" rel="stylesheet" href="/static/css/all-fa.css" /> <link type="text/css" rel="stylesheet" href="/static/css/all-fa.css" />
<title>pyShelf E-Book Server</title> <title>pyShelf E-Book Server</title>
<link href="https://fonts.googleapis.com/css?family=Audiowide&family=Montserrat:wght@300&family=Gruppo&family=Cinzel+Decorative&family=Ubuntu+Mono&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Audiowide&family=Montserrat:wght@300&family=Gruppo&family=Cinzel+Decorative&family=Ubuntu+Mono&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Gruppo&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Cinzel+Decorative&family=Ubuntu+Mono&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300&display=swap" rel="stylesheet">
<script src="/static/js/jquery-3.4.1.min.js" type="text/javascript"></script> <script src="/static/js/jquery-3.4.1.min.js" type="text/javascript"></script>
<script src="/static/js/pyshelf_ux.js" type="text/javascript"></script>
<!-- Place this tag in your head or just before your close body tag. --> <!-- Place this tag in your head or just before your close body tag. -->
<script async defer src="https://buttons.github.io/buttons.js"></script> <script async defer src="https://buttons.github.io/buttons.js"></script>
<script src="/static/js/pyshelf_ux.js" type="text/javascript"></script>
<script type="text/javascript">
var collections={{ CollectionObject|safe }};
</script>
</head> </head>
<body> <body>
@@ -44,7 +44,7 @@
</div> </div>
<div id="horiz_nav_main"> <div id="horiz_nav_main">
<!--<i class="fas fa-chevron-left nav_icon prev_page" onclick="window.location.href = '/prev_page/{{ Set }}'"></i>--> <!--<i class="fas fa-chevron-left nav_icon prev_page" onclick="window.location.href = '/prev_page/{{ Set }}'"></i>-->
{{ BookStats }} books | {{ CollectionStats }} collections {{ BookStats }} books | <script type="text/javascript">document.write(collections.length)</script> collections
<!--<i class="fas fa-chevron-right nav_icon next_page" onclick="window.location.href = '/next_page/{{ Set }}'"></i>--> <!--<i class="fas fa-chevron-right nav_icon next_page" onclick="window.location.href = '/next_page/{{ Set }}'"></i>-->
<!--<input class="nav_button search_submit" type="submit" value="Search">--> <!--<input class="nav_button search_submit" type="submit" value="Search">-->
</div> </div>

View File

@@ -8,12 +8,14 @@ from django.db import models
from django.http import JsonResponse from django.http import JsonResponse
from django.shortcuts import HttpResponse, render # render_to_response from django.shortcuts import HttpResponse, render # render_to_response
from django.utils.text import slugify from django.utils.text import slugify
import json
import jsonpickle
from .models import Books, Collections, Navigation from .models import Books, Collections, Navigation
config = Config(Path("../")) config = Config(Path("../"))
collections = Collections.objects.all()
def index(request): def index(request):
""" """
Return template index Return template index
@@ -29,8 +31,8 @@ def index(request):
"LeftNavCollections": menu("collections"), "LeftNavCollections": menu("collections"),
"LeftNavMenu0": menu("nav_l_0"), "LeftNavMenu0": menu("nav_l_0"),
"BookStats": Books.objects.all().count, "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, "Version": config.VERSION,
"LeftNavCollections": menu("collections"), "LeftNavCollections": menu("collections"),
"LeftNav": menu("collections"), "LeftNav": menu("collections"),
"Collections": collections_list()
}, },
) )
@@ -239,8 +242,8 @@ def format_list(list_in):
def menu(which, _set=1, parent=None): def menu(which, _set=1, parent=None):
if which == "collections": if which == "collections":
collection_list = Collections.objects.all() collection_list = collections
collections, collection_key, x = [], [], 0 _collections, collection_key, x = [], [], 0
for i in collection_list: for i in collection_list:
if i.collection not in collection_key: if i.collection not in collection_key:
# Using c as the alternating row identifier # Using c as the alternating row identifier
@@ -259,12 +262,19 @@ def menu(which, _set=1, parent=None):
else: else:
collection_string = i.collection collection_string = i.collection
collections.append( _collections.append(
{"string": collection_string, "link": i.collection, "class": c} {"string": collection_string, "link": i.collection, "class": c}
) )
collection_key.append(i.collection) collection_key.append(i.collection)
return collections return _collections
elif which == "nav_lvl_0": elif which == "nav_lvl_0":
navigation_list = Navigation.objects.all() navigation_list = Navigation.objects.all()
breakpoint() breakpoint()
return navigation_list 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)))