Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
pyramid.pdf
Скачиваний:
11
Добавлен:
24.03.2015
Размер:
3.82 Mб
Скачать

36. ZODB + TRAVERSAL WIKI TUTORIAL

36.2 Design

Following is a quick overview of our wiki application, to help us understand the changes that we will be doing next in our default files generated by the zodb scafffold.

36.2.1 Overall

We choose to use reStructuredText markup in the wiki text. Translation from reStructuredText to HTML is provided by the widely used docutils Python module. We will add this module in the dependency list on the project setup.py file.

36.2.2 Models

The root resource, named Wiki, will be a mapping of wiki page names to page resources. The page resources will be instances of a Page class and they store the text content.

URLs like /PageName will be traversed using Wiki[ PageName ] => page, and the context that results is the page resource of an existing page.

To add a page to the wiki, a new instance of the page resource is created and its name and reference are added to the Wiki mapping.

A page named FrontPage containing the text This is the front page, will be created when the storage is initialized, and will be used as the wiki home page.

36.2.3 Views

There will be four views to handle the normal operations of viewing, editing and adding wiki pages. Two additional views will handle the login and logout tasks related to security.

390

36.2. DESIGN

36.2.4 Security

We’ll eventually be adding security to our application. The components we’ll use to do this are below.

• USERS, a dictionary mapping users names to their corresponding passwords.

• GROUPS, a dictionary mapping user names to a list of groups they belong to.

• groupfinder, an authorization callback that looks up USERS and GROUPS. It will be provided in

 

a new security.py file.

 

 

An ACL is attached to the root resource. Each row below details an ACE:

 

 

 

 

 

 

Action

Principal

Permission

 

Allow

Everyone

View

 

 

Allow

group:editors

Edit

 

Permission declarations are added to the views to assert the security policies as each request is

 

handled.

 

 

 

36.2.5 Summary

The URL, context, actions, template and permission associated to each view are listed in the following table:

391

36. ZODB + TRAVERSAL WIKI TUTORIAL

URL

View

Context

Action

 

Template

Permission

/

view_wiki

Wiki

Redirect

to

 

 

 

 

 

/FrontPage

 

 

 

/PageName

view_page 1

Page

Display existing

view.pt

view

 

 

 

page 2

 

 

 

/PageName/edit_

pageedit_page

Page

Display

edit

edit.pt

edit

 

 

 

form

 

with

 

 

 

 

 

existing content.

 

 

 

 

 

If

the

form

 

 

 

 

 

was

submit-

 

 

 

 

 

ted,

redirect to

 

 

 

 

 

/PageName

 

 

/add_page/PageNameadd_page

Wiki

Create the page

edit.pt

edit

 

 

 

PageName

in

 

 

 

 

 

storage, display

 

 

 

 

 

the

edit

form

 

 

 

 

 

without content.

 

 

 

 

 

If

the

form

 

 

 

 

 

was

submit-

 

 

 

 

 

ted,

redirect to

 

 

 

 

 

/PageName

 

 

/login

login

Wiki, Forbidden

Display

login

login.pt

 

 

 

3

form.

 

 

 

 

 

 

 

 

 

 

 

 

If

the

form

 

 

 

 

 

was

submitted,

 

 

 

 

 

authenticate.

 

 

 

 

 

If authen-

 

 

 

 

 

 

tication

 

 

 

 

 

 

suc-

 

 

 

 

 

 

 

cessful,

 

 

 

 

 

 

redirect

 

 

 

 

 

 

to

the

 

 

 

 

 

 

page

that

 

 

 

 

 

 

we

came

 

 

 

 

 

 

from.

 

 

 

 

 

If authen-

 

 

 

 

 

 

tication

 

 

 

 

 

 

fails,

dis-

 

 

 

 

 

 

play login

 

 

 

 

 

 

form with

 

 

 

 

 

 

“login

 

 

 

 

 

 

failed”

 

 

 

 

 

 

message.

 

 

 

 

 

 

 

 

 

/logout

logout

Wiki

Redirect

to

 

 

 

 

392

/FrontPage

 

 

 

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]