Skip to content

Commit

Permalink
no caching from localhost, thanks Alan
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Mar 15, 2013
1 parent 348c2e6 commit 317fda3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
20 changes: 14 additions & 6 deletions controllers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
import os, datetime
session.forget()

TIME_EXPIRE = 60*60*24
FORCE_RENDER = False

# this is for checking new content instantly in development
if request.is_local:
TIME_EXPIRE = -1
FORCE_RENDER = True

response.title = 'web2py'
response.subtitle = 'Full Stack Web Framework, 4th Ed.\nwritten by Massimo Di Pierro in English'
response.menu = []
Expand Down Expand Up @@ -74,7 +82,7 @@ def truncate(x): return x[:70]+'...' if len(x)>70 else x
def index():
books = {}
for subfolder in FOLDERS:
books[subfolder] = cache.ram('info_%s' % subfolder, lambda: get_info(subfolder), time_expire=60*60*24)
books[subfolder] = cache.ram('info_%s' % subfolder, lambda: get_info(subfolder), time_expire=TIME_EXPIRE)
return locals()

def calc_date(now=request.utcnow.date()):
Expand All @@ -88,14 +96,14 @@ def calc_date(now=request.utcnow.date()):
def chapter():
book_id, chapter_id = request.args(0), request.args(1,cast=int,default='0')
subfolder = get_subfolder(book_id)
info = cache.ram('info_%s' % subfolder, lambda: get_info(subfolder), time_expire=60*60*24)
chapters = cache.ram('chapters_%s' % subfolder, lambda: get_chapters(subfolder), time_expire=60*60*24)
info = cache.ram('info_%s' % subfolder, lambda: get_info(subfolder), time_expire=TIME_EXPIRE)
chapters = cache.ram('chapters_%s' % subfolder, lambda: get_chapters(subfolder), time_expire=TIME_EXPIRE)
filename = os.path.join(FOLDER,subfolder,'%.2i.markmin' % chapter_id)
dest = os.path.join(request.folder, 'static_chaps', subfolder, '%.2i.html' % chapter_id)
response.headers['Cache-Control'] = 'public, must-revalidate'
response.headers['Expires'] = calc_date()
response.headers['Pragma'] = None
if not os.path.isfile(dest):
if (not os.path.isfile(dest)) or FORCE_RENDER:
content = open(filename).read()
content = convert2html(book_id,content).xml()
if not os.path.exists(os.path.dirname(dest)):
Expand All @@ -111,8 +119,8 @@ def search():
book_id = request.args(0) or redirect(URL('index'))
search = request.vars.search or redirect(URL('chapter',args=book_id))
subfolder = get_subfolder(book_id)
info = cache.ram('info_%s' % subfolder, lambda: get_info(subfolder), time_expire=60*60*24)
chapters = cache.ram('chapters_%s' % subfolder, lambda: get_chapters(subfolder), time_expire=60*60*24)
info = cache.ram('info_%s' % subfolder, lambda: get_info(subfolder), time_expire=TIME_EXPIRE)
chapters = cache.ram('chapters_%s' % subfolder, lambda: get_chapters(subfolder), time_expire=TIME_EXPIRE)
results = []
content = H2('No results for "%s"' % search)
for chapter in chapters:
Expand Down
6 changes: 3 additions & 3 deletions sources/29-web2py-english/03.markmin
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ Here we assume we are starting from scratch from a simple clone of the "welcome"
def index(): return auth.wiki()
``:code

Done! You have a fully working wiki. At this point no page has been created and in order to create pages you must be logged-in and you must be member of a group called "wiki-editor" or "wiki-author". If you are logged-in as administrator the "wiki-editor" group is created automatically and you are made a member. The difference between editors and authors is that the editors can create pages, edit and delete any page, while the authors can create pages (with some optional restrictions) and can only edit/delete the pages they have created.
Done! You have a fully working wiki. At this point no page has been created and in order to create pages you must be logged-in and you must be member of a group called "wiki_editor" or "wiki_author". If you are logged-in as administrator the "wiki_editor" group is created automatically and you are made a member. The difference between editors and authors is that the editors can create pages, edit and delete any page, while the authors can create pages (with some optional restrictions) and can only edit/delete the pages they have created.

The ``auth.wiki()`` function returns in a dictionary with a key ``content`` which is understood by the scaffolding "views/default/index.html". You can make your own view for this action:

Expand Down Expand Up @@ -1298,11 +1298,11 @@ def wiki(self, slug=None, env=None, render='markmin',
It takes the following arguments:

- ``render`` which defaults to ``'markmin'`` but can be set equal to ``'html'``. It determines the syntax of the wiki. We will discuss the markmin wiki markup later. If you change it to HTML you can use a wysiwyg javascript editor such as TinyMCE or NicEdit.
- ``manage_permissions``. This is set to ``False`` by default and only recognizes permissions for "wiki-editor" and "wiki-author". If you change it to ``True`` the create/edit page will give the option to specify by name the group(s) whose members have permission to read and edit the page. There is a group "everybody" which includes all users.
- ``manage_permissions``. This is set to ``False`` by default and only recognizes permissions for "wiki_editor" and "wiki_author". If you change it to ``True`` the create/edit page will give the option to specify by name the group(s) whose members have permission to read and edit the page. There is a group "everybody" which includes all users.

- ``force_prefix``. If set to something like ``'%(id)s-'`` it will restrict authors (not editors) to creating pages with a prefix like "[user id]-[page name]". The prefix can contain the id ("%(id)s") or the username ("%(username)s") or any other field from the auth_user table, as long as the corresponding column contains a valid string that would pass URL validation.
- ``restrict_search``. This defaults to ``False`` and any logged-in user can search all wiki pages (but not necessary read or edit them). If set to ``True``, authors can search only their own pages, editors can search everything, other users cannot search anything.
- ``menu_groups``. This defaults to ``None`` and it indicates that wiki management menu (search, create, edit, etc.) is always displayed. You can set it to a list of group names whose members only can see this menu, for example ``['wiki-editor','wiki-author']``. Notice that even if the menu is exposed to everybody that does not mean everybody is allowed to perform actions listed in the menu since they are regulated by the access control system.
- ``menu_groups``. This defaults to ``None`` and it indicates that wiki management menu (search, create, edit, etc.) is always displayed. You can set it to a list of group names whose members only can see this menu, for example ``['wiki_editor','wiki_author']``. Notice that even if the menu is exposed to everybody that does not mean everybody is allowed to perform actions listed in the menu since they are regulated by the access control system.

The ``wiki`` method has some additional parameters which will be explained later: ``slug``, ``env``, and ``extra``.

Expand Down

0 comments on commit 317fda3

Please sign in to comment.