defaults in PAuser include noo/folders for import/storage separated, defaults are stored into PAUser in DB, changable in GUI, used as the defaults for new PA_User_States. Also disabled search noo, search folders as they are hard-coded in the ORM retreive anyway

This commit is contained in:
2022-01-22 23:26:14 +11:00
parent 0f4632e240
commit 2e4b1ed9d2
8 changed files with 75 additions and 45 deletions

View File

@@ -56,15 +56,12 @@ class States(PA):
base=request.base_url
base=base.replace("ChangeFileOpts", "")
self.url = "/"+ref.replace(base, "" )
print( f"started with ChangeFileOpts, so self.url now is {self.url}, bu={request.base_url}")
# if viewlist, then we really are a view, and view_eid should be in the form
if 'viewlist' in request.path:
self.path_type = 'View'
self.view_eid = request.form['view_eid']
self.url = request.form['orig_url']
for el in request.form:
print( f"{el}={request.form[el]}" )
# this occurs ONLY when a POST to /view/<id> occurs (at this stage orig_url will be from an import, storage, bin or search)
elif 'view' in request.path:
self.path_type = 'View'
@@ -77,7 +74,6 @@ class States(PA):
# from pref
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==self.path_type,PA_UserState.view_eid==self.view_eid).first()
self.url = pref.orig_url
print( f"view/ so change url to: '{self.url}'" )
print( f"NOW, url={self.url}" )
@@ -103,7 +99,6 @@ class States(PA):
# okay if we are a search, but came from a view then get last_search_state form prefs and use it
self.orig_search_term = self.url[8:]
if self.path_type == "View":
print(f"view, url={self.url}")
self.orig_ptype = 'Search'
self.orig_url = self.url
else:
@@ -113,21 +108,13 @@ class States(PA):
self.view_eid = self.url[6:]
self.path_type="View"
self.orig_url=self.url
print( f"in view, eid={self.view_eid}, orig_url={self.orig_url}" )
elif 'ChangeFileOpts' in self.url:
print( f"ChangeFileOpts called, so all good?" )
else:
print( f"referrer={request.referrer}" )
elif 'ChangeFileOpts' not in self.url:
print( f"ERROR: DDP messed up, failed to match URL {self.url} for settings this will fail, redirecting to home" )
print( f"referrer={request.referrer}" )
return
if self.path_type == 'View':
print( f"its is a view, find the pref: {self.view_eid}" )
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==self.path_type,PA_UserState.view_eid==self.view_eid).first()
if not pref:
print( f"no pref" )
else:
print( f"pref={pref}" )
elif self.path_type == 'Search':
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==self.path_type,PA_UserState.orig_search_term==self.orig_search_term).first()
else:
@@ -147,16 +134,30 @@ class States(PA):
self.orig_url = pref.orig_url
self.view_eid = pref.view_eid
else:
self.folders=False
self.noo="Oldest"
self.grouping="None"
self.how_many="50"
# retreive defaults from 'PAUser' where defaults are stored
u=PAUser.query.filter(PAUser.dn==current_user.dn).one()
self.grouping=u.default_grouping
self.how_many=u.default_how_many
self.offset="0"
self.size="128"
self.size=u.default_size
if self.path_type == "View":
self.root='static/' + self.orig_ptype
tmp=self.orig_ptype
else:
self.root='static/' + self.path_type
tmp=self.path_type
if tmp == 'Import':
self.noo = u.default_import_noo
self.folders = u.default_import_folders
elif tmp == 'Storage':
self.noo = u.default_storage_noo
self.folders = u.default_storage_folders
else:
# is a search so...
print( "For now, search defaults for noo / folders are hardcoded" )
self.folders=False
self.noo = 'Oldest'
self.cwd=self.root
if not hasattr(self, 'orig_ptype'):
self.orig_ptype=None
@@ -206,12 +207,14 @@ class States(PA):
if 'next' in request.form:
self.offset += int(self.how_many)
# now save pref (if this is 'another' search, view, etc. then it will add a row for it with matching search_term, or view_eid, etc.
# now save pref
if not pref:
# insert new pref for this combo (might be a new search or view, or first time for a path)
pref=PA_UserState( pa_user_dn=current_user.dn, path_type=self.path_type, view_eid=self.view_eid, 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,
orig_ptype=self.orig_ptype, orig_search_term=self.orig_search_term, orig_url=self.orig_url )
else:
# update this pref with the values calculated above (most likely from POST to form)
pref.pa_user_dn=current_user.dn
pref.path_type=self.path_type
pref.view_eid=self.view_eid