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

37. SQLALCHEMY + URL DISPATCH WIKI TUTORIAL

37.2 Design

Following is a quick overview of the design of our wiki application, to help us understand the changes that we will be making as we work through the tutorial.

37.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.

37.2.2 Models

We’ll be using a SQLite database to hold our wiki data, and we’ll be using SQLAlchemy to access the data in this database.

Within the database, we define a single table named tables, whose elements will store the wiki pages. There are two columns: name and data.

URLs like /PageName will try to find an element in the table that has a corresponding name.

To add a page to the wiki, a new row is created and the text is stored in data.

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.

37.2.3 Views

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

440

37.2. DESIGN

37.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.

 

 

 

37.2.5 Summary

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

441

37. SQLALCHEMY + URL DISPATCH WIKI TUTORIAL

URL

Action

 

 

 

View

Template

Permission

/

Redirect

to

/Front-

view_wiki

 

 

 

Page

 

 

 

 

 

 

 

/PageName

Display

 

existing

view_page 2

view.pt

view

 

page 1

 

 

 

 

 

 

/edit_page/PageName

Display

edit

form

edit_page

edit.pt

edit

 

with

existing

con-

 

 

 

 

tent.

 

 

 

 

 

 

 

 

If the form was sub-

 

 

 

 

mitted,

redirect to

 

 

 

 

/PageName

 

 

 

 

 

/add_page/PageName

Create

the

page

add_page

edit.pt

edit

 

PageName in

stor-

 

 

 

 

age,

display

the

 

 

 

 

edit

form

without

 

 

 

 

content.

 

 

 

 

 

 

 

If the form was sub-

 

 

 

 

mitted,

redirect to

 

 

 

 

/PageName

 

 

 

 

 

/login

Display login form.

login

login.pt

 

 

If the

form

was

 

 

 

 

submitted, authenti-

 

 

 

 

cate.

 

 

 

 

 

 

 

 

If authentica-

 

 

 

 

 

tion success-

 

 

 

 

 

ful,

redirect

 

 

 

 

 

to

the

page

 

 

 

 

 

that we came

 

 

 

 

 

from.

 

 

 

 

 

 

If

authenti-

 

 

 

 

 

cation

fails,

 

 

 

 

 

display

login

 

 

 

 

 

form

 

with

 

 

 

 

 

“login failed”

 

 

 

 

 

message.

 

 

 

 

 

 

 

 

 

 

/logout

Redirect

to

/Front-

logout

 

 

 

Page

 

 

 

 

 

 

 

442

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