From 0710010736bbcc2edbad0a4f04008b2c6b05b81e Mon Sep 17 00:00:00 2001 From: Raelon Masters Date: Wed, 1 Jul 2020 12:49:38 -0400 Subject: [PATCH] Started handling of session data --- config.json | 2 +- src/frontend/settings.py | 4 + .../static/css/.dart_tool/package_config.json | 2 +- src/interface/static/css/.packages | 2 +- src/interface/static/css/pubspec.lock | 180 ++++++++++++++++++ src/interface/templates/index.html | 2 +- src/interface/views.py | 19 +- uwsgi.ini | 3 +- 8 files changed, 203 insertions(+), 11 deletions(-) create mode 100644 src/interface/static/css/pubspec.lock diff --git a/config.json b/config.json index 28132cf..42ec83c 100755 --- a/config.json +++ b/config.json @@ -1 +1 @@ -{"TITLE": "pyShelf E-Book Server", "VERSION": "0.5.0", "BOOKPATH": "/home/raelon/Books", "DB_HOST": "localhost", "DB_PORT": "5432", "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", "BOOKSHELF": "data/shelf.json", "ALLOWED_HOSTS": "*", "hostname": "localhost", "webport": "8000", "wsgiport": "8001"} +{"TITLE": "pyShelf E-Book Server", "VERSION": "0.5.0", "BOOKPATH": "/home/raelon/Books", "DB_HOST": "localhost", "DB_PORT": "5432", "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", "BOOKSHELF": "data/shelf.json", "ALLOWED_HOSTS": "*", "hostname": "localhost", "webport": "8000", "wsgiport": "8001"} \ No newline at end of file diff --git a/src/frontend/settings.py b/src/frontend/settings.py index 6fe29bb..b1ca483 100755 --- a/src/frontend/settings.py +++ b/src/frontend/settings.py @@ -101,6 +101,10 @@ DATABASES = { "PASSWORD": CONFIG.password, } } +# Session +# Uncomment below to enable sessions management by a memcache server +# https://docs.djangoproject.com/en/3.0/topics/http/sessions/ +# SESSION_ENGINE = "django.contrib.sessions.backends.cached_db" # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators diff --git a/src/interface/static/css/.dart_tool/package_config.json b/src/interface/static/css/.dart_tool/package_config.json index 53dc171..2a507a6 100644 --- a/src/interface/static/css/.dart_tool/package_config.json +++ b/src/interface/static/css/.dart_tool/package_config.json @@ -157,7 +157,7 @@ "packageUri": "lib/" } ], - "generated": "2020-06-24T15:15:46.784320Z", + "generated": "2020-06-28T03:58:01.082901Z", "generator": "pub", "generatorVersion": "2.8.4" } diff --git a/src/interface/static/css/.packages b/src/interface/static/css/.packages index 20dfea0..6bf3eb2 100644 --- a/src/interface/static/css/.packages +++ b/src/interface/static/css/.packages @@ -1,4 +1,4 @@ -# Generated by pub on 2020-06-24 11:15:46.775314. +# Generated by pub on 2020-06-27 23:58:01.069770. args:file:///home/raelon/.pub-cache/hosted/pub.dartlang.org/args-1.6.0/lib/ async:file:///home/raelon/.pub-cache/hosted/pub.dartlang.org/async-2.4.1/lib/ charcode:file:///home/raelon/.pub-cache/hosted/pub.dartlang.org/charcode-1.1.3/lib/ diff --git a/src/interface/static/css/pubspec.lock b/src/interface/static/css/pubspec.lock new file mode 100644 index 0000000..92eed66 --- /dev/null +++ b/src/interface/static/css/pubspec.lock @@ -0,0 +1,180 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.0" + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.1" + charcode: + dependency: transitive + description: + name: charcode + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.3" + cli_repl: + dependency: transitive + description: + name: cli_repl + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0+1" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.14.13" + http: + dependency: transitive + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.1" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.4" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.2" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.8" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.8" + package_config: + dependency: transitive + description: + name: package_config + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.3" + package_resolver: + dependency: transitive + description: + name: package_resolver + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.10" + path: + dependency: transitive + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.7.0" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.0" + quiver: + dependency: transitive + description: + name: quiver + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" + sass: + dependency: "direct dev" + description: + name: sass + url: "https://pub.dartlang.org" + source: hosted + version: "1.26.9" + source_maps: + dependency: transitive + description: + name: source_maps + url: "https://pub.dartlang.org" + source: hosted + version: "0.10.9" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.7.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.3" + stream_transform: + dependency: transitive + description: + name: stream_transform + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.5" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + tuple: + dependency: transitive + description: + name: tuple + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + watcher: + dependency: transitive + description: + name: watcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.7+15" +sdks: + dart: ">=2.7.0 <3.0.0" diff --git a/src/interface/templates/index.html b/src/interface/templates/index.html index d05bd0a..54a6ac4 100755 --- a/src/interface/templates/index.html +++ b/src/interface/templates/index.html @@ -53,7 +53,7 @@ diff --git a/src/interface/views.py b/src/interface/views.py index 1b9ce16..090153c 100755 --- a/src/interface/views.py +++ b/src/interface/views.py @@ -21,7 +21,7 @@ def index(request, query=None, _set=1, _limit=None, _order='title'): """ Return template index """ - _payload = payload(query, _set, _limit, _order) + _payload = payload(request, query, _set, _limit, _order) return render( request, "index.html", @@ -304,7 +304,7 @@ def collections_list(): collection_key.append(i.collection) return json.dumps(list(set(collection_key))) -def payload(query, _set, _limit, _order): +def payload(request, query, _set, _limit, _order): """ Return formatted data to template # TODO hook into payload and provide handling of next,prev, & search combos @@ -315,11 +315,18 @@ def payload(query, _set, _limit, _order): _set_max = int(_set) * _limit _set_min = _set_max - _limit _now_showing = "%s of %s"%(_set_min, _set_max) - + if query: - _results = Books().generic_search(query) - _r_len = _results.count() - _r, _search = _results[_set_min:_set_max], query + if query != request.session.get('cached_query'): + breakpoint() + ses_query = request.session['cached_query'] = query + ses_results = request.session['cached_results'] = Books().generic_search(query) + _r_len = ses_results.count() + _r, _search = ses_results[_set_min:_set_max], request.session.get('cached_query') + elif query == request.session.get('cached_query'): + _r, _search = request.session['cached_results'].order_by(_order)[_set_min:_set_max], request.session['cached_query'] + elif request.session['cached_query']: + _r,_search = request.session['cached_results'].order_by(_order)[_set_min:_set_max], request.session['cached_query'] else: _r, _r_len, _search = book_set(_order, _limit, _set), None, None _bookstats, _collectionstats, _collectionobject = \ diff --git a/uwsgi.ini b/uwsgi.ini index bc8057d..82901fd 100755 --- a/uwsgi.ini +++ b/uwsgi.ini @@ -1,9 +1,10 @@ [uwsgi] - chdir=/opt/pyShelf/src + chdir=/home/raelon/Projects/pyShelf/src module=frontend.wsgi master=True pidfile=/tmp/pyShelf.pid vacuum=True socket=/tmp/pyshelf_wsgi.sock chmod-socket=666 + \ No newline at end of file