def toolsHomeView(): """Index page for the 'tools' tasks, which are elsewhere in themselves.""" user = g.user db = dbGetDatabase() # filteredToolsPageDescriptor = g.availableTools # pageFeatures = prepareTaskPageFeatures( filteredToolsPageDescriptor, ['root'], g, ) return render_template( 'tasks.html', user=user, bgcolor=g.settings['color']['task_colors']['tool_task']['value'], **pageFeatures, )
def appsView(): """Main apps page with tasks (each an available app).""" user = g.user db = dbGetDatabase() request._onErrorUrl = url_for( 'lsView', lsPathString='', ) # filteredAppsPageDescriptor = g.availableApps # pageFeatures = prepareTaskPageFeatures( filteredAppsPageDescriptor, ['root'], g, ) return render_template( 'tasks.html', user=user, bgcolor=g.settings['color']['task_colors']['info_task']['value'], **pageFeatures, )
def calendarMakerIndexView(): """Main calendar maker view.""" user = g.user db = dbGetDatabase() request._onErrorUrl = url_for( 'lsView', lsPathString='', ) # destBoxString = request.cookies.get('apps_calendarmaker_destbox') currentCalendar = cookiesToCurrentCalendar(request.cookies) coverImagePathString = currentCalendar.get('cover_image_path_string') calendarImagePaths = currentCalendar.get('image_path_strings', []) cProps = currentCalendar.get('properties', {}) # if destBoxString is None: destBoxMessage = 'Destination box not set.' destBox = None destBoxName = None else: destBoxMessage = 'Destination box: "%s".' % destBoxString destBoxPath = splitPathString(destBoxString) destBox = getBoxFromPath(db, destBoxPath, user) destBoxName = describeBoxName(destBox) if coverImagePathString is None: coverMessage = 'Please select a cover' coverImageFileObject = None else: coverMessage = 'Cover selected' coverImageFileObject = pathToFileStructure( db, user, coverImagePathString, ) # calendarImages = [ pathToFileStructure(db, user, imgPath) for imgPath in calendarImagePaths ] # numRequiredImages = countMonths( cProps.get('year0'), cProps.get('month0'), cProps.get('year1'), cProps.get('month1'), ) # settingsDesc = describeSettings(cProps) settingsSummaryText = ('Not set' if settingsDesc is None else ' '.join( '%s.' % stc for stc in settingsDesc)) # if numRequiredImages is not None: if numRequiredImages <= len(calendarImages): gen1 = True gen1Message = [] else: gen1 = False gen1Message = ['Select enough images'] else: gen1 = False gen1Message = ['Set valid start/end dates'] if destBox is not None: gen2 = True gen2Message = [] else: gen2 = False gen2Message = ['Select a destination box'] if coverImageFileObject is not None: gen0 = True gen3Message = [] else: gen0 = False gen3Message = ['Select a cover image'] canGenerate = all([gen0, gen1, gen2]) generationMessages = gen3Message + gen1Message + gen2Message pageFeatures = prepareTaskPageFeatures( appsPageDescriptor, ['root', 'calendar_maker'], g, overrides={ 'pageSubtitle': ('Create your own custom calendar. (1) Configure ' 'dates and calendar appearance. (2) Select enoug' 'h images. (3) Choose a destination box for the ' 'calendar. (4) Hit "Generate calendar".'), }, ) # return render_template( 'apps/calendarmaker/index.html', user=user, settingsText=settingsSummaryText, destBox=destBox, destBoxName=destBoxName, bgcolor=g.settings['color']['app_colors']['calendar_maker_color'] ['value'], calendarImages=calendarImages, coverImageFileObject=coverImageFileObject, numRequiredImages=numRequiredImages, canGenerate=canGenerate, generationMessages=generationMessages, **pageFeatures, )
def calendarMakerImagesView(): """Calendar image-selection page view.""" user = g.user db = dbGetDatabase() request._onErrorUrl = url_for( 'calendarMakerIndexView', lsPathString='', ) # browseBoxString = request.cookies.get('apps_calendarmaker_browsebox') currentCalendar = cookiesToCurrentCalendar(request.cookies) coverImagePathString = currentCalendar.get('cover_image_path_string') calendarImagePaths = currentCalendar.get('image_path_strings', []) cProps = currentCalendar.get('properties', {}) # if coverImagePathString is None: coverImageFileObject = None else: coverImageFileObject = pathToFileStructure( db, user, coverImagePathString, ) # if browseBoxString is not None: browseBoxPath = splitPathString(browseBoxString) browseBox = getBoxFromPath(db, browseBoxPath, user) choosableFiles = [{ 'file': file, 'path': browseBoxPath[1:] + [file.name], 'obj_path': urllib.parse.quote_plus('/'.join(browseBoxPath[1:] + [file.name], )), } for file in sorted( getFilesFromBox(db, browseBox), key=lambda f: (f.name.lower(), f.name), ) if file.mime_type in admittedImageMimeTypeToExtension] browseBoxName = describeBoxName(browseBox) else: browseBox = None browseBoxName = None choosableFiles = [] # calendarImages = [ pathToFileStructure(db, user, imgPath) for imgPath in calendarImagePaths ] # numRequiredImages = countMonths( cProps.get('year0'), cProps.get('month0'), cProps.get('year1'), cProps.get('month1'), ) # pageFeatures = prepareTaskPageFeatures( appsPageDescriptor, ['root', 'calendar_maker', 'images'], g, ) return render_template( 'apps/calendarmaker/images.html', user=user, browseBox=browseBox, browseBoxName=browseBoxName, choosableFiles=choosableFiles, coverImageFileObject=coverImageFileObject, bgcolor=g.settings['color']['app_colors']['calendar_maker_color'] ['value'], bgcolorbrowse=g.settings['color']['app_colors'] ['calendar_maker_browse_color']['value'], calendarImages=calendarImages, numRequiredImages=numRequiredImages, **pageFeatures, )
def calendarMakerSettingsView(): """Calendar settings form view.""" user = g.user db = dbGetDatabase() request._onErrorUrl = url_for('calendarMakerIndexView', ) # currentCalendar = cookiesToCurrentCalendar(request.cookies) cProps = currentCalendar.get('properties', {}) currentYear = datetime.datetime.now().year form = CalendarMakerPropertyForm() # if form.validate_on_submit(): month0 = safeInt(form.month0.data, 1) year0 = form.year0.data month1 = safeInt(form.month1.data, 12) year1 = form.year1.data language = form.language.data startingweekday = safeInt(form.startingweekday.data, 6) response = redirect(url_for('calendarMakerIndexView')) dResponse = dressResponseWithCurrentCalendar( response, recursivelyMergeDictionaries( { 'properties': { 'month0': month0, 'year0': year0, 'month1': month1, 'year1': year1, 'language': language, 'startingweekday': startingweekday, }, }, defaultMap=currentCalendar, ), ) return dResponse else: form.month0.data = str(applyDefault(cProps.get('month0'), 1)) form.year0.data = applyDefault(cProps.get('year0'), currentYear) form.month1.data = str(applyDefault(cProps.get('month1'), 12)) form.year1.data = applyDefault(cProps.get('year1'), currentYear) form.language.data = applyDefault(cProps.get('language'), 'en') form.startingweekday.data = applyDefault( cProps.get('startingweekday'), 6, ) # pageFeatures = prepareTaskPageFeatures( appsPageDescriptor, ['root', 'calendar_maker', 'settings'], g, ) # return render_template( 'apps/calendarmaker/settings.html', user=user, bgcolor=g.settings['color']['app_colors']['calendar_maker_color'] ['value'], form=form, **pageFeatures, )
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, )
def findView(): """Complete (i.e. in-page) box- and file-find route.""" user = g.user db = dbGetDatabase() form = FindForm() # if not g.canPerformSearch: raise OstracionError('Insufficient permissions') # if form.validate_on_submit(): # search parameter collection searchMode = form.searchMode.data searchBoxes = form.searchTypeBoxes.data searchFiles = form.searchTypeFiles.data searchLinks = form.searchTypeLinks.data searchInDescription = form.searchFieldDescription.data searchTerm = form.text.data options = { 'mode': searchMode, 'searchBoxes': searchBoxes, 'searchFiles': searchFiles, 'searchLinks': searchLinks, 'useDescription': searchInDescription, } # initTime = time.time() findResults = fsFind( db, searchTerm, user, options=options, ) resultsDescription = describeFindResults(findResults) elapsed = time.time() - initTime # pageFeatures = prepareTaskPageFeatures( toolsPageDescriptor, ['root', 'search'], g, overrides={ 'pageTitle': 'Search results', 'pageSubtitle': 'Search term: "%s"' % searchTerm, }, ) return render_template( 'findform.html', user=user, form=form, findResults=findResults, resultsDescription=resultsDescription, elapsed=elapsed, searchTerm=searchTerm, **pageFeatures, ) else: # form.searchMode.data = applyDefault( form.searchMode.data, 'sim_ci', additionalNulls=['None'], ) print(form.searchTypeBoxes.data) form.searchTypeBoxes.data = applyDefault( form.searchTypeBoxes.data, True, ) form.searchTypeFiles.data = applyDefault( form.searchTypeFiles.data, True, ) form.searchTypeLinks.data = applyDefault( form.searchTypeLinks.data, True, ) print(form.searchTypeBoxes.data) pageFeatures = prepareTaskPageFeatures( toolsPageDescriptor, ['root', 'search'], g, ) return render_template( 'findform.html', user=user, form=form, results=None, **pageFeatures, )
def setIconView(mode, itemPathString=''): """ Route to set/replace the thumbnail of various items.""" if (mode == 'au' and not g.settings['behaviour']['behaviour_admin_powers'] ['admin_is_god']['value']): request._onErrorUrl = url_for('adminHomeUsersView') raise OstracionError('This feature is turned off in the configuration') else: user = g.user form = UploadIconForm() db = dbGetDatabase() tempFileDirectory = g.settings['system']['system_directories'][ 'temp_directory']['value'] fileStorageDirectory = g.settings['system']['system_directories'][ 'fs_directory']['value'] if mode == 'b': boxPath = splitPathString(itemPathString) request._onErrorUrl = url_for( 'lsView', lsPathString='/'.join(boxPath[1:]), ) parentBox = None thisItem = getBoxFromPath(db, boxPath, user) itemName = thisItem.getName() pageFeatures = { 'breadCrumbs': makeBreadCrumbs( splitPathString(itemPathString), g, appendedItems=[{ 'kind': 'link', 'target': None, 'name': 'Icon', }], ), } elif mode == 'f': fullPath = splitPathString(itemPathString) boxPath, fileName = fullPath[:-1], fullPath[-1] request._onErrorUrl = url_for( 'lsView', lsPathString='/'.join(boxPath[1:]), ) parentBox = getBoxFromPath(db, boxPath, user) thisItem = getFileFromParent(db, parentBox, fileName, user) itemName = thisItem.getName() pageFeatures = { 'breadCrumbs': makeBreadCrumbs( splitPathString(itemPathString)[:-1], g, appendedItems=[{ 'kind': 'file', 'target': thisItem, }, { 'kind': 'link', 'target': None, 'name': 'Icon', }], ), } elif mode == 'l': fullPath = splitPathString(itemPathString) boxPath, linkName = fullPath[:-1], fullPath[-1] request._onErrorUrl = url_for( 'lsView', lsPathString='/'.join(boxPath[1:]), ) parentBox = getBoxFromPath(db, boxPath, user) thisItem = getLinkFromParent(db, parentBox, linkName, user) itemName = thisItem.getName() pageFeatures = { 'breadCrumbs': makeBreadCrumbs( splitPathString(itemPathString)[:-1], g, appendedItems=[{ 'kind': 'external_link', 'target': thisItem, }, { 'kind': 'link', 'target': None, 'name': 'Icon', }], ), } elif mode == 'u': pageFeatures = prepareTaskPageFeatures( userProfilePageDescriptor, ['root', 'icon'], g, overrides={ 'pageTitle': None, 'pageSubtitle': None, 'iconUrl': None, }, ) thisItem = user itemName = thisItem.getName() parentBox = None elif mode == 'au': pageFeatures = prepareTaskPageFeatures( adminPageDescriptor, ['root', 'users'], g, appendedItems=[{ 'kind': 'link', 'link': False, 'target': None, 'name': 'Icon', }], overrides={ 'pageTitle': None, 'pageSubtitle': None, 'iconUrl': None, }, ) if userIsAdmin(db, user): thisItem = dbGetUser(db, itemPathString) itemName = thisItem.getName() parentBox = None else: raise OstracionError('Insufficient permissions') elif mode == 's': pageFeatures = prepareTaskPageFeatures( adminPageDescriptor, ['root', 'settings', 'images'], g, appendedItems=[{ 'kind': 'link', 'link': False, 'target': None, 'name': 'Set image', }], overrides={ 'pageTitle': None, 'pageSubtitle': None, 'iconUrl': None, }, ) if userIsAdmin(db, user): settingGroupId, settingId = itemPathString.split('/') thisItem = g.settings['image'][settingGroupId][settingId] itemName = thisItem['setting'].getName() parentBox = None else: raise OstracionError('Insufficient permissions') else: raise RuntimeError('Unknown mode encountered') # if form.validate_on_submit(): # storageSuccess = storeFileAsThumbnail( db, fileToSave=form.file.data, mode=mode, thumbnailFormat=determineThumbnailFormatByModeAndTarget( db, mode, thisItem, ), targetItem=thisItem, parentBox=parentBox, user=user, tempFileDirectory=tempFileDirectory, fileStorageDirectory=fileStorageDirectory, ) if not storageSuccess: raise OstracionError('Could not set the icon') # if mode in {'f', 'b', 'l'}: return redirect( url_for( 'lsView', lsPathString='/'.join(boxPath[1:-1] if mode == 'b' else boxPath[1:]), )) elif mode == 'u': return redirect(url_for('userProfileView', )) elif mode == 'au': return redirect(url_for('adminHomeUsersView', )) elif mode == 's': return redirect(url_for('adminHomeSettingsImagesView', )) else: raise RuntimeError('Unknown mode encountered') else: # titleMap = { 'f': 'Set File Icon', 'l': 'Set Link Icon', 'b': 'Set Box Icon', 'u': 'Set User Icon', 'au': 'Set User Icon (as admin)', 's': 'Set Application Image', } modeNameMap = { 'f': 'for file', 'l': 'for link', 'b': 'for box', 'u': 'for user', 'au': '(as admin) for user', 's': 'for setting', } finalPageFeatures = recursivelyMergeDictionaries( { 'pageTitle': titleMap[mode], 'pageSubtitle': 'Upload an image file %s "%s"' % ( modeNameMap[mode], itemName, ), }, defaultMap=pageFeatures, ) if mode == 'u': finalPageFeatures['iconUrl'] = url_for( 'userThumbnailView', dummyId='%s_' % thisItem.icon_file_id, username=thisItem.username, ) elif mode == 'au': finalPageFeatures['iconUrl'] = url_for( 'userThumbnailView', dummyId='%s_' % thisItem.icon_file_id, username=thisItem.username, ) elif mode == 's': finalPageFeatures['iconUrl'] = makeSettingImageUrl( g, settingGroupId, settingId, ) elif mode == 'b': finalPageFeatures['iconUrl'] = url_for( 'boxThumbnailView', dummyId=thisItem.icon_file_id + '_', boxPathString='/'.join(boxPath[1:]), ) elif mode == 'f': finalPageFeatures['iconUrl'] = url_for( 'fileThumbnailView', dummyId=thisItem.icon_file_id + '_', fsPathString='/'.join(boxPath[1:] + [thisItem.name]), ) elif mode == 'l': finalPageFeatures['iconUrl'] = url_for( 'linkThumbnailView', dummyId=thisItem.icon_file_id + '_', fsPathString='/'.join(boxPath[1:] + [thisItem.name]), ) # return render_template( 'uploadicon.html', form=form, user=user, mode=mode, itemPathString=itemPathString, **finalPageFeatures, )