示例#1
0
    def save(self, **kw):
        params, data = TinyDict.split(kw)

        error = None
        error_field = None

        id = params.id or 0
        id = (id > 0) and id or 0

        ids = params.ids or []

        model = params.parent.model
        if model != params.model and not params.parent.id:
            error = _("Parent record doesn't exists...")

        if error:
            return dict(error=error)

        try:
            proxy = rpc.RPCProxy(model)
            frm = TinyForm(**kw).to_python()
            data = {}
            ctx = context_with_concurrency_info(params.parent.context, params.concurrency_info)

            source = params.source
            if source and source != '_terp_list':

                data = frm.chain_get(source)

                if data is None:
                    return dict(error_field=error_field, error=error, id=id, ids=str([int(i) for i in ids]))

                if '__id' in data: data.pop('__id')
                if 'id' in data: data.pop('id')

                fld = source.split('/')[-1]
                data = {fld : [(id and 1, id, data.copy())]}
                proxy.write([params.parent.id], data, ctx)

                if not id:
                    all_ids = proxy.read([params.parent.id], [fld])[0][fld]
                    new_ids = [i for i in all_ids if i not in ids]

                    ids = all_ids
                    if new_ids:
                        id = new_ids[0]

            else:
                data = frm.copy()
                if 'id' in data: data.pop('id')

                if id > 0:
                    proxy.write([id], data, ctx)
                else:
                    id = proxy.create(data, params.parent.context or {})
                    ids = [id] + ids

        except TinyFormError, e:
            error_field = e.field
            error = ustr(e)
示例#2
0
    def clear_binary_data(self, **kw):
        params, data = TinyDict.split(kw)

        proxy = rpc.RPCProxy(params.model)
        ctx = utils.context_with_concurrency_info(params.context,
                                                  params.concurrency_info)

        if params.fname:
            proxy.write([params.id], {
                params.field: False,
                params.fname: False
            }, ctx)
        else:
            proxy.write([params.id], {params.field: False}, ctx)

        args = {
            'model': params.model,
            'id': params.id,
            'ids': ustr(params.ids),
            'view_ids': ustr(params.view_ids),
            'view_mode': ustr(params.view_mode),
            'domain': ustr(params.domain),
            'context': ustr(params.context),
            'offset': params.offset,
            'limit': params.limit,
            'count': params.count,
            'search_domain': ustr(params.search_domain),
            'filter_domain': ustr(params.filter_domain)
        }

        raise redirect(self.path + '/edit', **args)
示例#3
0
    def remove(self, **kw):
        params, data = TinyDict.split(kw)
        sc_ids = [i['id'] for i in cherrypy.session['terp_shortcuts']]
        error = None
        proxy = rpc.RPCProxy(params.model)
        if params.id:

            if params.model == 'ir.ui.view_sc' and cherrypy.session.get(
                    'terp_shortcuts'):
                for sc in cherrypy.session.get('terp_shortcuts'):
                    for id in params.id:
                        if id == sc['id']:
                            cherrypy.session['terp_shortcuts'].remove(sc)

            try:
                ctx = context_with_concurrency_info(params.context,
                                                    params.concurrency_info)
                if isinstance(params.id, list):
                    res = proxy.unlink(params.id, ctx)
                    for i in params.id:
                        params.ids.remove(i)
                else:
                    res = proxy.unlink([params.id], ctx)
                    params.ids.remove(params.id)

                if params.model == 'res.request':
                    ids, ids2 = rpc.RPCProxy(params.model).request_get()
                    return dict(res_ids=ids)

                return dict(ids=params.ids, count=len(params.ids))
            except Exception, e:
                error = ustr(e)
示例#4
0
    def clear_binary_data(self, **kw):
        params, data = TinyDict.split(kw)

        proxy = rpc.RPCProxy(params.model)
        ctx = utils.context_with_concurrency_info(params.context, params.concurrency_info)

        if params.fname:
            proxy.write([params.id], {params.field: False, params.fname: False}, ctx)
        else:
            proxy.write([params.id], {params.field: False}, ctx)

        args = {'model': params.model,
                'id': params.id,
                'ids': ustr(params.ids),
                'view_ids': ustr(params.view_ids),
                'view_mode': ustr(params.view_mode),
                'domain': ustr(params.domain),
                'context': ustr(params.context),
                'offset': params.offset,
                'limit': params.limit,
                'count': params.count,
                'search_domain': ustr(params.search_domain),
                'filter_domain': ustr(params.filter_domain)}

        raise redirect(self.path + '/edit', **args)
示例#5
0
    def remove(self, **kw):
        params, data = TinyDict.split(kw)
        sc_ids = [i['id'] for i in cherrypy.session['terp_shortcuts']]
        error = None
        proxy = rpc.RPCProxy(params.model)
        if params.id:

            if params.model == 'ir.ui.view_sc' and cherrypy.session.get('terp_shortcuts'):
                for sc in cherrypy.session.get('terp_shortcuts'):
                    for id in params.id:
                        if id == sc['id']:
                            cherrypy.session['terp_shortcuts'].remove(sc)

            try:
                ctx = context_with_concurrency_info(params.context, params.concurrency_info)
                if isinstance(params.id, list):
                    res = proxy.unlink(params.id, ctx)
                    for i in params.id:
                        params.ids.remove(i)
                else:
                    res = proxy.unlink([params.id], ctx)
                    params.ids.remove(params.id)

                if params.model == 'res.request':
                    ids, ids2 = rpc.RPCProxy(params.model).request_get()
                    return dict(res_ids = ids)

                return dict(ids = params.ids, count = len(params.ids))
            except Exception, e:
                error = ustr(e)
    def save(self, **kw):
        params, data = TinyDict.split(kw)

        error = None
        error_field = None

        id = params.id or 0
        id = (id > 0) and id or 0

        ids = params.ids or []

        model = params.parent.model
        if model != params.model and not params.parent.id:
            error = _("Parent record doesn't exists...")

        if error:
            return dict(error=error)

        try:
            proxy = rpc.RPCProxy(model)
            frm = TinyForm(**kw).to_python()
            data = {}
            ctx = context_with_concurrency_info(params.parent.context,
                                                params.concurrency_info)

            source = params.source
            if source and source != '_terp_list':

                data = frm.chain_get(source)

                if '__id' in data: data.pop('__id')
                if 'id' in data: data.pop('id')

                fld = source.split('/')[-1]
                data = {fld: [(id and 1, id, data.copy())]}
                proxy.write([params.parent.id], data, ctx)

                if not id:
                    all_ids = proxy.read([params.parent.id], [fld])[0][fld]
                    new_ids = [i for i in all_ids if i not in ids]

                    ids = all_ids
                    if new_ids:
                        id = new_ids[0]

            else:
                data = frm.copy()
                if 'id' in data: data.pop('id')

                if id > 0:
                    proxy.write([id], data, ctx)
                else:
                    id = proxy.create(data, params.parent.context or {})
                    ids = [id] + ids

        except TinyFormError, e:
            error_field = e.field
            error = ustr(e)
示例#7
0
    def save(self, terp_save_only=False, **kw):
        params, data = TinyDict.split(kw)
        params.editable = True

        proxy = rpc.RPCProxy(params.parent_model)

        pprefix = '.'.join(params.o2m.split('/')[:-1])

        if pprefix:
            data = eval(pprefix, TinyDict(**data)).make_dict()

        ctx = context_with_concurrency_info(rpc.session.context, params.concurrency_info)
        ctx.update(params.parent_context or {})
        ctx.update(params.o2m_context or {})

        id = proxy.write([params.parent_id], data, ctx)

        prefix = params.o2m
        current = params.chain_get(prefix)

        params.load_counter = 1

        ids = current.ids
        fld = params.o2m.split('/')[-1]
        all_ids = proxy.read([params.parent_id], [fld])[0][fld]
        new_ids = [i for i in all_ids if i not in ids]

        current.ids = all_ids
        if new_ids and params.source:
            current.id = new_ids[-1]
            params.o2m_id = current.id
        elif not params.button:
            params.o2m_id = False

        # perform button action
        if params.button:
            current.button = params.button
            current.parent_params = params
            cherrypy.request._terp_view_target = 'new'
            res = self.button_action(current)
            if res:
                tw.ConcurrencyInfo.update(
                    current.model, rpc.RPCProxy(current.model).read([current.id], ['__last_update'], ctx)
                )
                return res
        if params.close:
            return """
            <script type="text/javascript">
                jQuery.o2m('refresh_n_close');
            </script>
            """
        return self.create(params)
示例#8
0
    def save(self, terp_save_only=False, **kw):
        params, data = TinyDict.split(kw)
        params.editable = True

        proxy = rpc.RPCProxy(params.parent_model)

        pprefix = '.'.join(params.o2m.split('/')[:-1])

        if pprefix:
            data = eval(pprefix, TinyDict(**data)).make_dict()

        ctx = context_with_concurrency_info(rpc.session.context,
                                            params.concurrency_info)
        ctx.update(params.parent_context or {})
        ctx.update(params.o2m_context or {})

        id = proxy.write([params.parent_id], data, ctx)

        prefix = params.o2m
        current = params.chain_get(prefix)

        params.load_counter = 1

        ids = current.ids
        fld = params.o2m.split('/')[-1]
        all_ids = proxy.read([params.parent_id], [fld])[0][fld]
        new_ids = [i for i in all_ids if i not in ids]

        current.ids = all_ids
        if new_ids and params.source:
            current.id = new_ids[-1]
            params.o2m_id = current.id
        elif not params.button:
            params.o2m_id = False

        # perform button action
        if params.button:
            current.button = params.button
            current.parent_params = params
            cherrypy.request._terp_view_target = 'new'
            res = self.button_action(current)
            if res:
                return res
        if params.close:
            return """
            <script type="text/javascript">
                jQuery.o2m('refresh_n_close');
            </script>
            """
        return self.create(params)
    def delete(self, **kw):

        params, data = TinyDict.split(kw)

        error = None

        ctx = rpc.session.context.copy()
        ctx.update(params.context or {})
        ctx = context_with_concurrency_info(ctx, params.concurrency_info)

        proxy = rpc.RPCProxy(params.model)

        try:
            proxy.unlink([params.id], ctx)
        except Exception, e:
            error = ustr(e)
示例#10
0
    def delete(self, **kw):

        params, data = TinyDict.split(kw)

        error = None

        ctx = rpc.get_session().context.copy()
        ctx.update(params.context or {})
        ctx = context_with_concurrency_info(ctx, params.concurrency_info)

        proxy = rpc.RPCProxy(params.model)

        try:
            proxy.unlink([params.id], ctx)
        except Exception, e:
            error = ustr(e)
示例#11
0
    def delete(self, **kw):
        params, data = TinyDict.split(kw)

        current = params.chain_get(params.source or '') or params
        proxy = rpc.RPCProxy(current.model)

        idx = -1
        if current.id:
            ctx = utils.context_with_concurrency_info(current.context,
                                                      params.concurrency_info)
            res = proxy.unlink([current.id], ctx)
            if current.ids:
                idx = current.ids.index(current.id)
                if idx >= 0:
                    current.ids.remove(current.id)
            params.count -= 1
            if not len(current.ids) and params.count > 0:
                params.offset = params.offset - params.limit
                current.ids = proxy.search([], params.offset, params.limit, 0,
                                           ctx)
                idx = -1
            if idx == len(current.ids):
                idx = -1
        current.id = (current.ids or None) and current.ids[idx]
        self.reset_notebooks()

        args = {
            'model': params.model,
            'id': params.id,
            'ids': ustr(params.ids),
            'view_ids': ustr(params.view_ids),
            'view_mode': ustr(params.view_mode),
            'domain': ustr(params.domain),
            'context': ustr(params.context),
            'offset': params.offset,
            'limit': params.limit,
            'count': params.count,
            'search_domain': ustr(params.search_domain),
            'filter_domain': ustr(params.filter_domain)
        }

        if not params.id:
            raise redirect(self.path + '/edit', **args)

        raise redirect(self.path + '/view', **args)
示例#12
0
    def save(self, terp_save_only=False, **kw):
        params, data = TinyDict.split(kw)

        # remember the current page (tab) of notebooks
        cherrypy.session['remember_notebooks'] = True

        # bypass save, for button action in non-editable view
        if not (params.button and not params.editable and params.id):

            proxy = rpc.RPCProxy(params.model)

            if not params.id:
                id = proxy.create(data, params.context)
                params.ids = (params.ids or []) + [int(id)]
                params.id = int(id)
                params.count += 1
            else:
                ctx = context_with_concurrency_info(params.context, params.concurrency_info)
                id = proxy.write([params.id], data, ctx)

        current = params.chain_get(params.source or '')
        button = (params.button or False) and True

        params.load_counter = 1
        if current and current.id and not button:
            params.load_counter = 2

        # perform button action
        if params.button:
            res = self.button_action(params)
            if res:
                return res


        if current:
            current.id = None
            if not params.id:
                params.id = int(id)
        elif not button:
            params.editable = False

        if not current and not button:
            params.load_counter = 2

        return self.create(params)
    def save(self, **kw):
        params, data = TinyDict.split(kw)

        data = {}
        ds = tc.utils.parse_datetime(params.starts)
        de = tc.utils.parse_datetime(params.ends)

        data[params.fields['date_start']['name']] = format.parse_datetime(
            ds.timetuple())

        if 'date_stop' in params.fields:
            data[params.fields['date_stop']['name']] = format.parse_datetime(
                de.timetuple())
        elif 'date_delay' in params.fields:
            # convert the end time in hours
            day_length = params.fields['day_length']

            tds = time.mktime(ds.timetuple())
            tde = time.mktime(de.timetuple())

            n = (tde - tds) / (60 * 60)

            if n > day_length:
                d = math.floor(n / 24)
                h = n % 24

                n = d * day_length + h

            data[params.fields['date_delay']['name']] = n

        ctx = dict(rpc.session.context, **(params.context or {}))
        ctx = context_with_concurrency_info(ctx, params.concurrency_info)

        error = None
        proxy = rpc.RPCProxy(params.model)

        try:
            proxy.write([params.id], data, ctx)
            info = proxy.read([params.id],
                              ['__last_update'])[0]['__last_update']
            info = {'%s,%s' % (params.model, params.id): info}
        except Exception, e:
            error = ustr(e)
示例#14
0
文件: form.py 项目: hectord/unifield
    def delete(self, **kw):
        params, data = TinyDict.split(kw)

        current = params.chain_get(params.source or '') or params
        proxy = rpc.RPCProxy(current.model)

        idx = -1
        if current.id:
            ctx = utils.context_with_concurrency_info(current.context, params.concurrency_info)
            res = proxy.unlink([current.id], ctx)
            if current.ids:
                idx = current.ids.index(current.id)
                if idx >= 0:
                    current.ids.remove(current.id)
            params.count -= 1
            if not len(current.ids) and params.count > 0:
                params.offset = max(params.offset - params.limit, 0)
                current.ids = proxy.search([], params.offset, params.limit,0, ctx)
                idx = -1
            if idx == len(current.ids):
                idx = -1
        current.id = (current.ids or None) and current.ids[idx]
        self.reset_notebooks()

        args = {'model': params.model,
                'id': params.id,
                'ids': ustr(params.ids),
                'view_ids': ustr(params.view_ids),
                'view_mode': ustr(params.view_mode),
                'domain': ustr(params.domain),
                'context': ustr(params.context),
                'offset': params.offset,
                'limit': params.limit,
                'count': params.count,
                'search_domain': ustr(params.search_domain),
                'filter_domain': ustr(params.filter_domain),
                'sidebar_closed': params.sidebar_closed}

        if not params.id:
            raise redirect(self.path + '/edit', **args)

        raise redirect(self.path + '/view', **args)
    def save(self, terp_save_only=False, **kw):
        params, data = TinyDict.split(kw)

        # remember the current page (tab) of notebooks
        cherrypy.session['remember_notebooks'] = True

        # bypass save, for button action in non-editable view
        if not (params.button and not params.editable and params.id):

            proxy = rpc.RPCProxy(params.model)

            if not params.id:
                id = proxy.create(data, params.context)
                params.ids = (params.ids or []) + [int(id)]
                params.id = int(id)
                params.count += 1
            else:
                ctx = context_with_concurrency_info(params.context,
                                                    params.concurrency_info)
                id = proxy.write([params.id], data, ctx)

        button = (params.button or False) and True

        # perform button action
        if params.button:
            res = self.button_action(params)
            if res:
                return res

        current = params.chain_get(params.source or '')
        if current:
            current.id = None
            if not params.id:
                params.id = int(id)
        elif not button:
            params.editable = False

        if not current and not button:
            params.load_counter = 2

        return self.create(params)
示例#16
0
    def save(self, **kw):
        params, data = TinyDict.split(kw)

        data = {}
        ds = tc.utils.parse_datetime(params.starts)
        de = tc.utils.parse_datetime(params.ends)

        data[params.fields['date_start']['name']] = format.parse_datetime(ds.timetuple())

        if 'date_stop' in params.fields:
            data[params.fields['date_stop']['name']] = format.parse_datetime(de.timetuple())
        elif 'date_delay' in params.fields:
            # convert the end time in hours
            day_length = params.fields['day_length']

            tds = time.mktime(ds.timetuple())
            tde = time.mktime(de.timetuple())

            n = (tde - tds) / (60 * 60)

            if n > day_length:
                d = math.floor(n / 24)
                h = n % 24

                n = d * day_length + h

            data[params.fields['date_delay']['name']] = n

        ctx = dict(rpc.get_session().context,
                   **(params.context or {}))
        ctx = context_with_concurrency_info(ctx, params.concurrency_info)

        error = None
        proxy = rpc.RPCProxy(params.model)

        try:
            proxy.write([params.id], data, ctx)
            info = proxy.read([params.id], ['__last_update'])[0]['__last_update']
            info = {'%s,%s'%(params.model, params.id): info}
        except Exception, e:
            error = ustr(e)
示例#17
0
    def save(self, terp_save_only=False, **kw):
        """Controller method to save/button actions...

        @param tg_errors: TG special arg, used durring validation
        @param kw: keyword arguments

        @return: form view
        """
        params, data = TinyDict.split(kw)
        # remember the current page (tab) of notebooks
        cherrypy.session['remember_notebooks'] = True

        Model = rpc.RPCProxy(params.model)
        # bypass save, for button action in non-editable view
        if params.editable:
            if not params.id:

                if params.default_o2m:
                    data.update(params.default_o2m)
                ctx = dict((params.context or {}), **rpc.get_session().context)
                params.id = int(Model.create(data, ctx))
                params.ids = (params.ids or []) + [params.id]
                params.count += 1
            else:
                original_data = Model.read(params.id, data.keys())
                modified = {}

                if original_data and isinstance(original_data, dict):
                    for field, original_value in original_data.iteritems():
                        if isinstance(original_value, tuple):
                            original_data[field] = original_value[0]
                        if field in data and data[field] != original_data[field]:
                            modified[field] = data[field]

                    ctx = utils.context_with_concurrency_info(params.context, params.concurrency_info)
                    Model.write([params.id], modified, ctx)
                else:
                    ctx = utils.context_with_concurrency_info(params.context, params.concurrency_info)
                    Model.write([params.id], data, ctx)

            tw.ConcurrencyInfo.update(
                params.model, Model.read([params.id], ['__last_update'], ctx)
            )

        cherrypy.request.params = params

        button = params.button

        # perform button action
        if params.button:
            res = self.button_action(params)
            if res:
                return res

        current = params.chain_get(params.source or '')
        if current:
            current.id = None
        elif not button:
            params.editable = False

        if terp_save_only:
            return dict(params=params, data=data)

        def get_params(p, f):

            pp = p.chain_get(f)
            px = rpc.RPCProxy(p.model)

            _ids = pp.ids
            _all = px.read([p.id], [f])[0][f]
            _new = [i for i in _all if i not in _ids]

            pp.ids = _all
            if _new:
                pp.id = _new[0]

            return pp

        if params.source and len(params.source.split("/")) > 1:

            path = params.source.split("/")
            p = params
            for f in path:
                p = get_params(p, f)

            return self.create(params)

        args = {'model': params.model,
                'id': params.id,
                'ids': ustr(params.ids),
                'view_ids': ustr(params.view_ids),
                'view_mode': ustr(params.view_mode),
                'domain': ustr(params.domain),
                'context': ustr(params.context),
                'offset': params.offset,
                'limit': params.limit,
                'count': params.count,
                'search_domain': ustr(params.search_domain),
                'search_data': ustr(params.search_data),
                'filter_domain': ustr(params.filter_domain),
                'notebook_tab': params.notebook_tab}
        if params.o2m_edit:
            # hack to avoid creating new record line when editing o2m inline:
            # by default one2many.mako is going to fetch a new line (.create)
            # on /edit
            args['o2m_edit'] = "1"

        if params.editable or params.source or params.return_edit:
            raise redirect(self.path + '/edit', source=params.source, **args)
        raise redirect(self.path + '/view', **args)
示例#18
0
    def save(self, terp_save_only=False, **kw):
        """Controller method to save/button actions...

        @param tg_errors: TG special arg, used durring validation
        @param kw: keyword arguments

        @return: form view
        """
        params, data = TinyDict.split(kw)
        # remember the current page (tab) of notebooks
        cherrypy.session['remember_notebooks'] = True

        Model = rpc.RPCProxy(params.model)
        # bypass save, for button action in non-editable view
        if params.editable:
            if not params.id:

                if params.default_o2m:
                    data.update(params.default_o2m)
                ctx = dict((params.context or {}), **rpc.session.context)
                params.id = int(Model.create(data, ctx))
                params.ids = (params.ids or []) + [params.id]
                params.count += 1
            else:
                original_data = Model.read(params.id, data.keys())
                modified = {}

                if original_data and isinstance(original_data, dict):
                    for field, original_value in original_data.iteritems():
                        if isinstance(original_value, tuple):
                            original_data[field] = original_value[0]
                        if field in data and data[field] != original_data[
                                field]:
                            #When field is many2many at that time following code will be applied
                            if isinstance(data[field], list) and isinstance(
                                    data[field][0][2], list):
                                if sorted(data[field][0][2]) != sorted(
                                        original_data[field]):
                                    modified[field] = data[field]
                            else:
                                modified[field] = data[field]

                    ctx = utils.context_with_concurrency_info(
                        params.context, params.concurrency_info)
                    Model.write([params.id], modified, ctx)
                else:
                    ctx = utils.context_with_concurrency_info(
                        params.context, params.concurrency_info)
                    Model.write([params.id], data, ctx)

            tw.ConcurrencyInfo.update(
                params.model, Model.read([params.id], ['__last_update'], ctx))

        cherrypy.request.params = params

        button = params.button

        # perform button action
        if params.button:
            res = self.button_action(params)
            if res:
                return res

        current = params.chain_get(params.source or '')
        if current:
            current.id = None
        elif not button:
            params.editable = False

        if terp_save_only:
            return dict(params=params, data=data)

        def get_params(p, f):

            pp = p.chain_get(f)
            px = rpc.RPCProxy(p.model)

            _ids = pp.ids
            _all = px.read([p.id], [f])[0][f]
            _new = [i for i in _all if i not in _ids]

            pp.ids = _all
            if _new:
                pp.id = _new[0]

            return pp

        if params.source and len(params.source.split("/")) > 1:

            path = params.source.split("/")
            p = params
            for f in path:
                p = get_params(p, f)

            return self.create(params)

        args = {
            'model': params.model,
            'id': params.id,
            'ids': ustr(params.ids),
            'view_ids': ustr(params.view_ids),
            'view_mode': ustr(params.view_mode),
            'domain': ustr(params.domain),
            'context': ustr(params.context),
            'offset': params.offset,
            'limit': params.limit,
            'count': params.count,
            'search_domain': ustr(params.search_domain),
            'search_data': ustr(params.search_data),
            'filter_domain': ustr(params.filter_domain),
            'notebook_tab': params.notebook_tab
        }
        if params.o2m_edit:
            # hack to avoid creating new record line when editing o2m inline:
            # by default one2many.mako is going to fetch a new line (.create)
            # on /edit
            args['o2m_edit'] = "1"

        if params.editable or params.source or params.return_edit:
            raise redirect(self.path + '/edit', source=params.source, **args)
        raise redirect(self.path + '/view', **args)