~unifield-team/unifield-web/us-2156

« back to all changes in this revision

Viewing changes to addons/openerp/controllers/actions.py

  • Committer: jf
  • Date: 2016-11-09 09:53:49 UTC
  • mfrom: (4807.5.13 unifield-web)
  • Revision ID: jfb@tempo-consulting.fr-20161109095349-u8x1q3ygjhh8678s
US-1364 [IMP] Standard Export: generate file on server side to speed up process and remove limit of 2000 records

lp:~fabien-morin/unifield-web/fm-us-1364

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
def restart_pooler_if_new_module():
43
43
    from openobject import pooler
44
44
    autoreloader_enabled = bool(
45
 
            getattr(cherrypy.engine.autoreload, 'thread', None))
 
45
        getattr(cherrypy.engine.autoreload, 'thread', None))
46
46
    if autoreloader_enabled:
47
47
        # stop (actually don't listen to) the auto-reloader the process
48
48
        # doesn't restart due to downloading new add-ons or refreshing
97
97
        params.action_id = action_id
98
98
 
99
99
    if name:
100
 
         params.context['_terp_view_name'] = name
 
100
        params.context['_terp_view_name'] = name
101
101
    else:
102
102
        if params.context.get('_terp_view_name'):
103
103
            del params.context['_terp_view_name']
141
141
    return Wizard().create(params)
142
142
 
143
143
PRINT_FORMATS = {
144
 
     'pdf' : 'application/pdf',
145
 
     'doc' : 'application/vnd.ms-word',
146
 
     'html': 'text/html',
147
 
     'sxw' : 'application/vnd.sun.xml.writer',
148
 
     'odt' : 'application/vnd.oasis.opendocument.text',
149
 
     'ods' : 'application/vnd.oasis.opendocument.spreadsheet',
150
 
     'xls' : 'application/vnd.ms-excel',
151
 
     'xml' : 'application/force-download',
152
 
     'csv' : 'text/csv',
153
 
     'rtf' : 'application/rtf',
154
 
     'txt' : 'text/plain',
155
 
     'zip' : 'application/zip',
156
 
     'dump': 'application/octet-stream',
 
144
    'pdf' : 'application/pdf',
 
145
    'doc' : 'application/vnd.ms-word',
 
146
    'html': 'text/html',
 
147
    'sxw' : 'application/vnd.sun.xml.writer',
 
148
    'odt' : 'application/vnd.oasis.opendocument.text',
 
149
    'ods' : 'application/vnd.oasis.opendocument.spreadsheet',
 
150
    'xls' : 'application/vnd.ms-excel',
 
151
    'xml' : 'application/force-download',
 
152
    'csv' : 'text/csv',
 
153
    'rtf' : 'application/rtf',
 
154
    'txt' : 'text/plain',
 
155
    'zip' : 'application/zip',
 
156
    'dump': 'application/octet-stream',
157
157
}
158
158
 
159
159
def _print_data(data):
167
167
    else:
168
168
        if not data.get('result') and data.get('path'):
169
169
            try:
170
 
                return serve_file.serve_file(data['path'], "application/x-download", 'attachment', delete=data.get('delete', False))
 
170
                return serve_file.serve_file(data['path'],
 
171
                                             "application/x-download", 'attachment',
 
172
                                             name=data.get('filename', ''), delete=data.get('delete', False))
171
173
            except Exception, e:
172
174
                cherrypy.response.headers['Content-Type'] = 'text/html'
173
175
                if 'Content-Disposition' in cherrypy.response.headers:
279
281
        data[key] = action.get(key, data.get(key))
280
282
    if not data.get('search_view') and data.get('search_view_id'):
281
283
        data['search_view'] = str(rpc.session.execute(
282
 
                'object', 'execute', data['res_model'], 'fields_view_get',
283
 
                data['search_view_id'], 'search', data['context']))
 
284
            'object', 'execute', data['res_model'], 'fields_view_get',
 
285
            data['search_view_id'], 'search', data['context']))
284
286
    # store action limit within request and set it as None for action
285
287
    # so that view specific can differenciate between defaults (i.e this
286
288
    # act_window limit) and user's choosen value
290
292
        #       once we're sure there is *no* performance impact.
291
293
        cherrypy.request.action_limit = 20
292
294
    data['limit'] = None
293
 
    
 
295
 
294
296
    if action.get('target') and action['target'] == 'popup' and action.get('res_model') and isinstance(action.get('context'), dict):
295
297
        search_view_id = rpc.RPCProxy('ir.ui.view').search([('type','=', 'search'), ('model','=',action['res_model'])], 0, 0, 0, rpc.session.context)
296
298
        if search_view_id and action['context'].get('search_view'):
297
299
            action['context']['search_view'] = search_view_id[0]
298
 
    
 
300
 
299
301
    view_ids = False
300
302
    if action.get('views', []):
301
303
        if isinstance(action['views'], list):
310
312
        action['domain'] = '[]'
311
313
 
312
314
    ctx = dict(data.get('context', {}),
313
 
        active_id=data.get('id', False),
314
 
        active_ids=data.get('ids', []),
315
 
        active_model=data.get('model', False)
316
 
    )
317
 
    
 
315
               active_id=data.get('id', False),
 
316
               active_ids=data.get('ids', []),
 
317
               active_model=data.get('model', False)
 
318
               )
 
319
 
318
320
    if action.get('context') and isinstance(action['context'], dict):
319
321
        if not action['context'].get('active_ids'):
320
322
            action['context']['active_ids'] = ctx['active_ids'] or []
321
 
    
 
323
 
322
324
    ctx.update(expr_eval(action.get('context', '{}'), ctx))
323
325
 
324
326
    search_view = action.get('search_view_id')
358
360
 
359
361
def server(action, data):
360
362
    context = dict(data.get('context', {}),
361
 
        active_id=data.get('id', False),
362
 
        active_ids=data.get('ids', [])
363
 
    )
 
363
                   active_id=data.get('id', False),
 
364
                   active_ids=data.get('ids', [])
 
365
                   )
364
366
    action_result = rpc.RPCProxy('ir.actions.server').run([action['id']], context)
365
367
    if action_result:
366
368
        if not isinstance(action_result, list):
393
395
 
394
396
def act_url(action, data):
395
397
    return execute_url(**dict(data,
396
 
        url=action['url'],
397
 
        target=action['target'],
398
 
        type=action['type']
399
 
    ))
 
398
                              url=action['url'],
 
399
                              target=action['target'],
 
400
                              type=action['type']
 
401
                              ))
400
402
 
401
403
ACTIONS_BY_TYPE = {
402
404
    'ir.actions.act_window_close': act_window_close,
415
417
    # or if it is not tied to an object (ex: home action after login)
416
418
    open_new_tab = False
417
419
    if action['target'] == 'current' and action.get('res_model') != 'ir.ui.menu'\
418
 
        and data.get('model') != 'ir.ui.menu' and not 'home_action' in data:
 
420
            and data.get('model') != 'ir.ui.menu' and not 'home_action' in data:
419
421
        action['target'] = 'popup'
420
422
        open_new_tab = True
421
423
 
430
432
    if getattr(cherrypy.request, 'params', []):
431
433
        if getattr(cherrypy.request.params, 'context', {}):
432
434
            cherrypy.response.headers['active_id'] = cherrypy.request.params.get('_terp_id')\
433
 
            or cherrypy.request.params.context.get('active_id')
 
435
                or cherrypy.request.params.context.get('active_id')
434
436
 
435
437
    # Add 'opened' mark to indicate we're now within the popup and can
436
438
    # continue on during the second round of execution
437
439
    payload = str({
438
 
      'action': dict(action, opened=True),
439
 
      'data': data
 
440
        'action': dict(action, opened=True),
 
441
        'data': data
440
442
    })
441
443
    # Use compressed payloads in order to keep the URL under MSIE's size
442
444
    # limitations. Plus repeated urlencodings of serialized Python data
450
452
 
451
453
    if open_new_tab:
452
454
        url = '/?' + urllib.urlencode({'next': url})
453
 
        
 
455
 
454
456
    cherrypy.response.headers['X-Target'] = action['target']
455
457
    cherrypy.response.headers['Location'] = url
456
458
    return """<script type="text/javascript">
497
499
                  openLink('%s')
498
500
              </script>
499
501
            """ % url
500
 
    
 
502
 
501
503
 
502
504
def get_action_type(act_id):
503
505
    """Get the action type for the given action id.
526
528
 
527
529
    if type is None:
528
530
        type = get_action_type(act_id)
529
 
        
 
531
 
530
532
    ctx = dict(rpc.session.context, **(data.get('context') or {}))   
531
533
 
532
534
    res = rpc.session.execute('object', 'execute', type, 'read', act_id, False, ctx)
591
593
def report_link(report_name, **kw):
592
594
    cherrypy.response.headers['X-Target'] = 'download'
593
595
    cherrypy.response.headers['Location'] = tools.url(
594
 
            '/openerp/report', report_name=report_name, **kw)
 
596
        '/openerp/report', report_name=report_name, **kw)
595
597
    return dict(name=report_name, data=kw)
596
 
    
 
598