db.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # -*- coding: utf-8 -*-
  2. #########################################################################
  3. ## This scaffolding model makes your app work on Google App Engine too
  4. ## File is released under public domain and you can use without limitations
  5. #########################################################################
  6. ## if SSL/HTTPS is properly configured and you want all HTTP requests to
  7. ## be redirected to HTTPS, uncomment the line below:
  8. # request.requires_https()
  9. ## app configuration made easy. Look inside private/appconfig.ini
  10. from gluon.contrib.appconfig import AppConfig
  11. ## once in production, remove reload=True to gain full speed
  12. myconf = AppConfig(reload=True)
  13. if not request.env.web2py_runtime_gae:
  14. ## if NOT running on Google App Engine use SQLite or other DB
  15. db = DAL(myconf.take('db.uri'), pool_size=myconf.take('db.pool_size', cast=int), check_reserved=['all'])
  16. else:
  17. ## connect to Google BigTable (optional 'google:datastore://namespace')
  18. db = DAL('google:datastore+ndb')
  19. ## store sessions and tickets there
  20. session.connect(request, response, db=db)
  21. ## or store session in Memcache, Redis, etc.
  22. ## from gluon.contrib.memdb import MEMDB
  23. ## from google.appengine.api.memcache import Client
  24. ## session.connect(request, response, db = MEMDB(Client()))
  25. ## by default give a view/generic.extension to all actions from localhost
  26. ## none otherwise. a pattern can be 'controller/function.extension'
  27. response.generic_patterns = ['*'] if request.is_local else []
  28. ## choose a style for forms
  29. response.formstyle = myconf.take('forms.formstyle') # or 'bootstrap3_stacked' or 'bootstrap2' or other
  30. response.form_label_separator = myconf.take('forms.separator')
  31. ## (optional) optimize handling of static files
  32. # response.optimize_css = 'concat,minify,inline'
  33. # response.optimize_js = 'concat,minify,inline'
  34. ## (optional) static assets folder versioning
  35. # response.static_version = '0.0.0'
  36. #########################################################################
  37. ## Here is sample code if you need for
  38. ## - email capabilities
  39. ## - authentication (registration, login, logout, ... )
  40. ## - authorization (role based authorization)
  41. ## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
  42. ## - old style crud actions
  43. ## (more options discussed in gluon/tools.py)
  44. #########################################################################
  45. from gluon.tools import Auth, Service, PluginManager
  46. auth = Auth(db)
  47. service = Service()
  48. plugins = PluginManager()
  49. ## create all tables needed by auth if not custom tables
  50. auth.define_tables(username=False, signature=False)
  51. ## configure email
  52. mail = auth.settings.mailer
  53. mail.settings.server = 'logging' if request.is_local else myconf.take('smtp.server')
  54. mail.settings.sender = myconf.take('smtp.sender')
  55. mail.settings.login = myconf.take('smtp.login')
  56. ## configure auth policy
  57. auth.settings.registration_requires_verification = False
  58. auth.settings.registration_requires_approval = False
  59. auth.settings.reset_password_requires_verification = True
  60. #########################################################################
  61. ## Define your tables below (or better in another model file) for example
  62. ##
  63. ## >>> db.define_table('mytable',Field('myfield','string'))
  64. ##
  65. ## Fields can be 'string','text','password','integer','double','boolean'
  66. ## 'date','time','datetime','blob','upload', 'reference TABLENAME'
  67. ## There is an implicit 'id integer autoincrement' field
  68. ## Consult manual for more options, validators, etc.
  69. ##
  70. ## More API examples for controllers:
  71. ##
  72. ## >>> db.mytable.insert(myfield='value')
  73. ## >>> rows=db(db.mytable.myfield=='value').select(db.mytable.ALL)
  74. ## >>> for row in rows: print row.id, row.myfield
  75. #########################################################################
  76. ## after defining tables, uncomment below to enable auditing
  77. # auth.enable_record_versioning(db)