~openerp-dev/openerp-web/trunk-purchase-visibility-nco

« back to all changes in this revision

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

  • Committer: Darshan Kalola(OpenERP)
  • Date: 2013-10-30 05:36:01 UTC
  • mfrom: (3718.1.150 trunk)
  • Revision ID: dka@tinyerp.com-20131030053601-dt4arec0k9vc6ydh
[MERGE]merged with lp:openerp-web.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
import openerp.modules.registry
34
34
from openerp.tools.translate import _
35
35
from openerp.tools import config
36
 
 
37
 
from .. import http
38
 
 
39
 
from openerp.addons.web.http import request
 
36
from openerp import http
 
37
 
 
38
from openerp.http import request
40
39
 
41
40
#----------------------------------------------------------
42
41
# OpenERP Web helpers
527
526
 
528
527
    @http.route('/', type='http', auth="none")
529
528
    def index(self, s_action=None, db=None, debug=False, **kw):
 
529
        query = dict(urlparse.parse_qsl(request.httprequest.query_string, keep_blank_values=True))
 
530
        redirect = '/web' + '?' + urllib.urlencode(query)
 
531
        return redirect_with_hash(redirect)
 
532
 
 
533
    @http.route('/web', type='http', auth="none")
 
534
    def web_client(self, s_action=None, db=None, debug=False, **kw):
530
535
        debug = debug != False
531
 
        if db is not None:
532
 
            lst = http.db_list(True)
533
 
            if db in lst and db != request.session.db:
534
 
                request.session.logout()
535
 
                request.session.db = db
536
 
 
537
 
        if db != request.session.db:
 
536
 
 
537
        try:
 
538
            lst = http.db_list()
 
539
        except openerp.exceptions.AccessDenied:
 
540
            lst = []
 
541
 
 
542
        if db not in lst:
 
543
            db = None
 
544
        guessed_db = http.db_monodb(request.httprequest)
 
545
 
 
546
        def redirect(db):
538
547
            query = dict(urlparse.parse_qsl(request.httprequest.query_string, keep_blank_values=True))
539
 
            query.update({'db': request.session.db})
 
548
            query.update({'db': db})
540
549
            redirect = request.httprequest.path + '?' + urllib.urlencode(query)
541
550
            return redirect_with_hash(redirect)
542
 
                
543
 
        db = request.session.db
544
 
 
545
 
        js = "\n        ".join('<script type="text/javascript" src="%s"></script>' % i for i in manifest_list('js', db=db, debug=debug))
546
 
        css = "\n        ".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list('css', db=db, debug=debug))
 
551
 
 
552
        if guessed_db is None and db is None and lst:
 
553
            return redirect(lst[0])
 
554
 
 
555
        if guessed_db is None and lst:
 
556
            guessed_db = lst[0]
 
557
 
 
558
        if db is not None and db != guessed_db:
 
559
            request.session.logout()
 
560
            request.session.db = db
 
561
            guessed_db = db
 
562
 
 
563
        js = "\n        ".join('<script type="text/javascript" src="%s"></script>' % i for i in manifest_list('js', db=guessed_db, debug=debug))
 
564
        css = "\n        ".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list('css', db=guessed_db, debug=debug))
547
565
 
548
566
        r = html_template % {
549
567
            'js': js,
550
568
            'css': css,
551
 
            'modules': simplejson.dumps(module_boot(db=db)),
 
569
            'modules': simplejson.dumps(module_boot(db=guessed_db)),
552
570
            'init': 'var wc = new s.web.WebClient();wc.appendTo($(document.body));'
553
571
        }
554
572
        return request.make_response(r, {'Cache-Control': 'no-cache', 'Content-Type': 'text/html; charset=utf-8'})
729
747
    def get_list(self):
730
748
        # TODO change js to avoid calling this method if in monodb mode
731
749
        try:
732
 
            return db_list()
 
750
            return http.db_list()
733
751
        except openerp.exceptions.AccessDenied:
734
752
            monodb = db_monodb()
735
753
            if monodb:
852
870
            return {'error': _('The old password you provided is incorrect, your password was not changed.'), 'title': _('Change Password')}
853
871
        return {'error': _('Error, password not changed !'), 'title': _('Change Password')}
854
872
 
855
 
    @http.route('/web/session/sc_list', type='json', auth="user")
856
 
    def sc_list(self):
857
 
        return request.session.model('ir.ui.view_sc').get_sc(
858
 
            request.session.uid, "ir.ui.menu", request.context)
859
 
 
860
873
    @http.route('/web/session/get_lang_list', type='json', auth="none")
861
874
    def get_lang_list(self):
862
875
        try:
1002
1015
        """
1003
1016
        return request.session.model('ir.ui.menu').get_needaction_data(menu_ids, request.context)
1004
1017
 
1005
 
    @http.route('/web/menu/action', type='json', auth="user")
1006
 
    def action(self, menu_id):
1007
 
        # still used by web_shortcut
1008
 
        actions = load_actions_from_ir_values('action', 'tree_but_open',
1009
 
                                             [('ir.ui.menu', menu_id)], False)
1010
 
        return {"action": actions}
1011
 
 
1012
1018
class DataSet(http.Controller):
1013
1019
 
1014
1020
    @http.route('/web/dataset/search_read', type='json', auth="user")
1078
1084
                return records
1079
1085
 
1080
1086
        if method.startswith('_'):
1081
 
            raise Exception("Access denied")
 
1087
            raise Exception("Access Denied: Underscore prefixed methods cannot be remotely called")
1082
1088
 
1083
1089
        return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
1084
1090
 
1683
1689
            if 'ids' in action['datas']:
1684
1690
                report_ids = action['datas'].pop('ids')
1685
1691
            report_data.update(action['datas'])
1686
 
        if not report_ids:
1687
 
            raise ValueError("action['datas']['ids'] and context['active_ids'] are undefined")
1688
1692
 
1689
1693
        report_id = report_srv.report(
1690
1694
            request.session.db, request.session.uid, request.session.password,