[FIX] http controllers inheritance
minimalist and backward compatible implementation bzr revid: al@openerp.com-20130423210644-hmvglhh10zlrwp9q
This commit is contained in:
parent
60f0bd08ee
commit
44569c06a2
|
@ -1439,7 +1439,7 @@ class Action(openerpweb.Controller):
|
|||
else:
|
||||
return False
|
||||
|
||||
class Export(View):
|
||||
class Export(openerpweb.Controller):
|
||||
_cp_path = "/web/export"
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
|
@ -1580,7 +1580,7 @@ class Export(View):
|
|||
(prefix + '/' + k, prefix_string + '/' + v)
|
||||
for k, v in self.fields_info(req, model, export_fields).iteritems())
|
||||
|
||||
#noinspection PyPropertyDefinition
|
||||
class ExportFormat(object):
|
||||
@property
|
||||
def content_type(self):
|
||||
""" Provides the format's content type """
|
||||
|
@ -1628,7 +1628,7 @@ class Export(View):
|
|||
('Content-Type', self.content_type)],
|
||||
cookies={'fileToken': int(token)})
|
||||
|
||||
class CSVExport(Export):
|
||||
class CSVExport(ExportFormat, http.Controller):
|
||||
_cp_path = '/web/export/csv'
|
||||
fmt = {'tag': 'csv', 'label': 'CSV'}
|
||||
|
||||
|
@ -1663,7 +1663,7 @@ class CSVExport(Export):
|
|||
fp.close()
|
||||
return data
|
||||
|
||||
class ExcelExport(Export):
|
||||
class ExcelExport(ExportFormat, http.Controller):
|
||||
_cp_path = '/web/export/xls'
|
||||
fmt = {
|
||||
'tag': 'xls',
|
||||
|
@ -1702,7 +1702,7 @@ class ExcelExport(Export):
|
|||
fp.close()
|
||||
return data
|
||||
|
||||
class Reports(View):
|
||||
class Reports(openerpweb.Controller):
|
||||
_cp_path = "/web/report"
|
||||
POLLING_DELAY = 0.25
|
||||
TYPES_MAPPING = {
|
||||
|
|
|
@ -356,17 +356,31 @@ def httprequest(f):
|
|||
addons_module = {}
|
||||
addons_manifest = {}
|
||||
controllers_class = []
|
||||
controllers_class_path = {}
|
||||
controllers_object = {}
|
||||
controllers_object_path = {}
|
||||
controllers_path = {}
|
||||
|
||||
class ControllerType(type):
|
||||
def __init__(cls, name, bases, attrs):
|
||||
super(ControllerType, cls).__init__(name, bases, attrs)
|
||||
controllers_class.append(("%s.%s" % (cls.__module__, cls.__name__), cls))
|
||||
name_class = ("%s.%s" % (cls.__module__, cls.__name__), cls)
|
||||
controllers_class.append(name_class)
|
||||
path = attrs.get('_cp_path')
|
||||
if path not in controllers_class_path:
|
||||
controllers_class_path[path] = name_class
|
||||
|
||||
class Controller(object):
|
||||
__metaclass__ = ControllerType
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
subclasses = [c for c in cls.__subclasses__() if c._cp_path == cls._cp_path]
|
||||
if subclasses:
|
||||
name = "%s (extended by %s)" % (cls.__name__, ', '.join(sub.__name__ for sub in subclasses))
|
||||
cls = type(name, tuple(reversed(subclasses)), {})
|
||||
|
||||
return object.__new__(cls)
|
||||
|
||||
#----------------------------------------------------------
|
||||
# Session context manager
|
||||
#----------------------------------------------------------
|
||||
|
@ -566,10 +580,11 @@ class Root(object):
|
|||
addons_manifest[module] = manifest
|
||||
self.statics['/%s/static' % module] = path_static
|
||||
|
||||
for k, v in controllers_class:
|
||||
if k not in controllers_object:
|
||||
o = v()
|
||||
controllers_object[k] = o
|
||||
for k, v in controllers_class_path.items():
|
||||
if k not in controllers_object_path and hasattr(v[1], '_cp_path'):
|
||||
o = v[1]()
|
||||
controllers_object[v[0]] = o
|
||||
controllers_object_path[k] = o
|
||||
if hasattr(o, '_cp_path'):
|
||||
controllers_path[o._cp_path] = o
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import openerp
|
||||
|
||||
class DiagramView(openerp.addons.web.controllers.main.View):
|
||||
class DiagramView(openerp.addons.web.http.Controller):
|
||||
_cp_path = "/web_diagram/diagram"
|
||||
|
||||
@openerp.addons.web.http.jsonrequest
|
||||
|
|
Loading…
Reference in New Issue