~openerp-dev/openerp-web/trunk-qweb-report

« back to all changes in this revision

Viewing changes to addons/web/controllers/main.py

  • Committer: openerp-sle
  • Date: 2014-01-30 16:38:51 UTC
  • mfrom: (3801.1.29 trunk-website-al)
  • Revision ID: openerp-sle@openerp-sle.home-20140130163851-1r9sqxkb9bgwjry5
[MERGE] trunk-website-al

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
import re
16
16
import simplejson
17
17
import time
18
 
import urllib
19
18
import urllib2
20
19
import zlib
21
20
from xml.etree import ElementTree
120
119
    """
121
120
    return http.redirect_with_hash(*args, **kw)
122
121
 
 
122
def ensure_db(redirect='/web/database/selector'):
 
123
    # This helper should be used in web client auth="none" routes
 
124
    # if those routes needs a db to work with.
 
125
    # If the heuristics does not find any database, then the users will be
 
126
    # redirected to db selector or any url specified by `redirect` argument.
 
127
    # If the db is taken out of a query parameter, it will be checked against
 
128
    # `http.db_filter()` in order to ensure it's legit and thus avoid db
 
129
    # forgering that could lead to xss attacks.
 
130
    db = request.params.get('db')
 
131
 
 
132
    # Ensure db is legit
 
133
    if db and db not in http.db_filter([db]):
 
134
        db = None
 
135
 
 
136
    # if db not provided, use the session one
 
137
    if not db:
 
138
        db = request.session.db
 
139
 
 
140
    # if no database provided and no database in session, use monodb
 
141
    if not db:
 
142
        db = db_monodb(request.httprequest)
 
143
 
 
144
    # if no db can be found til here, send to the database selector
 
145
    # the database selector will redirect to database manager if needed
 
146
    if not db:
 
147
        werkzeug.exceptions.abort(werkzeug.utils.redirect(redirect, 303))
 
148
 
 
149
    # always switch the session to the computed db
 
150
    if db != request.session.db:
 
151
        request.session.logout()
 
152
 
 
153
    request.session.db = db
 
154
 
123
155
def module_topological_sort(modules):
124
156
    """ Return a list of module names sorted so that their dependencies of the
125
157
    modules are listed before the module itself
322
354
    if not debug:
323
355
        path = '/web/webclient/' + extension
324
356
        if mods is not None:
325
 
            path += '?' + urllib.urlencode({'mods': mods})
 
357
            path += '?' + werkzeug.url_encode({'mods': mods})
326
358
        elif db:
327
 
            path += '?' + urllib.urlencode({'db': db})
 
359
            path += '?' + werkzeug.url_encode({'db': db})
328
360
 
329
361
        remotes = [wp for fp, wp in files if fp is None]
330
362
        return [path] + remotes
584
616
 
585
617
    @http.route('/web', type='http', auth="none")
586
618
    def web_client(self, s_action=None, **kw):
587
 
        http.ensure_db()
 
619
        ensure_db()
588
620
 
589
621
        if request.session.uid:
590
622
            html = render_bootstrap_template(request.session.db, "web.webclient_bootstrap")
594
626
 
595
627
    @http.route('/web/login', type='http', auth="none")
596
628
    def web_login(self, redirect=None, **kw):
597
 
        http.ensure_db(with_registry=True)
 
629
        ensure_db()
598
630
 
599
631
        values = request.params.copy()
600
632
        if not redirect: