Files
photoassistant/options.py

65 lines
2.6 KiB
Python

from settings import Settings
from shared import PA
################################################################################
# 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):
self.noo="Oldest"
self.grouping="None"
self.how_many="50"
self.offset="0"
self.size="128"
self.folders=True
settings=Settings.query.first()
if 'orig_url' in request.form:
url = request.form['orig_url']
else:
url = request.path
if 'files_sp' in url:
self.noo="A to Z"
self.path_type = 'Storage'
self.paths = settings.storage_path.split("#")
elif 'files_rbp' in url:
self.path_type = 'Bin'
self.paths = settings.recycle_bin_path.split("#")
else:
self.folders=False
self.path_type = 'Import'
self.cwd='static/Import'
self.paths = settings.import_path.split("#")
self.cwd='static/' + self.path_type
self.root=self.cwd
# the above are defaults, if we are here, then we have current values, use them instead
if request.method=="POST":
self.noo=request.form['noo']
self.how_many=request.form['how_many']
self.offset=int(request.form['offset'])
self.grouping=request.form['grouping']
self.size = request.form['size']
# seems html cant do boolean, but uses strings so convert
if request.form['folders'] == "False":
self.folders=False
if 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
self.cwd = request.form['cwd']
if 'fullscreen' in request.form:
self.fullscreen=request.form['fullscreen']
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)