Ejemplo n.º 1
0
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)
    )
Ejemplo n.º 2
0
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'))