Beispiel #1
0
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')
        )
Beispiel #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'))