renamed pa_pref to better named pa_user_state, changed code to adapt and made new_view and viewlist work with newer Options/pa_user_state - still more work but it should be functional again
This commit is contained in:
165
states.py
Normal file
165
states.py
Normal file
@@ -0,0 +1,165 @@
|
||||
from settings import Settings, SettingsRBPath, SettingsIPath, SettingsSPath
|
||||
from flask import request, render_template, redirect, url_for
|
||||
from flask_login import login_required, current_user
|
||||
from main import db, app, ma
|
||||
from shared import PA
|
||||
|
||||
|
||||
################################################################################
|
||||
# PA_UserState: preference data for a given user / path_type combo, so a given user
|
||||
# and their prefs for say the import path(s) and storage path(s) etc, each
|
||||
# path_type has different defaults, and keeping those works better
|
||||
################################################################################
|
||||
class PA_UserState(db.Model):
|
||||
__tablename__ = "pa_user_state"
|
||||
pa_user_dn = db.Column(db.String, db.ForeignKey('pa_user.dn'), primary_key=True )
|
||||
path_type = db.Column(db.String, primary_key=True, unique=False, nullable=False )
|
||||
noo = db.Column(db.String, unique=False, nullable=False )
|
||||
grouping = db.Column(db.String, unique=False, nullable=False )
|
||||
how_many = db.Column(db.Integer, unique=False, nullable=False )
|
||||
st_offset = db.Column(db.Integer, unique=False, nullable=False )
|
||||
size = db.Column(db.Integer, unique=False, nullable=False )
|
||||
folders = db.Column(db.Boolean, unique=False, nullable=False )
|
||||
fullscreen = db.Column(db.Boolean, unique=False, nullable=False )
|
||||
root = db.Column(db.String, unique=False, nullable=False )
|
||||
cwd = db.Column(db.String, unique=False, nullable=False )
|
||||
|
||||
def __repr__(self):
|
||||
return f"<pa_user_dn: {self.pa_user_dn}, path_type: {self.path_type}, noo: {self.noo}, grouping: {self.grouping}, how_many: {self.how_many}, st_offset: {self.st_offset}, size: {self.size}, folders: {self.folders}, root: {self.root}, cwd: {self.cwd}>"
|
||||
|
||||
|
||||
################################################################################
|
||||
# Options: class to store set of default values for viewing (order/size, etc.)
|
||||
# and if a request object (from a POST) is passed in, it returns those instead
|
||||
# it also handles the cwd appropriately, paths, fullscreen, search, etc.
|
||||
################################################################################
|
||||
class Options(PA):
|
||||
def __init__(self, request):
|
||||
if 'orig_url' in request.form:
|
||||
url = request.form['orig_url']
|
||||
else:
|
||||
url = request.path
|
||||
self.orig_url=url
|
||||
if 'files_sp' in url:
|
||||
self.path_type = 'Storage'
|
||||
self.paths = SettingsSPath()
|
||||
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==self.path_type).first()
|
||||
if pref:
|
||||
self.folders=pref.folders
|
||||
self.noo=pref.noo
|
||||
else:
|
||||
self.folders=True
|
||||
self.noo="A to Z"
|
||||
elif 'files_rbp' in url:
|
||||
self.path_type = 'Bin'
|
||||
self.paths = []
|
||||
self.paths.append(SettingsRBPath())
|
||||
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==self.path_type).first()
|
||||
if pref:
|
||||
self.folders=pref.folders
|
||||
self.noo=pref.noo
|
||||
else:
|
||||
self.folders=True
|
||||
self.noo="A to Z"
|
||||
elif 'search' in url:
|
||||
self.path_type = 'Search'
|
||||
self.paths = None
|
||||
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==self.path_type).first()
|
||||
if pref:
|
||||
self.folders=pref.folders
|
||||
self.noo=pref.noo
|
||||
else:
|
||||
self.folders=False
|
||||
self.noo="Oldest"
|
||||
else:
|
||||
self.path_type = 'Import'
|
||||
self.paths = SettingsIPath()
|
||||
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==self.path_type).first()
|
||||
if pref:
|
||||
self.folders=pref.folders
|
||||
self.noo=pref.noo
|
||||
else:
|
||||
self.folders=False
|
||||
self.noo="Oldest"
|
||||
|
||||
if pref:
|
||||
self.grouping=pref.grouping
|
||||
self.how_many=pref.how_many
|
||||
self.offset=pref.st_offset
|
||||
self.size=pref.size
|
||||
self.root=pref.root
|
||||
self.cwd=pref.cwd
|
||||
else:
|
||||
self.grouping="None"
|
||||
self.how_many="50"
|
||||
self.offset="0"
|
||||
self.size="128"
|
||||
self.root='static/' + self.path_type
|
||||
self.cwd=self.root
|
||||
|
||||
|
||||
# the above are defaults, if we are here, then we have current values, use them instead if they are set -- AI: searches dont set them so then we use those in the DB first
|
||||
if request.method=="POST":
|
||||
if 'noo' in request.form:
|
||||
self.noo=request.form['noo']
|
||||
if 'how_many' in request.form:
|
||||
self.how_many=request.form['how_many']
|
||||
if 'offset' in request.form:
|
||||
self.offset=int(request.form['offset'])
|
||||
if 'grouping' in request.form:
|
||||
self.grouping=request.form['grouping']
|
||||
# this can be null if we come from view by details
|
||||
if 'size' in request.form:
|
||||
self.size = request.form['size']
|
||||
# seems html cant do boolean, but uses strings so convert
|
||||
if 'folders' not in request.form or request.form['folders'] == "False":
|
||||
self.folders=False
|
||||
elif request.form['folders'] == "True":
|
||||
self.folders=True
|
||||
# have to force grouping to None if we flick to folders from a flat
|
||||
# view with grouping (otherwise we print out group headings for
|
||||
# child content that is not in the CWD)
|
||||
self.grouping=None
|
||||
|
||||
# possible to not be set for an AI: search
|
||||
if 'cwd' in request.form:
|
||||
self.cwd = request.form['cwd']
|
||||
if 'fullscreen' in request.form:
|
||||
self.fullscreen=request.form['fullscreen']
|
||||
else:
|
||||
self.fullscreen=False
|
||||
if 'prev' in request.form:
|
||||
self.offset -= int(self.how_many)
|
||||
if self.offset < 0:
|
||||
self.offset=0
|
||||
if 'next' in request.form:
|
||||
self.offset += int(self.how_many)
|
||||
|
||||
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==self.path_type).first()
|
||||
if not pref:
|
||||
pref=PA_UserState( pa_user_dn=current_user.dn, path_type=self.path_type, noo=self.noo, grouping=self.grouping, how_many=self.how_many,
|
||||
st_offset=self.offset, size=self.size, folders=self.folders, root=self.root, cwd=self.cwd )
|
||||
else:
|
||||
pref.noo=self.noo
|
||||
pref.grouping=self.grouping
|
||||
pref.how_many=self.how_many
|
||||
pref.st_offset=self.offset
|
||||
pref.size=self.size
|
||||
pref.folders=self.folders
|
||||
pref.root = self.root
|
||||
pref.cwd = self.cwd
|
||||
|
||||
db.session.add(pref)
|
||||
db.session.commit()
|
||||
|
||||
return
|
||||
|
||||
################################################################################
|
||||
# /states -> GET only -> prints out list of all prefs (simple for now)
|
||||
################################################################################
|
||||
@app.route("/states", methods=["GET"])
|
||||
@login_required
|
||||
def states():
|
||||
states = PA_UserState.query.filter( PA_UserState.pa_user_dn==current_user.dn ).all()
|
||||
return render_template("states.html", states=states )
|
||||
|
||||
34
templates/states.html
Normal file
34
templates/states.html
Normal file
@@ -0,0 +1,34 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block main_content %}
|
||||
<h3>PA User state page</h3>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<alert class="alert alert-warning">The following values are based on navigating the application and are not set by hand. This page is for checking/debugging only.</alert>
|
||||
</div class="row">
|
||||
<div class="row">
|
||||
<table id="pa_user_state_tbl" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
|
||||
<thead>
|
||||
<tr class="table-primary"><th>Path</th><th>New or Oldest</th><th>How Many</th><th>Folders?</th><th>Group by</th><th>Thumb size</th><th>Fullscreen</th><th>DB retrieve offset</th><th>Root</th><th>cwd</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for st in states %}
|
||||
<tr>
|
||||
<td>{{st.path_type}}</td>
|
||||
<td>{{st.noo}}</td>
|
||||
<td>{{st.how_many}}</td>
|
||||
<td>{{st.folders}}</td>
|
||||
<td>{{st.grouping}}</td>
|
||||
<td>{{st.size}}</td>
|
||||
<td>{{st.fullscreen}}</td>
|
||||
<td>{{st.st_offset}}</td>
|
||||
<td>{{st.root}}</td>
|
||||
<td>{{st.cwd}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div class="row">
|
||||
</div class="container-fluid">
|
||||
{% endblock main_content %}
|
||||
Reference in New Issue
Block a user