source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/applications/welcome/models/db.py

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 7.6 KB
Line 
1# -*- coding: utf-8 -*-
2
3# -------------------------------------------------------------------------
4# AppConfig configuration made easy. Look inside private/appconfig.ini
5# Auth is for authenticaiton and access control
6# -------------------------------------------------------------------------
7from gluon.contrib.appconfig import AppConfig
8from gluon.tools import Auth
9
10# -------------------------------------------------------------------------
11# This scaffolding model makes your app work on Google App Engine too
12# File is released under public domain and you can use without limitations
13# -------------------------------------------------------------------------
14
15if request.global_settings.web2py_version < "2.15.5":
16    raise HTTP(500, "Requires web2py 2.15.5 or newer")
17
18# -------------------------------------------------------------------------
19# if SSL/HTTPS is properly configured and you want all HTTP requests to
20# be redirected to HTTPS, uncomment the line below:
21# -------------------------------------------------------------------------
22# request.requires_https()
23
24# -------------------------------------------------------------------------
25# once in production, remove reload=True to gain full speed
26# -------------------------------------------------------------------------
27configuration = AppConfig(reload=True)
28
29if not request.env.web2py_runtime_gae:
30    # ---------------------------------------------------------------------
31    # if NOT running on Google App Engine use SQLite or other DB
32    # ---------------------------------------------------------------------
33    db = DAL(configuration.get('db.uri'),
34             pool_size=configuration.get('db.pool_size'),
35             migrate_enabled=configuration.get('db.migrate'),
36             check_reserved=['all'])
37else:
38    # ---------------------------------------------------------------------
39    # connect to Google BigTable (optional 'google:datastore://namespace')
40    # ---------------------------------------------------------------------
41    db = DAL('google:datastore+ndb')
42    # ---------------------------------------------------------------------
43    # store sessions and tickets there
44    # ---------------------------------------------------------------------
45    session.connect(request, response, db=db)
46    # ---------------------------------------------------------------------
47    # or store session in Memcache, Redis, etc.
48    # from gluon.contrib.memdb import MEMDB
49    # from google.appengine.api.memcache import Client
50    # session.connect(request, response, db = MEMDB(Client()))
51    # ---------------------------------------------------------------------
52
53# -------------------------------------------------------------------------
54# by default give a view/generic.extension to all actions from localhost
55# none otherwise. a pattern can be 'controller/function.extension'
56# -------------------------------------------------------------------------
57response.generic_patterns = []
58if request.is_local and not configuration.get('app.production'):
59    response.generic_patterns.append('*')
60
61# -------------------------------------------------------------------------
62# choose a style for forms
63# -------------------------------------------------------------------------
64response.formstyle = 'bootstrap4_inline'
65response.form_label_separator = ''
66
67# -------------------------------------------------------------------------
68# (optional) optimize handling of static files
69# -------------------------------------------------------------------------
70# response.optimize_css = 'concat,minify,inline'
71# response.optimize_js = 'concat,minify,inline'
72
73# -------------------------------------------------------------------------
74# (optional) static assets folder versioning
75# -------------------------------------------------------------------------
76# response.static_version = '0.0.0'
77
78# -------------------------------------------------------------------------
79# Here is sample code if you need for
80# - email capabilities
81# - authentication (registration, login, logout, ... )
82# - authorization (role based authorization)
83# - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
84# - old style crud actions
85# (more options discussed in gluon/tools.py)
86# -------------------------------------------------------------------------
87
88# host names must be a list of allowed host names (glob syntax allowed)
89auth = Auth(db, host_names=configuration.get('host.names'))
90
91# -------------------------------------------------------------------------
92# create all tables needed by auth, maybe add a list of extra fields
93# -------------------------------------------------------------------------
94auth.settings.extra_fields['auth_user'] = []
95auth.define_tables(username=False, signature=False)
96
97# -------------------------------------------------------------------------
98# configure email
99# -------------------------------------------------------------------------
100mail = auth.settings.mailer
101mail.settings.server = 'logging' if request.is_local else configuration.get('smtp.server')
102mail.settings.sender = configuration.get('smtp.sender')
103mail.settings.login = configuration.get('smtp.login')
104mail.settings.tls = configuration.get('smtp.tls') or False
105mail.settings.ssl = configuration.get('smtp.ssl') or False
106
107# -------------------------------------------------------------------------
108# configure auth policy
109# -------------------------------------------------------------------------
110auth.settings.registration_requires_verification = False
111auth.settings.registration_requires_approval = False
112auth.settings.reset_password_requires_verification = True
113
114# ------------------------------------------------------------------------- 
115# read more at http://dev.w3.org/html5/markup/meta.name.html               
116# -------------------------------------------------------------------------
117response.meta.author = configuration.get('app.author')
118response.meta.description = configuration.get('app.description')
119response.meta.keywords = configuration.get('app.keywords')
120response.meta.generator = configuration.get('app.generator')
121response.show_toolbar = configuration.get('app.toolbar')
122
123# -------------------------------------------------------------------------
124# your http://google.com/analytics id                                     
125# -------------------------------------------------------------------------
126response.google_analytics_id = configuration.get('google.analytics_id')
127
128# -------------------------------------------------------------------------
129# maybe use the scheduler
130# -------------------------------------------------------------------------
131if configuration.get('scheduler.enabled'):
132    from gluon.scheduler import Scheduler
133    scheduler = Scheduler(db, heartbeat=configuration.get('scheduler.heartbeat'))
134
135# -------------------------------------------------------------------------
136# Define your tables below (or better in another model file) for example
137#
138# >>> db.define_table('mytable', Field('myfield', 'string'))
139#
140# Fields can be 'string','text','password','integer','double','boolean'
141#       'date','time','datetime','blob','upload', 'reference TABLENAME'
142# There is an implicit 'id integer autoincrement' field
143# Consult manual for more options, validators, etc.
144#
145# More API examples for controllers:
146#
147# >>> db.mytable.insert(myfield='value')
148# >>> rows = db(db.mytable.myfield == 'value').select(db.mytable.ALL)
149# >>> for row in rows: print row.id, row.myfield
150# -------------------------------------------------------------------------
151
152# -------------------------------------------------------------------------
153# after defining tables, uncomment below to enable auditing
154# -------------------------------------------------------------------------
155# auth.enable_record_versioning(db)
Note: See TracBrowser for help on using the repository browser.