Web to py enterprise web framework - p 10

A WIKI 75 66 67 68 69 70 71 pattern = '%' + () + '%' pages = db(().like(pattern))\ .select(orderby=) items = [A(, _href=URL(r=request, f=show, args=)) \ for row in pages] return UL(*items).xml() Lines 2-6 provide a comment for the index action. Lines 4-5 inside the comment are interpreted by python as test code (doctest). Tests can be run via the admin interface. In this case the tests verify that the index action runs without errors. Lines 19, 33, and 43 try fetch a page record with the id in (0). Line 14, 24 and 47 define and process create forms, for a new page. | AWIKI 75 66 pattern request .vars .keyword. lower 67 pages db . title . lower .like pattern 68 . select orderby . title 69 items A _href URL r request f show args 70 for row in pages 71 return UL items .xml Lines 2-6 provide a comment for the index action. Lines 4-5 inside the comment are interpreted by python as test code doctest . Tests can be run via the admin interface. In this case the tests verify that the index action runs without errors. Lines 19 33 and 43 try fetch a page record with the id in 0 . Line 14 24 and 47 define and process create forms for a new page and a new comment and a new document respectively. Line 36 defines and process an update form for a wiki page. Some magic happens in line 59. The onkeyup attribute of the INPUT tag keyword is set. Every time the visitor presses a key or releases a key the JavaScript code inside the onkeyup attribute is executed client-side. Here is the JavaScript code 1 ajax bg_find keyword target ajax is a JavaScript function defined in the file which is included by the default . It takes three parameters the URL of the action that performs the synchronous callback bg_find a list of the IDs of variables to be sent to the callback keyword and the ID where the response has to be inserted target . As soon as you type something in the search box and release a key the client calls the server and sends the content of the keyword field and when the sever responds the response is embedded in the page itself as the innerHTML of the target tag. The target tag is a DIV defined m iine 75. It could have been defined in the view as well. Here is the code for the view default 1 extend 2 h1 Create new wiki page h1 3 form If you visit the create page you see the following 76 OVERVIEW Here is the code for the view default 1 extend 2 h1 Available wiki pages h1 3 A search _href URL r request f search br 4 ul for .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.