def display_admin_resources(): '''This routine displays the administration tools for resource units. It is password protected because the listing page allows administrative features. ''' return display_content( breadcrumbs=get_breadcrumbs('admin', 'resources'), title='Administration: Resources', primaryList=create_admin_resources_list(Resources.read_units()), primaryListHr=True, editable=False )
def display_resources(): '''Configure and display the resources overview page.''' return display_content( breadcrumbs=get_breadcrumbs('resources'), image=Images.read_tagged_unit('resources'), title='Department Resources', primary='''The Department of Computer Science offers the following resources.''', primaryList=create_resources_list(Resources.read_units()), primaryListHr=False, editable=False )
def display_resource(name): '''This routine displays a given resource. It is not password protected because all resources are visible to all visitors. ''' resource = check_unit(Resources.read_unit(name)) return display_content( breadcrumbs=get_breadcrumbs('resources', name), title=resource.get('title'), primary=resource.get('content'), tabList=create_resource_tab_list(resource), editable=True, editableUrl=url_for('web.update_resource', name=name) )
def create_resource(): '''This routine displays an editing page for creating an resource.''' form = Resources() if form.is_submitted(): if form.validate() and request.form.get('submit'): Resources.create_unit(form) return redirect(url_for('web.display_resource', name=form.getName())) else: return redirect(url_for('web.display_admin_resources')) else: form.initialize(action='create') return display_content( form=form, title='Create resource', breadcrumbs=get_breadcrumbs('resources', 'create') )
def update_resource(name): '''For GET requests, this method allows the administrator to edit the named resource. For POST requests, this method saves the edits made by the administrator and then reloads/redisplays the resource administration page. Non-authenticated users are redirected to the login page. resources that don't exist can't be edited. Because we don't show individual resources, all redirects go to the resources administration page. ''' form = Resources() if form.is_submitted(): if form.validate() and request.form.get('submit'): Resources.update_unit(form) return redirect(url_for('web.display_resource', name=form.getName())) else: resource = Resources.read_unit(name) if resource: form.initialize(name=name, action='update', resource=resource) return display_content( form=form, title='Edit: ' + name, breadcrumbs=get_breadcrumbs('resources', name, 'edit') ) return redirect(url_for('web.display_admin_resources'))
def delete_resource(name): '''This routine deletes the given resource entry, but it leaves the actual resource in place. ''' Resources.delete_unit(name) return redirect(url_for('web.display_admin_resources'))