def preparePickBoxPageView(db, user, callbackUrl, startBox, message, predicate=lambda richFileOrBox: True): """ Prepare a full response for a "select box" view. Boxes are made selectable according to a 'predicate' and upon selection the callback URL is invokect, with the chosen box path passed as querystring parameter 'chosenBoxObjPath'. """ dstBoxTree = collectTreeFromBox( db, startBox, user, admitFiles=False, fileOrBoxEnricher=lambda richBox: { 'obj_path': urllib.parse.quote_plus('/'.join(richBox['path'])), }, predicate=predicate, ) # maxDepth = getMaxTreeDepth(dstBoxTree) colorShadeMap = prepareColorShadeMap( g.settings['color']['navigation_colors']['box']['value'], g.settings['color']['tree_shade_colors']['shade_treeview_pickbox'] ['value'], numShades=1 + maxDepth, ) # return render_template( 'dirtreeview.html', tree=dstBoxTree, mode='pick_box', object_quoted_path=callbackUrl, colorShadeMap=colorShadeMap, user=user, iconUrl=makeSettingImageUrl(g, 'app_images', 'move'), pageTitle='Choose a box', pageSubtitle=message, actions=None, backToUrl=None, breadCrumbs=[ { 'kind': 'link', 'target': None, 'name': 'Move box', }, ], )
def fsMoveBoxView(quotedSrcBox): """ Move-box-phase-1 route: where the source box is selected (and then in offering the choose-dest-box it is put in the URL for calling phase two). """ user = g.user db = dbGetDatabase() # first we find the box bxPathString = urllib.parse.unquote_plus(quotedSrcBox) boxPath = splitPathString(bxPathString) parentBox = getBoxFromPath(db, boxPath[:-1], user) request._onErrorUrl = url_for( 'lsView', lsPathString='/'.join(boxPath[1:-1]), ) box = getBoxFromPath(db, boxPath, user) if not canDeleteBox(db, box, parentBox, user): raise OstracionWarning('Cannot act on this object') # next we prepare the selectable destinations rootBox = getRootBox(db) def rbPredicate(richBox, _box=box, _srcBox=parentBox): _dstBox = richBox['box'] if _box.parent_id != _dstBox.box_id: if all(userHasPermission(db, user, _dstBox.permissions, prm) for prm in {'w', 'c'}): if not isNameUnderParentBox(db, _dstBox, _box.box_name): if not isAncestorBoxOf(db, _box, _dstBox): return True return False dstBoxTree = collectTreeFromBox( db, rootBox, user, admitFiles=False, fileOrBoxEnricher=lambda richBox: { 'obj_path': urllib.parse.quote_plus('/'.join(richBox['path'])), }, predicate=rbPredicate, ) # maxDepth = getMaxTreeDepth(dstBoxTree) colorShadeMap = prepareColorShadeMap( g.settings['color']['navigation_colors']['box']['value'], g.settings['color']['tree_shade_colors'][ 'shade_treeview_pickbox']['value'], numShades=1 + maxDepth, ) destinationsExist = treeAny( dstBoxTree, property=lambda node: node['predicate'], ) # return render_template( 'dirtreeview.html', tree=dstBoxTree if destinationsExist else None, mode='box_move', object_quoted_path=quotedSrcBox, colorShadeMap=colorShadeMap, user=user, iconUrl=makeSettingImageUrl(g, 'app_images', 'move'), pageTitle='Select box destination', pageSubtitle=('Choose the box to which box "%s" ' 'shall be moved from "%s"') % ( describeBoxTitle(box), describeBoxTitle(parentBox), ), actions=None, backToUrl=(None if destinationsExist else url_for( 'lsView', lsPathString='/'.join(boxPath[1:]))), breadCrumbs=makeBreadCrumbs( boxPath, g, appendedItems=[ { 'kind': 'link', 'target': None, 'name': 'Move box', } ], ), )
def fsMoveFileView(quotedFilePath): """Move-file, view 1/2: select destination box.""" user = g.user db = dbGetDatabase() # first we find the file fsPathString = urllib.parse.unquote_plus(quotedFilePath) lsPath = splitPathString(fsPathString) boxPath, fileName = lsPath[:-1], lsPath[-1] parentBox = getBoxFromPath(db, boxPath, user) file = getFileFromParent(db, parentBox, fileName, user) # next we prepare the selectable destinations rootBox = getRootBox(db) def rbPredicate(richBox, idToAvoid=parentBox.box_id): return all((richBox['box'].box_id != idToAvoid, userHasPermission(db, user, richBox['box'].permissions, 'w'))) dstBoxTree = collectTreeFromBox( db, rootBox, user, admitFiles=False, fileOrBoxEnricher=lambda richBox: { 'obj_path': urllib.parse.quote_plus('/'.join(richBox['path'])), }, predicate=rbPredicate, ) # maxDepth = getMaxTreeDepth(dstBoxTree) colorShadeMap = prepareColorShadeMap( g.settings['color']['navigation_colors']['file']['value'], g.settings['color']['tree_shade_colors']['shade_treeview_pickbox'] ['value'], numShades=1 + maxDepth, ) destinationsExist = treeAny( dstBoxTree, property=lambda node: node['predicate'], ) # return render_template( 'dirtreeview.html', tree=dstBoxTree if destinationsExist else None, mode='file_move', object_quoted_path=quotedFilePath, colorShadeMap=colorShadeMap, user=user, iconUrl=makeSettingImageUrl(g, 'app_images', 'move'), pageTitle='Select file destination', pageSubtitle=(('Choose the box to which file "%s" shall ' 'be moved from "%s"') % ( file.name, describeBoxTitle(parentBox), )), actions=None, backToUrl=None if destinationsExist else url_for( 'lsView', lsPathString='/'.join(boxPath[1:]), ), breadCrumbs=makeBreadCrumbs( boxPath, g, appendedItems=[{ 'kind': 'file', 'target': file, }, { 'kind': 'link', 'target': None, 'name': 'Move file', }], ), )
def dirTreeView(includeFiles=0): """ Box-tree route. Can show files or not depending of optional parameter 'includeFiles' and the availability of files as configured in settings. """ user = g.user db = dbGetDatabase() # if not g.canShowTreeView: raise OstracionError('Insufficient permissions') # canIncludeFiles = g.settings['behaviour']['search'][ 'tree_view_files_visible']['value'] if not canIncludeFiles: includeFiles = 0 availableViewModes = [0] + ([1] if canIncludeFiles else []) viewModeActions = {} if len(availableViewModes) > 1: if includeFiles == 0: viewModeActions['disabled_hide_tree_files'] = 'yes' else: viewModeActions['hide_tree_files'] = url_for( 'dirTreeView', includeFiles=0, ) if includeFiles != 0: viewModeActions['disabled_show_tree_files'] = 'yes' else: viewModeActions['show_tree_files'] = url_for( 'dirTreeView', includeFiles=1, ) else: raise NotImplementedError('no available view modes in dirTreeView') # rootBox = getRootBox(db) tree = collectTreeFromBox(db, rootBox, user, includeFiles != 0) # maxDepth = getMaxTreeDepth(tree) if includeFiles: gradientDestinationColor = g.settings['color']['tree_shade_colors'][ 'shade_treeview_files']['value'] else: gradientDestinationColor = g.settings['color']['tree_shade_colors'][ 'shade_treeview_boxes']['value'] # colorShadeMap = prepareColorShadeMap( g.settings['color']['navigation_colors']['box']['value'], gradientDestinationColor, numShades=1 + maxDepth, ) # pageFeatures = prepareTaskPageFeatures( toolsPageDescriptor, ['root', 'tree_view'], g, ) # return render_template( 'dirtreeview.html', tree=tree, mode='tree_view', colorShadeMap=colorShadeMap, user=user, actions=viewModeActions, **pageFeatures, )