Ejemplo n.º 1
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)
    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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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"))
Ejemplo n.º 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
Ejemplo n.º 6
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!"))
Ejemplo n.º 7
0
    def default(self, id, model, view_id, domain, context):
        params = TinyDict()

        try:
            view_id = int(view_id)
        except:
            view_id = False

        params.ids = id
        params.view_ids = [view_id]
        params.model = model
        params.domain = domain
        params.context = context or {}

        return self.create(params)
Ejemplo n.º 8
0
    def default(self, id, model, view_id, domain, context):
        params = TinyDict()

        try:
            view_id = int(view_id)
        except:
            view_id = False

        params.ids = id
        params.view_ids = [view_id]
        params.model = model
        params.domain = domain
        params.context = context or {}

        return self.create(params)
Ejemplo n.º 9
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"))
Ejemplo n.º 10
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