source: OpenRLabs-Git/web2py/applications/rlabs/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 100644
File size: 8.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# -------------------------------------------------------------------------
12# This scaffolding model makes your app work on Google App Engine too
13# File is released under public domain and you can use without limitations
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=False)
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'],
37             fake_migrate=configuration.get('db.fake_migrate'))
38else:
39    # ---------------------------------------------------------------------
40    # connect to Google BigTable (optional 'google:datastore://namespace')
41    # ---------------------------------------------------------------------
42    db = DAL('google:datastore+ndb')
43    # ---------------------------------------------------------------------
44    # store sessions and tickets there
45    # ---------------------------------------------------------------------
46    session.connect(request, response, db=db)
47    # ---------------------------------------------------------------------
48    # or store session in Memcache, Redis, etc.
49    # from gluon.contrib.memdb import MEMDB
50    # from google.appengine.api.memcache import Client
51    # session.connect(request, response, db = MEMDB(Client()))
52    # ---------------------------------------------------------------------
53
54# -------------------------------------------------------------------------
55# by default give a view/generic.extension to all actions from localhost
56# none otherwise. a pattern can be 'controller/function.extension'
57# -------------------------------------------------------------------------
58response.generic_patterns = []
59if request.is_local and not configuration.get('app.production'):
60    response.generic_patterns.append('*')
61
62# -------------------------------------------------------------------------
63# choose a style for forms
64# -------------------------------------------------------------------------
65response.formstyle = 'bootstrap4_inline'
66response.form_label_separator = ''
67
68# -------------------------------------------------------------------------
69# (optional) optimize handling of static files
70# -------------------------------------------------------------------------
71# response.optimize_css = 'concat,minify,inline'
72# response.optimize_js = 'concat,minify,inline'
73
74# -------------------------------------------------------------------------
75# (optional) static assets folder versioning
76# -------------------------------------------------------------------------
77# response.static_version = '0.0.0'
78
79# -------------------------------------------------------------------------
80# Here is sample code if you need for
81# - email capabilities
82# - authentication (registration, login, logout, ... )
83# - authorization (role based authorization)
84# - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
85# - old style crud actions
86# (more options discussed in gluon/tools.py)
87# -------------------------------------------------------------------------
88
89# host names must be a list of allowed host names (glob syntax allowed)
90auth = Auth(db, host_names=configuration.get('host.names'))
91
92# -------------------------------------------------------------------------
93# create all tables needed by auth, maybe add a list of extra fields
94# -------------------------------------------------------------------------
95auth.settings.extra_fields['auth_user'] = []
96#auth.define_tables(username=False, signature=False)
97#Use username
98auth.define_tables(username=True, signature=False)
99# Add database constraint
100
101# -------------------------------------------------------------------------
102# configure email
103# -------------------------------------------------------------------------
104mail = auth.settings.mailer
105mail.settings.server = 'logging' if request.is_local else configuration.get('smtp.server')
106mail.settings.sender = configuration.get('smtp.sender')
107mail.settings.login = configuration.get('smtp.login')
108mail.settings.tls = configuration.get('smtp.tls') or False
109mail.settings.ssl = configuration.get('smtp.ssl') or False
110
111# -------------------------------------------------------------------------
112# configure auth policy
113# -------------------------------------------------------------------------
114auth.settings.registration_requires_verification = False
115auth.settings.registration_requires_approval = False
116auth.settings.reset_password_requires_verification = True
117
118
119# Deshabilitamos que se cree grupo nuevo al registrar usuario
120auth.settings.create_user_groups = None
121# ------------------------------------------------------------------------- 
122# read more at http://dev.w3.org/html5/markup/meta.name.html               
123# -------------------------------------------------------------------------
124response.meta.author = configuration.get('app.author')
125response.meta.description = configuration.get('app.description')
126response.meta.keywords = configuration.get('app.keywords')
127response.meta.generator = configuration.get('app.generator')
128response.show_toolbar = configuration.get('app.toolbar')
129
130# -------------------------------------------------------------------------
131# your http://google.com/analytics id                                     
132# -------------------------------------------------------------------------
133response.google_analytics_id = configuration.get('google.analytics_id')
134
135# -------------------------------------------------------------------------
136# maybe use the scheduler
137# -------------------------------------------------------------------------
138if configuration.get('scheduler.enabled'):
139    from gluon.scheduler import Scheduler
140    scheduler = Scheduler(db, heartbeat=configuration.get('scheduler.heartbeat'))
141
142# -------------------------------------------------------------------------
143# Define your tables below (or better in another model file) for example
144#
145# >>> db.define_table('mytable', Field('myfield', 'string'))
146#
147# Fields can be 'string','text','password','integer','double','boolean'
148#       'date','time','datetime','blob','upload', 'reference TABLENAME'
149# There is an implicit 'id integer autoincrement' field
150# Consult manual for more options, validators, etc.
151#
152# More API examples for controllers:
153#
154# >>> db.mytable.insert(myfield='value')
155# >>> rows = db(db.mytable.myfield == 'value').select(db.mytable.ALL)
156# >>> for row in rows: print row.id, row.myfield
157# -------------------------------------------------------------------------
158
159# -------------------------------------------------------------------------
160# after defining tables, uncomment below to enable auditing
161# -------------------------------------------------------------------------
162# auth.enable_record_versioning(db)
163
164# -------------------------------------------------------------------------
165# Config Authentication again posta.unizar
166# -------------------------------------------------------------------------
167
168
169auth.settings.actions_disabled.append('register')
170auth.settings.actions_disabled.append('change_password')
171auth.settings.actions_disabled.append('retrieve_password')
172auth.settings.actions_disabled.append('profile')
173
174auth.settings.remember_me_form = False
175
176# -------------------------------------------------------------------------
177# Login method in m1_auth_login.py
178# -------------------------------------------------------------------------
179#from gluon.contrib.login_methods.email_auth import email_auth
180
Note: See TracBrowser for help on using the repository browser.