def __init__(self, **attrs): super(M2M, self).__init__(**attrs) ids = None params = getattr(cherrypy.request, 'terp_params', None) if not params: params = TinyDict() params.model = attrs.get('relation', 'model') params.ids = attrs.get('value', []) params.name = attrs.get('name', '') current = params.chain_get(self.name) if current and params.source == self.name: ids = current.ids self.model = attrs.get('relation', 'model') self.link = attrs.get('link', 1) self.onchange = None # override onchange in js code self.relation = attrs.get('relation', '') self.domain = attrs.get('domain', []) self.context = attrs.get('context', {}) or {} view = attrs.get('views', {}) mode = str(attrs.get('mode', 'tree,form')).split(',') self.view = view view_mode = mode view_type = mode[0] self.switch_to = view_mode[-1] if view_type == view_mode[-1]: self.switch_to = view_mode[0] if ids is None: ids = attrs.get('value', []) id = (ids or None) and ids[0] pprefix = '' if '/' in self.name: pprefix = self.name[:self.name.rindex('/')] current = params.chain_get(self.name) if not current: current = TinyDict() current.offset = current.offset or 0 current.limit = current.limit or 0 current.count = len(ids or []) if current.view_mode: view_mode = current.view_mode if current.view_type: view_type = current.view_type if current and params.source == self.name: id = current.id id = id or None current.model = self.model current.id = id if isinstance(ids, tuple): ids = list(ids) current.ids = ids or [] current.view_mode = view_mode current.view_type = view_type current.domain = current.domain or [] current.context = current.context or {} if isinstance(self.context, basestring): ctx = cherrypy.request.terp_record ctx['current_date'] = time.strftime('%Y-%m-%d') ctx['time'] = time ctx['context'] = current.context ctx['active_id'] = current.id or False # XXX: parent record for O2M #if self.parent: # ctx['parent'] = EvalEnvironment(self.parent) try: ctx = tools.expr_eval(self.context, ctx) current.context.update(ctx) except: pass if current.view_type == 'tree' and self.readonly: self.editable = False if self.editable is False: selectable = 0 else: selectable = 2 # try to get original input values if creating validation form if not params.filter_action: try: current.ids = eval(cherrypy.request.terp_data.get(self.name)) except: pass self.screen = Screen(current, prefix=self.name, views_preloaded=view, editable=False, readonly=self.editable, selectable=selectable, nolinks=self.link) if view_type == 'tree': limit = 20 if self.screen.widget.attr_limit: limit = self.screen.widget.attr_limit if current.limit == 0: current.limit = limit self.screen.widget.pageable = Pager(ids=current.ids, offset=current.offset, limit=current.limit, count=current.count, def_limit=limit) self.screen.widget.checkbox_name = False self.screen.widget.m2m = True self.validator = validators.many2many()
def __init__(self, **attrs): super(M2M, self).__init__(**attrs) ids = None params = getattr(cherrypy.request, "terp_params", None) if not params: params = TinyDict() params.model = attrs.get("relation", "model") params.ids = attrs.get("value", []) params.name = attrs.get("name", "") current = params.chain_get(self.name) if current and params.source == self.name: ids = current.ids self.model = attrs.get("relation", "model") self.link = attrs.get("link", None) self.onchange = None # override onchange in js code self.relation = attrs.get("relation", "") self.domain = attrs.get("domain", []) self.context = attrs.get("context", {}) or {} view = attrs.get("views", {}) mode = str(attrs.get("mode", "tree,form")).split(",") self.view = view view_mode = mode view_type = mode[0] self.switch_to = view_mode[-1] if view_type == view_mode[-1]: self.switch_to = view_mode[0] if ids is None: ids = attrs.get("value") or [] id = (ids or None) and ids[0] pprefix = "" if "/" in self.name: pprefix = self.name[: self.name.rindex("/")] current = params.chain_get(self.name) if not current: current = TinyDict() current.offset = current.offset or 0 current.limit = current.limit or 50 current.count = len(ids or []) if isinstance(ids, tuple): ids = list(ids) if self.name == params.source and params.sort_key and ids: # reorder ids based on supplier criteria (sort_key, sort_order) domain = current.domain or [] domain.append(("id", "in", ids)) ids = rpc.RPCProxy(self.model).search( domain, 0, 0, params.sort_key + " " + params.sort_order, current.context ) id = ids[0] if current.view_mode: view_mode = current.view_mode if current.view_type: view_type = current.view_type if current and params.source == self.name: id = current.id id = id or None current.model = self.model current.id = id current.ids = ids or [] current.view_mode = view_mode current.view_type = view_type current.domain = current.domain or [] current.context = current.context or {} if isinstance(self.context, basestring): # XXX: parent record for O2M # if self.parent: # ctx['parent'] = EvalEnvironment(self.parent) try: ctx = expr_eval( self.context, dict(cherrypy.request.terp_record, context=current.context, active_id=current.id or False), ) current.context.update(ctx) except: pass if current.view_type == "tree" and self.readonly: self.editable = False if self.editable is False: selectable = 0 else: selectable = 2 # try to get original input values if creating validation form if not params.filter_action: try: current.ids = eval(cherrypy.request.terp_data.get(self.name)) except: pass self.screen = Screen( current, prefix=self.name, views_preloaded=view, editable=self.editable, readonly=self.editable, selectable=selectable, nolinks=self.link, **{"_m2m": 1} ) self.screen.widget.checkbox_name = False self.screen.widget.m2m = True self.validator = validators.many2many()
def __init__(self, **attrs): super(M2M, self).__init__(**attrs) ids = None params = getattr(cherrypy.request, 'terp_params', None) if not params: params = TinyDict() params.model = attrs.get('relation', 'model') params.ids = attrs.get('value', []) params.name = attrs.get('name', '') current = params.chain_get(self.name) if current and params.source == self.name: ids = current.ids self.model = attrs.get('relation', 'model') self.link = attrs.get('link', None) self.onchange = None # override onchange in js code self.relation = attrs.get('relation', '') self.domain = attrs.get('domain', []) self.context = attrs.get('context', {}) or {} view = attrs.get('views', {}) mode = str(attrs.get('mode', 'tree,form')).split(',') self.view = view view_mode = mode view_type = mode[0] self.switch_to = view_mode[-1] if view_type == view_mode[-1]: self.switch_to = view_mode[0] if ids is None: ids = attrs.get('value', []) id = (ids or None) and ids[0] pprefix = '' if '/' in self.name: pprefix = self.name[:self.name.rindex('/')] if self.name == params.source and params.sort_key and ids: self.domain.append(('id', 'in', ids)) ids = rpc.RPCProxy(self.model).search(self.domain, 0, 0, params.sort_key+ ' '+params.sort_order, self.context) id = ids[0] current = params.chain_get(self.name) if not current: current = TinyDict() current.offset = current.offset or 0 current.limit = current.limit or 50 current.count = len(ids or []) if current.view_mode: view_mode = current.view_mode if current.view_type: view_type = current.view_type if current and params.source == self.name: id = current.id id = id or None current.model = self.model current.id = id if isinstance(ids, tuple): ids = list(ids) current.ids = ids or [] current.view_mode = view_mode current.view_type = view_type current.domain = current.domain or [] current.context = current.context or {} if isinstance(self.context, basestring): # XXX: parent record for O2M #if self.parent: # ctx['parent'] = EvalEnvironment(self.parent) try: ctx = expr_eval( self.context, dict(cherrypy.request.terp_record, context=current.context, active_id=current.id or False)) current.context.update(ctx) except: pass if current.view_type == 'tree' and self.readonly: self.editable = False if self.editable is False: selectable = 0 else: selectable = 2 # try to get original input values if creating validation form if not params.filter_action: try: current.ids = eval(cherrypy.request.terp_data.get(self.name)) except: pass self.screen = Screen(current, prefix=self.name, views_preloaded=view, editable=self.editable, readonly=self.editable, selectable=selectable, nolinks=self.link, **{'_m2m': 1}) self.screen.widget.checkbox_name = False self.screen.widget.m2m = True self.validator = validators.many2many()
def __init__(self, **attrs): super(M2M, self).__init__(**attrs) ids = None params = getattr(cherrypy.request, 'terp_params', None) if not params: params = TinyDict() params.model = attrs.get('relation', 'model') params.ids = attrs.get('value', []) params.name = attrs.get('name', '') current = params.chain_get(self.name) if current and params.source == self.name: ids = current.ids self.model = attrs.get('relation', 'model') self.link = attrs.get('link', None) self.onchange = None # override onchange in js code self.relation = attrs.get('relation', '') self.domain = attrs.get('domain', []) self.context = attrs.get('context', {}) or {} view = attrs.get('views', {}) mode = str(attrs.get('mode', 'tree,form')).split(',') self.view = view view_mode = mode view_type = mode[0] self.switch_to = view_mode[-1] if view_type == view_mode[-1]: self.switch_to = view_mode[0] if ids is None: ids = attrs.get('value', []) id = (ids or None) and ids[0] pprefix = '' if '/' in self.name: pprefix = self.name[:self.name.rindex('/')] if self.name == params.source and params.sort_key and ids: self.domain.append(('id', 'in', ids)) ids = rpc.RPCProxy(self.model).search( self.domain, 0, 0, params.sort_key + ' ' + params.sort_order, self.context) id = ids[0] current = params.chain_get(self.name) if not current: current = TinyDict() current.offset = current.offset or 0 current.limit = current.limit or 50 current.count = len(ids or []) if current.view_mode: view_mode = current.view_mode if current.view_type: view_type = current.view_type if current and params.source == self.name: id = current.id id = id or None current.model = self.model current.id = id if isinstance(ids, tuple): ids = list(ids) current.ids = ids or [] current.view_mode = view_mode current.view_type = view_type current.domain = current.domain or [] current.context = current.context or {} if isinstance(self.context, basestring): # XXX: parent record for O2M #if self.parent: # ctx['parent'] = EvalEnvironment(self.parent) try: ctx = expr_eval( self.context, dict(cherrypy.request.terp_record, context=current.context, active_id=current.id or False)) current.context.update(ctx) except: pass if current.view_type == 'tree' and self.readonly: self.editable = False if self.editable is False: selectable = 0 else: selectable = 2 # try to get original input values if creating validation form if not params.filter_action: try: current.ids = eval(cherrypy.request.terp_data.get(self.name)) except: pass self.screen = Screen(current, prefix=self.name, views_preloaded=view, editable=self.editable, readonly=self.editable, selectable=selectable, nolinks=self.link, **{'_m2m': 1}) self.screen.widget.checkbox_name = False self.screen.widget.m2m = True self.validator = validators.many2many()