~ubuntu-branches/debian/jessie/web2py/jessie

« back to all changes in this revision

Viewing changes to applications/welcome/models/db.py

  • Committer: Package Import Robot
  • Author(s): José L. Redrejo Rodríguez
  • Date: 2011-11-04 10:12:01 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20111104101201-ym8q3030ik8sc10u
Tags: 1.99.2.1-1
* Updated upstream sources with real 1.99.2 version
* Ensure python-gtk2 is not needed to run web2py, fixing 
  debian/patches/gtk_gui (Closes: #646931)
* Refreshed debian/patches/avoid_updating patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
 
# this file is released under public domain and you can use without limitations
3
2
 
4
3
#########################################################################
5
4
## This scaffolding model makes your app work on Google App Engine too
 
5
## File is released under public domain and you can use without limitations
6
6
#########################################################################
7
7
 
8
 
if request.env.web2py_runtime_gae:            # if running on Google App Engine
9
 
    db = DAL('google:datastore')              # connect to Google BigTable
10
 
                                              # optional DAL('gae://namespace')
11
 
    session.connect(request, response, db = db) # and store sessions and tickets there
12
 
    ### or use the following lines to store sessions in Memcache
13
 
    # from gluon.contrib.memdb import MEMDB
14
 
    # from google.appengine.api.memcache import Client
15
 
    # session.connect(request, response, db = MEMDB(Client()))
16
 
else:                                         # else use a normal relational database
17
 
    db = DAL('sqlite://storage.sqlite')       # if not, use SQLite or other DB
 
8
if not request.env.web2py_runtime_gae:     
 
9
    ## if NOT running on Google App Engine use SQLite or other DB
 
10
    db = DAL('sqlite://storage.sqlite') 
 
11
else:
 
12
    ## connect to Google BigTable (optional 'google:datastore://namespace')
 
13
    db = DAL('google:datastore') 
 
14
    ## store sessions and tickets there
 
15
    session.connect(request, response, db = db) 
 
16
    ## or store session in Memcache, Redis, etc.
 
17
    ## from gluon.contrib.memdb import MEMDB
 
18
    ## from google.appengine.api.memcache import Client
 
19
    ## session.connect(request, response, db = MEMDB(Client()))
18
20
 
19
 
# by default give a view/generic.extension to all actions from localhost
20
 
# none otherwise. a pattern can be 'controller/function.extension'
 
21
## by default give a view/generic.extension to all actions from localhost
 
22
## none otherwise. a pattern can be 'controller/function.extension'
21
23
response.generic_patterns = ['*'] if request.is_local else []
22
24
 
23
25
#########################################################################
26
28
## - authentication (registration, login, logout, ... )
27
29
## - authorization (role based authorization)
28
30
## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
29
 
## - crud actions
 
31
## - old style crud actions
30
32
## (more options discussed in gluon/tools.py)
31
33
#########################################################################
32
34
 
33
 
from gluon.tools import Mail, Auth, Crud, Service, PluginManager, prettydate
34
 
mail = Mail()                                  # mailer
35
 
auth = Auth(db)                                # authentication/authorization
36
 
crud = Crud(db)                                # for CRUD helpers using auth
37
 
service = Service()                            # for json, xml, jsonrpc, xmlrpc, amfrpc
38
 
plugins = PluginManager()                      # for configuring plugins
39
 
 
40
 
mail.settings.server = 'logging' or 'smtp.gmail.com:587'  # your SMTP server
41
 
mail.settings.sender = 'you@gmail.com'         # your email
42
 
mail.settings.login = 'username:password'      # your credentials or None
43
 
 
44
 
auth.settings.hmac_key = '<your secret key>'   # before define_tables()
45
 
auth.define_tables()                           # creates all needed tables
46
 
auth.settings.mailer = mail                    # for user email verification
 
35
from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
 
36
auth = Auth(db, hmac_key=Auth.get_or_create_key()) 
 
37
crud, service, plugins = Crud(db), Service(), PluginManager()
 
38
 
 
39
## create all tables needed by auth if not custom tables
 
40
auth.define_tables() 
 
41
 
 
42
## configure email
 
43
mail=auth.settings.mailer
 
44
mail.settings.server = 'logging' or 'smtp.gmail.com:587'
 
45
mail.settings.sender = 'you@gmail.com'
 
46
mail.settings.login = 'username:password'
 
47
 
 
48
## configure auth policy
47
49
auth.settings.registration_requires_verification = False
48
50
auth.settings.registration_requires_approval = False
49
 
auth.messages.verify_email = 'Click on the link http://'+request.env.http_host+URL('default','user',args=['verify_email'])+'/%(key)s to verify your email'
50
51
auth.settings.reset_password_requires_verification = True
51
 
auth.messages.reset_password = 'Click on the link http://'+request.env.http_host+URL('default','user',args=['reset_password'])+'/%(key)s to reset your password'
52
 
 
53
 
#########################################################################
54
 
## If you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
55
 
## register with janrain.com, uncomment and customize following
56
 
# from gluon.contrib.login_methods.rpx_account import RPXAccount
57
 
# auth.settings.actions_disabled = \
58
 
#    ['register','change_password','request_reset_password']
59
 
# auth.settings.login_form = RPXAccount(request, api_key='...',domain='...',
60
 
#    url = "http://localhost:8000/%s/default/user/login" % request.application)
61
 
## other login methods are in gluon/contrib/login_methods
62
 
#########################################################################
63
 
 
64
 
crud.settings.auth = None        # =auth to enforce authorization on crud
 
52
 
 
53
## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
 
54
## register with janrain.com, write your domain:api_key in private/janrain.key
 
55
from gluon.contrib.login_methods.rpx_account import use_janrain
 
56
use_janrain(auth,filename='private/janrain.key')
65
57
 
66
58
#########################################################################
67
59
## Define your tables below (or better in another model file) for example