Пример #1
0
    def add_view(self, arch, fields, display=False, custom=False, toolbar=None, submenu=None, name=False, help={},
            context=None):
        if toolbar is None:
            toolbar = {}
        if submenu is None:
            submenu = {}
        def _parse_fields(node, fields, type):
            if node.tag =='field':
                attrs = tools.node_attributes(node)
                if attrs.get('widget', False):
                    if attrs['widget'] == 'one2many_list':
                        attrs['widget'] = 'one2many'
                    if attrs['widget'] not in self.openerp_widgets.get(type, []):
                        attrs['type'] = fields[str(attrs['name'])]['type']
                        del attrs['widget']
                    else:
                        attrs['type'] = attrs['widget']
                if attrs.get('selection',[]):
                    attrs['selection'] = eval(attrs['selection'])
                    for att_key, att_val in attrs['selection'].items():
                        for sel in fields[str(attrs['name'])]['selection']:
                            if att_key == sel[0]:
                                sel[1] = att_val
                    attrs['selection'] = fields[str(attrs['name'])]['selection']
                fields[unicode(attrs['name'])].update(attrs)
            for node2 in node:
                _parse_fields(node2, fields, type)
        root_node = etree.XML(arch)
        _parse_fields(root_node, fields, type=root_node.tag)

        from widget.view.widget_parse import widget_parse
        models = self.models.models
        if self.current_model and (self.current_model not in models):
            models = models + [self.current_model]
        if context and context.get('view_type','') == 'diagram':
            fields = {}
        if custom:
            self.models.add_fields_custom(fields, self.models)
        else:
            self.models.screen = self
            self.models.add_fields(fields, self.models, context=context)
        self.fields = self.models.fields

        parser = widget_parse(parent=self.parent, window=self.window)
        view = parser.parse(self, root_node, self.fields, toolbar=toolbar, submenu=submenu, name=name, help=help)
        if view:
            self.views.append(view)

        if display:
            self.__current_view = len(self.views) - 1
            self.current_view.display()
            self.screen_container.set(view.widget)

        # Store the fields for this view (we will use them when switching views)
        self.view_fields[len(self.views)-1] = copy.deepcopy(self.fields)

        return view
Пример #2
0
    def add_view(self, arch, fields, display=False, custom=False, toolbar=None,
            context=None):
        if toolbar is None:
            toolbar = {}
        def _parse_fields(node, fields):
            if node.nodeType == node.ELEMENT_NODE:
                if node.localName=='field':
                    attrs = tools.node_attributes(node)
                    if attrs.get('widget', False):
                        if attrs['widget']=='one2many_list':
                            attrs['widget']='one2many'
                        attrs['type'] = attrs['widget']
                    fields[unicode(attrs['name'])].update(attrs)
            for node2 in node.childNodes:
                _parse_fields(node2, fields)
        dom = xml.dom.minidom.parseString(arch)
        _parse_fields(dom, fields)
        for dom in self.domain:
            if dom[0] in fields:
                field_dom = str(fields[dom[0]].setdefault('domain',
                        []))
                fields[dom[0]]['domain'] = field_dom[:1] + \
                        str(('id', dom[1], dom[2])) + ',' + field_dom[1:]

        from widget.view.widget_parse import widget_parse
        models = self.models.models
        if self.current_model and (self.current_model not in models):
            models = models + [self.current_model]
        if custom:
            self.models.add_fields_custom(fields, self.models)
        else:
            self.models.add_fields(fields, self.models, context=context)
        self.fields = self.models.fields

        parser = widget_parse(parent=self.parent, window=self.window)
        dom = xml.dom.minidom.parseString(arch)
        view = parser.parse(self, dom, self.fields, toolbar=toolbar)
        if view:
            self.views.append(view)

        if display:
            self.__current_view = len(self.views) - 1
            self.current_view.display()
            self.screen_container.set(view.widget)
        
        # Store the fields for this view (we will use them when switching views)
        self.view_fields[len(self.views)-1] = copy.deepcopy(self.fields)

        return view