'Edit a page\'s attributes.'

@web.expose
@web.require_login('edit    pages')
def edit(self, trans, id, page_title='', page_slug='', page_annotation=''):

    encoded_id = id
    id = self.decode_id(id)
    session = trans.sa_session
    page = session.query(model.Page).get(id)
    user = trans.user
    assert (page.user == user)
    page_title_err = page_slug_err = page_annotation_err = ''
    if (trans.request.method == 'POST'):
        if (not page_title):
            page_title_err = 'Page    name    is    required'
        elif (not page_slug):
            page_slug_err = 'Page    id    is    required'
        elif (not self._is_valid_slug(page_slug)):
            page_slug_err = "Page    identifier    must    consist    of    only    lowercase    letters,    numbers,    and    the    '-'    character"
        elif ((page_slug != page.slug) and trans.sa_session.query(model.Page).filter_by(user=user, slug=page_slug, deleted=False).first()):
            page_slug_err = 'Page    id    must    be    unique'
        elif (not page_annotation):
            page_annotation_err = 'Page    annotation    is    required'
        else:
            page.title = page_title
            page.slug = page_slug
            page_annotation = sanitize_html(page_annotation, 'utf-8', 'text/html')
            self.add_item_annotation(trans.sa_session, trans.get_user(), page, page_annotation)
            session.flush()
            return trans.response.send_redirect(web.url_for(controller='pages', action='list'))
    else:
        page_title = page.title
        page_slug = page.slug
        page_annotation = self.get_item_annotation_str(trans.sa_session, trans.user, page)
        if (not page_annotation):
            page_annotation = ''
    return trans.show_form(web.FormBuilder(web.url_for(controller='page', action='edit', id=encoded_id), 'Edit    page    attributes', submit_text='Submit').add_text('page_title', 'Page    title', value=page_title, error=page_title_err).add_text('page_slug', 'Page    identifier', value=page_slug, error=page_slug_err, help="A    unique    identifier    that    will    be    used    for\n                                                                                            public    links    to    this    page.    A    default    is    generated\n                                                                                            from    the    page    title,    but    can    be    edited.    This    field\n                                                                                            must    contain    only    lowercase    letters,    numbers,    and\n                                                                                            the    '-'    character.").add_text('page_annotation', 'Page    annotation', value=page_annotation, error=page_annotation_err, help='A    description    of    the    page;    annotation    is    shown    alongside    published    pages.'), template='page/create.mako')
