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