示例#1
0
文件: views.py 项目: Calvin-CS/csweb
def create_image():
    '''This routine displays an editing page for creating an image.'''
    form = Images()
    if form.is_submitted():
        if form.validate() and request.form.get('submit'):
            Images.create_unit(form)
            return redirect(url_for('web.display_image',
                            name=form.getName()))
        else:
            return redirect(url_for('web.display_admin_images'))
    else:
        form.initialize(action='create')
        return display_content(
            form=form,
            title='Create Image',
            breadcrumbs=get_breadcrumbs('images', 'create')
        )
示例#2
0
文件: views.py 项目: Calvin-CS/csweb
def update_image(name):
    '''For GET requests, this method allows the administrator to edit the named
       image. For POST requests, this method saves the edits made by the
       administrator and then reloads/redisplays the image admin page.
       Non-authenticated users are redirected to the login page. Images that
       don't exist can't be edited. Because we don't show individual images,
       all redirects go to the images admin page.
    '''
    form = Images()
    if form.is_submitted():
        if form.validate() and request.form.get('submit'):
            Images.update_unit(form)
            return redirect(url_for('web.display_image',
                            name=form.getName()))
    else:
        image = Images.read_unit(name)
        if image:
            form.initialize(name=name, action='update', image=image)
            return display_content(
                form=form,
                title='Edit: ' + name,
                breadcrumbs=get_breadcrumbs('images', name, 'edit')
            )
    return redirect(url_for('web.display_admin_images'))