def create(self, saved=False):

        tg_errors = None
        proxy = rpc.RPCProxy("res.users")
        action_id = proxy.action_get({})

        action = rpc.RPCProxy("ir.actions.act_window").read([action_id], False, rpc.session.context)[0]

        view_ids = []
        if action.get("views", []):
            view_ids = [x[0] for x in action["views"]]
        elif action.get("view_id", False):
            view_ids = [action["view_id"][0]]

        params = TinyDict()
        params.id = rpc.session.uid
        params.ids = [params.id]
        params.model = "res.users"
        params.view_type = "form"
        params.view_mode = ["form"]
        params.view_ids = view_ids

        params.string = _("Preferences")

        params.editable = True
        form = self.create_form(params, tg_errors)

        return dict(form=form, params=params, editable=True, saved=saved)
Example #2
0
    def create(self, saved=False):

        tg_errors = None
        proxy = rpc.RPCProxy('res.users')
        action_id = proxy.action_get({})

        action = rpc.RPCProxy('ir.actions.act_window').read(
            [action_id], False, rpc.session.context)[0]

        view_ids = []
        if action.get('views', []):
            view_ids = [x[0] for x in action['views']]
        elif action.get('view_id', False):
            view_ids = [action['view_id'][0]]

        params = TinyDict()
        params.id = rpc.session.uid
        params.ids = [params.id]
        params.model = 'res.users'
        params.view_type = 'form'
        params.view_mode = ['form']
        params.view_ids = view_ids

        params.string = _('Preferences')

        params.editable = True
        form = self.create_form(params, tg_errors)

        return dict(form=form, params=params, editable=True, saved=saved)
    def edit(self, model, id=False, type = 'false', ids=None, view_ids=None, view_mode=['form', 'tree'], 
             source=None, domain=[], context={}, offset=0, limit=20, count=0, search_domain=None):

        params, data = TinyDict.split({'_terp_model': model,
                                       '_terp_id' : id,
                                       '_terp_ids' : ids,
                                       '_terp_view_ids' : view_ids,
                                       '_terp_view_mode' : view_mode,
                                       '_terp_source' : source,
                                       '_terp_domain' : domain,
                                       '_terp_context' : context,
                                       '_terp_offset': offset,
                                       '_terp_limit': limit,
                                       '_terp_count': count,
                                       '_terp_search_domain': search_domain,
                                       '_terp_bi_type': type})
        params.editable = True
        params.view_type = 'form'

        if params.view_mode and 'form' not in params.view_mode:
            params.view_type = params.view_mode[-1]
            
        if params.view_type == 'tree':
            params.view_type = 'form'

        # On New O2M
        if params.source:
            current = TinyDict()
            current.id = False
            params[params.source] = current
        
        return self.create(params)
Example #4
0
    def create(self, saved=False):

        tg_errors = None
        proxy = rpc.RPCProxy('res.users')
        action_id = proxy.action_get({})

        action = rpc.RPCProxy('ir.actions.act_window').read([action_id], False, rpc.get_session().context)[0]

        view_ids=[]
        if action.get('views', []):
            view_ids=[x[0] for x in action['views']]
        elif action.get('view_id', False):
            view_ids=[action['view_id'][0]]

        params = TinyDict()
        params.id = rpc.get_session().uid
        params.ids = [params.id]
        params.model = 'res.users'
        params.view_type = 'form'
        params.view_mode = ['form']
        params.view_ids = view_ids

        params.string = _('Preferences')

        params.editable = True
        form = self.create_form(params, tg_errors)

        return dict(form=form, params=params, editable=True, saved=saved)
Example #5
0
    def __init__(self, **attrs):

        super(Action, self).__init__(**attrs)
        self.nolabel = True

        self.act_id= self.name
        res = rpc.session.execute('object', 'execute', 'ir.actions.actions', 'read', [self.act_id], ['type'], rpc.session.context)
        if not res:
            raise _('Action not found!')

        type=res[0]['type']
        self.action = rpc.session.execute('object', 'execute', type, 'read', [self.act_id], False, rpc.session.context)[0]

        if 'view_mode' in attrs:
            self.action['view_mode'] = attrs['view_mode']

        if self.action['type']=='ir.actions.act_window':

            if not self.action.get('domain', False):
                self.action['domain']='[]'
            
            ctx = rpc.session.context.copy()
            ctx.update({'active_id': False, 'active_ids': []})
            
            self.context = tools.expr_eval(self.action.get('context', '{}'), ctx)
            self.domain = tools.expr_eval(self.action['domain'], ctx)

            views = dict(map(lambda x: (x[1], x[0]), self.action['views']))
            view_mode = self.action.get('view_mode', 'tree,form').split(',')
            view_ids = map(lambda x: views.get(x, False), view_mode)

            if self.action['view_type']=='form':

                params = TinyDict()
                params.model = self.action['res_model']
                params.id = False
                params.ids = None
                params.view_ids = view_ids
                params.view_mode = view_mode
                params.context = self.context
                params.domain = self.domain

                params.offset = params.offset or 0
                params.limit = params.limit or 20

                # get pager vars if set
                if hasattr(cherrypy.request, 'terp_params'):
                    current = cherrypy.request.terp_params
                    current = current.chain_get(self.name or '') or current

                    params.offset = current.offset
                    params.limit = current.limit

                self.screen = screen.Screen(params, prefix=self.name, editable=True, selectable=3)

            elif self.action['view_type']=='tree':
                pass #TODO
Example #6
0
def execute_window(view_ids, model, res_id=False, domain=None, view_type='form', context=None,
                   mode='form,tree', name=None, target=None, limit=None, search_view=None,
                   context_menu=False, display_menu_tip=False, action_id=None):
    """Performs `actions.act_window` action.

    @param view_ids: view ids
    @param model: a model for which the action should be performed
    @param res_id: resource id
    @param domain: domain
    @param view_type: view type, eigther `form` or `tree`
    @param context: the context
    @param mode: view mode, eigther `form,tree` or `tree,form` or None

    @return: view (mostly XHTML code)
    """

    params = TinyDict()

    params.model = model
    params.ids = res_id
    params.view_ids = view_ids
    params.domain = domain or []
    params.context = context or {}
    params.limit = limit
    params.search_view = search_view
    params['context_menu'] = context_menu
    params['display_menu_tip'] = display_menu_tip
    params['target'] = target or None
    cherrypy.request._terp_view_name = name or None
    cherrypy.request._terp_view_target = target or None

    if action_id:
        params.action_id = action_id

    if name:
         params.context['_terp_view_name'] = name
    else:
        if params.context.get('_terp_view_name'):
            del params.context['_terp_view_name']
    
    if params.ids and not isinstance(params.ids, list):
        params.ids = [params.ids]

    params.id = (params.ids or False) and params.ids[0]

    mode = mode or view_type
    if view_type == 'form':
        mode = mode.split(',')
        params.view_mode=mode

        return Form().create(params)

    elif view_type == 'tree':
        return Tree().create(params)

    else:
        raise common.message(_("Invalid View"))
Example #7
0
    def edit(self,
             model,
             id=False,
             ids=None,
             view_ids=None,
             view_mode=['form', 'tree'],
             source=None,
             domain=[],
             context={},
             offset=0,
             limit=20,
             count=0,
             search_domain=None,
             **kw):

        params, data = TinyDict.split({
            '_terp_model': model,
            '_terp_id': id,
            '_terp_ids': ids,
            '_terp_view_ids': view_ids,
            '_terp_view_mode': view_mode,
            '_terp_source': source,
            '_terp_domain': domain,
            '_terp_context': context,
            '_terp_offset': offset,
            '_terp_limit': limit,
            '_terp_count': count,
            '_terp_search_domain': search_domain
        })

        params.editable = True
        params.view_type = 'form'

        if kw.get('default_date'):
            params.context.update({'default_date': kw.get('default_date')})

        cherrypy.request._terp_view_target = kw.get('target')

        if params.view_mode and 'form' not in params.view_mode:
            params.view_type = params.view_mode[-1]

        if params.view_type == 'tree':
            params.view_type = 'form'

        if not params.ids:
            params.count = 0
            params.offset = 0

        # On New O2M
        if params.source:
            current = TinyDict()
            current.id = False
            params[params.source] = current

        return self.create(params)
Example #8
0
def execute_window(view_ids,
                   model,
                   res_id=False,
                   domain=None,
                   view_type='form',
                   context={},
                   mode='form,tree',
                   name=None,
                   target=None,
                   limit=None):
    """Performs `actions.act_window` action.

    @param view_ids: view ids
    @param model: a model for which the action should be performed
    @param res_id: resource id
    @param domain: domain
    @param view_type: view type, eigther `form` or `tree`
    @param context: the context
    @param mode: view mode, eigther `form,tree` or `tree,form` or None

    @return: view (mostly XHTML code)
    """

    params = TinyDict()

    params.model = model
    params.ids = res_id
    params.view_ids = view_ids
    params.domain = domain or []
    params.context = context or {}
    params.limit = limit

    if name:
        params.context['_terp_view_name'] = name

    if params.ids and not isinstance(params.ids, list):
        params.ids = [params.ids]

    params.id = (params.ids or False) and params.ids[0]

    mode = mode or view_type

    if view_type == 'form':
        mode = mode.split(',')
        params.view_mode = mode

        return Form().create(params)

    elif view_type == 'tree':
        return Tree().create(params)

    else:
        raise common.message(_("Invalid View!"))
Example #9
0
    def edit(self, model=None, id=False, **kw):

        params = TinyDict()
        params.model = model
        params.id = id

        id = params.id
        if not id:
            res = rpc.RPCProxy('ir.model').search([('model', '=', params.model)])

            id = (res or False) and res[0]

        return super(NewModel, self).edit(model='ir.model', id=id)
Example #10
0
    def edit(self, model=None, id=False, **kw):

        params = TinyDict()
        params.model = model
        params.id = id

        id = params.id
        if not id:
            res = rpc.RPCProxy('ir.model').search([('model', '=', params.model)
                                                   ])

            id = (res or False) and res[0]

        return super(NewModel, self).edit(model='ir.model', id=id)
Example #11
0
    def edit(self,
             model,
             id=False,
             ids=None,
             view_ids=None,
             view_mode=['form', 'tree'],
             view_type='form',
             source=None,
             domain=[],
             context={},
             offset=0,
             limit=50,
             count=0,
             search_domain=None,
             search_data=None,
             filter_domain=None,
             o2m_edit=False,
             **kw):

        notebook_tab = kw.get('notebook_tab') or 0
        params = self._read_form(context,
                                 count,
                                 domain,
                                 filter_domain,
                                 id,
                                 ids,
                                 kw,
                                 limit,
                                 model,
                                 offset,
                                 search_data,
                                 search_domain,
                                 source,
                                 view_ids,
                                 view_mode,
                                 view_type,
                                 notebook_tab,
                                 o2m_edit=o2m_edit,
                                 editable=True)

        if not params.ids:
            params.count = 0

        # On New O2M
        if params.source:
            current = TinyDict()
            current.id = False
            params[params.source] = current

        return self.create(params)
Example #12
0
    def action(self, **kw):
        params, data = TinyDict.split(kw)

        button = TinyDict()

        button.model = params.model
        button.id = params.id
        button.name = params.action
        button.btype = params.kind

        params.button = button

        fobj = form.Form()

        error = ""
        try:
            res = fobj.button_action(params)
        except Exception, e:
            error = str(e)
Example #13
0
    def action(self, **kw):
        params, data = TinyDict.split(kw)

        button = TinyDict()

        button.model = params.model
        button.id = params.id
        button.name = params.action
        button.btype = params.kind

        params.button = button

        fobj = form.Form()

        error = ""
        try:
            res = fobj.button_action(params)
        except Exception, e:
            error = str(e)
Example #14
0
    def view(self, model, id, ids=None, view_ids=None, view_mode=['form', 'tree'],
            source=None, domain=[], context={}, offset=0, limit=20, count=0, search_domain=None, **kw):

        params, data = TinyDict.split({'_terp_model': model,
                                       '_terp_id' : id,
                                       '_terp_ids' : ids,
                                       '_terp_view_ids' : view_ids,
                                       '_terp_view_mode' : view_mode,
                                       '_terp_source' : source,
                                       '_terp_domain' : domain,
                                       '_terp_context' : context,
                                       '_terp_offset': offset,
                                       '_terp_limit': limit,
                                       '_terp_count': count,
                                       '_terp_search_domain': search_domain})

        params.editable = True
        params.view_type = 'form'
        
        if kw.get('default_date'):
            params.context.update({'default_date' : kw.get('default_date')})
            
        cherrypy.request._terp_view_target = kw.get('target')

        if params.view_mode and 'form' not in params.view_mode:
            params.view_type = params.view_mode[-1]

        if params.view_type == 'tree':
            params.view_type = 'form'

        if not params.ids:
            params.count = 0
            params.offset = 0

        # On New O2M
        if params.source:
            current = TinyDict()
            current.id = False
            params[params.source] = current

        return self.create(params)
Example #15
0
    def edit(self, model, id=False, ids=None, view_ids=None,
             view_mode=['form', 'tree'], view_type='form', source=None, domain=[], context={},
             offset=0, limit=50, count=0, search_domain=None,
             search_data=None, filter_domain=None, o2m_edit=False, **kw):

        notebook_tab = kw.get('notebook_tab') or 0
        params = self._read_form(context, count, domain, filter_domain, id,
                                 ids, kw, limit, model, offset, search_data,
                                 search_domain, source, view_ids, view_mode,
                                 view_type, notebook_tab, o2m_edit=o2m_edit, editable=True)

        if not params.ids:
            params.count = 0

        # On New O2M
        if params.source:
            current = TinyDict()
            current.id = False
            params[params.source] = current

        return self.create(params)
Example #16
0
    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()
Example #17
0
    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()
Example #18
0
    def __init__(self, **attrs):
        #FIXME: validation error in `Pricelist Version`
        attrs['required'] = False

        super(O2M, self).__init__(**attrs)

        self.new_attrs = { 'text': _("New"), 'help': _('Create new record.')}
        self.default_get_ctx = attrs.get('default_get', {}) or attrs.get('context', {})

#        self.colspan = 4
#        self.nolabel = True

        # get top params dictionary
        params = cherrypy.request.terp_params

        pprefix = ''
        if '/' in self.name:
            pprefix = self.name[:self.name.rindex('/')]

        pparams = params.chain_get(pprefix)
        if (pparams and not pparams.id) or (not pparams and not params.id):
            self.new_attrs = { 'text': _("Save/New"), 'help': _('Save parent record.')}

        self.parent_id = params.id
        if pparams:
            self.parent_id = pparams.id

        # get params for this field
        current = params.chain_get(self.name)

        self.model = attrs['relation']
        self.link = attrs.get('link', 1)
        self.onchange = None # override onchange in js code

        view = attrs.get('views', {})
        mode = str(attrs.get('mode', 'tree,form')).split(',')

        self.view = view
        
        view_mode = mode
        view_type = mode[0]
        if not current:
            current = TinyDict()

        if current.view_mode: view_mode = current.view_mode
        if current.view_type: view_type = current.view_type

        self.switch_to = view_mode[-1]
        if view_type == view_mode[-1]: self.switch_to = view_mode[0]
        
        ids = attrs.get('value') or []
        if not isinstance(ids, list):
            ids = [ids]
        
        if ids and isinstance(ids[0], dict):
            ids = []
            
        if ids and isinstance(ids[0], tuple):
            ids = [i[1] for i in ids]
            
        id = (ids or None) and ids[0]
        
        if current and params.source and self.name in params.source.split('/'):
            id = current.id

        id = id or None    
        current.model = self.model
        current.id = id
        current.ids = ids
        current.view_mode = view_mode
        current.view_type = view_type
        current.domain = current.domain or []
        current.context = current.context or {}

        if self.default_get_ctx:
            ctx = cherrypy.request.terp_record
            ctx['current_date'] = time.strftime('%Y-%m-%d')
            ctx['time'] = time
            ctx['context'] = current.context
            ctx['active_id'] = self.parent_id or False

            # XXX: parent record for O2M
            #if self.parent:
            #    ctx['parent'] = EvalEnvironment(self.parent)

            try:
                ctx = tools.expr_eval("dict(%s)" % self.default_get_ctx, ctx)
                current.context.update(ctx)
            except:
                pass

        current.offset = current.offset or 0
        current.limit = current.limit or 0 
        current.count = len(ids or [])

        if current.view_type == 'tree' and self.readonly:
            self.editable = False

        self.screen = Screen(current, prefix=self.name, views_preloaded=view,
                             editable=self.editable, readonly=self.readonly,
                             selectable=0, nolinks=self.link)
        self.id = id
        self.ids = ids

        if view_type == 'tree':
            limit = 20
            #self.screen.widget.pageable=False
            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.id = None

        pager_info = None
        if view_type == 'form':
            c = (self.screen.ids or 0) and len(self.screen.ids)
            i = 0

            if c and self.screen.id in self.screen.ids:
                i = self.screen.ids.index(self.screen.id) + 1

            self.pager_info = '[%s/%s]' % (i, c)
Example #19
0
    def __init__(self, **attrs):

        super(Action, self).__init__(**attrs)
        self.nolabel = True

        self.act_id = self.name
        res = rpc.session.execute('object', 'execute', 'ir.actions.actions',
                                  'read', [self.act_id], ['type'],
                                  rpc.session.context)
        if not res:
            raise _('Action not found!')

        type = res[0]['type']
        self.action = rpc.session.execute('object', 'execute', type, 'read',
                                          [self.act_id], False,
                                          rpc.session.context)[0]

        if 'view_mode' in attrs:
            self.action['view_mode'] = attrs['view_mode']

        if self.action['type'] == 'ir.actions.act_window':

            if not self.action.get('domain', False):
                self.action['domain'] = '[]'

            ctx = rpc.session.context.copy()
            ctx.update({'active_id': False, 'active_ids': []})

            self.context = tools.expr_eval(self.action.get('context', '{}'),
                                           ctx)
            self.domain = tools.expr_eval(self.action['domain'], ctx)

            views = dict(map(lambda x: (x[1], x[0]), self.action['views']))
            view_mode = self.action.get('view_mode', 'tree,form').split(',')
            view_ids = map(lambda x: views.get(x, False), view_mode)

            if self.action['view_type'] == 'form':

                params = TinyDict()
                params.model = self.action['res_model']
                params.id = False
                params.ids = None
                params.view_ids = view_ids
                params.view_mode = view_mode
                params.context = self.context
                params.domain = self.domain

                params.offset = params.offset or 0
                params.limit = params.limit or 20

                # get pager vars if set
                if hasattr(cherrypy.request, 'terp_params'):
                    current = cherrypy.request.terp_params
                    current = current.chain_get(self.name or '') or current

                    params.offset = current.offset
                    params.limit = current.limit

                self.screen = screen.Screen(params,
                                            prefix=self.name,
                                            editable=True,
                                            selectable=3)

            elif self.action['view_type'] == 'tree':
                pass  #TODO
Example #20
0
    def __init__(self, **attrs):
        #FIXME: validation error in `Pricelist Version`
        attrs['required'] = False

        super(O2M, self).__init__(**attrs)

        self.new_attrs = {'text': _("New"), 'help': _('Create new record.')}
        self.default_get_ctx = attrs.get('default_get', {}) or attrs.get(
            'context', {})

        # get top params dictionary
        params = cherrypy.request.terp_params
        self.source = params.source
        self.edition = params.o2m_edit
        pprefix = ''
        if '/' in self.name:
            pprefix = self.name[:self.name.rindex('/')]

        pparams = params.chain_get(pprefix)
        if (pparams and not pparams.id) or (not pparams and not params.id):
            self.new_attrs = {
                'text': _("Save/New"),
                'help': _('Save parent record.')
            }

        self.parent_id = params.id
        if pparams:
            self.parent_id = pparams.id

        # get params for this field
        current = params.chain_get(self.name)

        self.model = attrs['relation']
        self.link = attrs.get('link', '')
        self.onchange = None  # override onchange in js code

        view = attrs.get('views', {})
        mode = str(attrs.get('mode', 'tree,form')).split(',')

        self.view = view

        view_mode = mode
        view_type = mode[0]
        self.view_type = view_type

        if not current:
            current = TinyDict()

        if current.view_mode: view_mode = current.view_mode
        if current.view_type: view_type = current.view_type

        self.switch_to = view_mode[-1]
        if view_type == view_mode[-1]: self.switch_to = view_mode[0]

        ids = attrs.get('value') or []
        if not isinstance(ids, list):
            ids = [ids]

        current.offset = current.offset or 0
        current.limit = current.limit or 50
        current.count = len(ids or [])

        if current.limit != -1 and not params.sort_key:
            ids = ids[current.offset:current.offset + current.limit]

        if ids:
            if isinstance(ids[0], dict):
                current.default_data = ids
                for item in current.default_data:
                    self.default_value.append(OneToMany.create(item))
                    item['id'] = 0
                ids = []
            elif isinstance(ids[0], tuple):
                [current_id[1] for current_id in ids]

        id = (ids or None) and ids[0]

        if self.name == self.source or self.name == params.source:
            if params.sort_key and ids:
                domain = current.domain or []
                domain.append(('id', 'in', ids))
                limit = current.limit
                if current.limit == -1:
                    limit = 0
                ids = rpc.RPCProxy(self.model).search(
                    domain, current.offset, limit,
                    params.sort_key + ' ' + params.sort_order, current.context)
                id = ids[0]
        if current and params.source and isinstance(
                params.source,
                basestring) and self.name in params.source.split('/'):
            id = current.id

        id = id or None

        current.model = self.model
        current.id = id
        current.ids = ids
        current.view_mode = view_mode
        current.view_type = view_type
        current.domain = current.domain or []
        current.context = current.context or {}

        group_by_ctx = ''
        if self.default_get_ctx:
            ctx = dict(cherrypy.request.terp_record,
                       context=current.context,
                       active_id=self.parent_id or False)
            ctx[attrs['name']] = ids
            # XXX: parent record for O2M
            #if self.parent:
            #    ctx['parent'] = EvalEnvironment(self.parent)

            try:
                context = ctx.copy()
                ctx = expr_eval("dict(%s)" % self.default_get_ctx, context)
                ctx.update(
                    expr_eval("dict(%s)" % attrs.get('context', '{}'),
                              context))
                current.context.update(ctx)
            except:
                pass

            if ctx and ctx.get('group_by'):
                group_by_ctx = ctx.get('group_by')

        # Group By for one2many list.
        if group_by_ctx:
            current.group_by_ctx = group_by_ctx
            current.domain = [('id', 'in', ids)]

        if current.view_type == 'tree' and self.readonly:
            self.editable = False

        if 'default_name' in current.context:
            del current.context['default_name']

        self.screen = Screen(current,
                             prefix=self.name,
                             views_preloaded=view,
                             editable=self.editable,
                             readonly=self.readonly,
                             selectable=0,
                             nolinks=self.link,
                             _o2m=1)

        self.id = id
        self.ids = ids

        if view_type == 'tree':
            self.id = None

        elif view_type == 'form':
            records_count = len(self.screen.ids or [])

            current_record = 0
            if records_count and self.screen.id in self.screen.ids:
                current_record = self.screen.ids.index(self.screen.id) + 1
                self.pager_info = _('%d of %d') % (current_record,
                                                   records_count)
            else:
                self.pager_info = _('- of %d') % (records_count)
    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()
Example #22
0
    def __init__(self, **attrs):
        #FIXME: validation error in `Pricelist Version`
        attrs['required'] = False

        super(O2M, self).__init__(**attrs)

        self.new_attrs = { 'text': _("New"), 'help': _('Create new record.')}
        self.default_get_ctx = attrs.get('default_get', {}) or attrs.get('context', {})

        # get top params dictionary
        params = cherrypy.request.terp_params
        self.source = params.source
        self.edition = params.o2m_edit
        pprefix = ''
        if '/' in self.name:
            pprefix = self.name[:self.name.rindex('/')]

        pparams = params.chain_get(pprefix)
        if (pparams and not pparams.id) or (not pparams and not params.id):
            self.new_attrs = { 'text': _("Save/New"), 'help': _('Save parent record.')}

        self.parent_id = params.id
        if pparams:
            self.parent_id = pparams.id

        # get params for this field
        current = params.chain_get(self.name)

        self.model = attrs['relation']
        self.link = attrs.get('link', '')
        self.onchange = None # override onchange in js code

        view = attrs.get('views', {})
        mode = str(attrs.get('mode', 'tree,form')).split(',')

        self.view = view

        view_mode = mode
        view_type = mode[0]
        self.view_type = view_type
        
        if not current:
            current = TinyDict()

        if current.view_mode: view_mode = current.view_mode
        if current.view_type: view_type = current.view_type

        self.switch_to = view_mode[-1]
        if view_type == view_mode[-1]: self.switch_to = view_mode[0]

        ids = attrs.get('value') or []
        if not isinstance(ids, list):
            ids = [ids]

        if ids:
            if isinstance(ids[0], dict):
                current.default_data = ids
                for item in current.default_data:
                    self.default_value.append(
                        OneToMany.create(item))
                    item['id'] = 0
                ids = []
            elif isinstance(ids[0], tuple):
                [current_id[1] for current_id in ids]
        
        id = (ids or None) and ids[0]
        
        if self.name == self.source or self.name == params.source:
            if params.sort_key and ids:
                domain = current.domain or []
                domain.append(('id', 'in', ids))
                ids = rpc.RPCProxy(self.model).search(domain, current.offset, current.limit, params.sort_key + ' '+params.sort_order, current.context)
                id = ids[0]
        if current and params.source and self.name in params.source.split('/'):
            id = current.id

        id = id or None
                
        current.model = self.model
        current.id = id
        current.ids = ids
        current.view_mode = view_mode
        current.view_type = view_type
        current.domain = current.domain or []
        current.context = current.context or {}

        group_by_ctx = ''
        if self.default_get_ctx:
            ctx = dict(cherrypy.request.terp_record,
                       context=current.context,
                       active_id=self.parent_id or False)
            ctx[attrs['name']] = ids
            # XXX: parent record for O2M
            #if self.parent:
            #    ctx['parent'] = EvalEnvironment(self.parent)

            try:
                context = ctx.copy()
                ctx = expr_eval("dict(%s)" % self.default_get_ctx, context)
                ctx.update(expr_eval("dict(%s)" % attrs.get('context', '{}'), context))
                current.context.update(ctx)
            except:
                pass

            if ctx and ctx.get('group_by'):
                group_by_ctx = ctx.get('group_by')

        current.offset = current.offset or 0
        current.limit = current.limit or 50
        current.count = len(ids or [])

        # Group By for one2many list.
        if group_by_ctx:
            current.group_by_ctx = group_by_ctx
            current.domain = [('id', 'in', ids)]

        if current.view_type == 'tree' and self.readonly:
            self.editable = False

        if 'default_name' in current.context:
            del current.context['default_name']

        if self.view_type == 'tree' and pparams:
            self.editable = bool(pparams.id)

        self.screen = Screen(current, prefix=self.name, views_preloaded=view,
                             editable=self.editable, readonly=self.readonly,
                             selectable=0, nolinks=self.link, _o2m=1)
        
        self.id = id
        self.ids = ids

        if view_type == 'tree':
            self.id = None

        elif view_type == 'form':
            records_count = len(self.screen.ids or [])

            current_record = 0
            if records_count and self.screen.id in self.screen.ids:
                current_record = self.screen.ids.index(self.screen.id) + 1
                self.pager_info = _('%d of %d') % (current_record, records_count)
            else:
                self.pager_info = _('- of %d') % (records_count)
Example #23
0
    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 execute_window(view_ids,
                   model,
                   res_id=False,
                   domain=None,
                   view_type='form',
                   context=None,
                   mode='form,tree',
                   name=None,
                   target=None,
                   limit=None,
                   search_view=None,
                   context_menu=False,
                   display_menu_tip=False,
                   action_id=None):
    """Performs `actions.act_window` action.

    @param view_ids: view ids
    @param model: a model for which the action should be performed
    @param res_id: resource id
    @param domain: domain
    @param view_type: view type, eigther `form` or `tree`
    @param context: the context
    @param mode: view mode, eigther `form,tree` or `tree,form` or None

    @return: view (mostly XHTML code)
    """

    params = TinyDict()

    params.model = model
    params.ids = res_id
    params.view_ids = view_ids
    params.domain = domain or []
    params.context = context or {}
    params.limit = limit
    params.search_view = search_view
    params['context_menu'] = context_menu
    params['display_menu_tip'] = display_menu_tip
    params['target'] = target or None
    cherrypy.request._terp_view_name = name or None
    cherrypy.request._terp_view_target = target or None

    if action_id:
        params.action_id = action_id

    if name:
        params.context['_terp_view_name'] = name
    else:
        if params.context.get('_terp_view_name'):
            del params.context['_terp_view_name']

    if params.ids and not isinstance(params.ids, list):
        params.ids = [params.ids]

    params.id = (params.ids or False) and params.ids[0]

    mode = mode or view_type
    if view_type == 'form':
        mode = mode.split(',')
        params.view_mode = mode

        return Form().create(params)

    elif view_type == 'tree':
        return Tree().create(params)

    else:
        raise common.message(_("Invalid View"))