~ubuntu-branches/ubuntu/natty/openerp-web/natty

« back to all changes in this revision

Viewing changes to openerp/controllers/fieldpref.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2010-09-13 09:21:22 UTC
  • Revision ID: james.westby@ubuntu.com-20100913092122-0eovj11cxresot89
Tags: upstream-5.0.12+dfsg
ImportĀ upstreamĀ versionĀ 5.0.12+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
###############################################################################
 
2
#
 
3
# Copyright (C) 2007-TODAY Tiny ERP Pvt Ltd. All Rights Reserved.
 
4
#
 
5
# $Id$
 
6
#
 
7
# Developed by Tiny (http://openerp.com) and Axelor (http://axelor.com).
 
8
#
 
9
# The OpenERP web client is distributed under the "OpenERP Public License".
 
10
# It's based on Mozilla Public License Version (MPL) 1.1 with following
 
11
# restrictions:
 
12
#
 
13
# -   All names, links and logos of Tiny, Open ERP and Axelor must be
 
14
#     kept as in original distribution without any changes in all software
 
15
#     screens, especially in start-up page and the software header, even if
 
16
#     the application source code has been changed or updated or code has been
 
17
#     added.
 
18
#
 
19
# -   All distributions of the software must keep source code with OEPL.
 
20
#
 
21
# -   All integrations to any other software must keep source code with OEPL.
 
22
#
 
23
# If you need commercial licence to remove this kind of restriction please
 
24
# contact us.
 
25
#
 
26
# You can see the MPL licence at: http://www.mozilla.org/MPL/MPL-1.1.html
 
27
#
 
28
###############################################################################
 
29
 
 
30
import os
 
31
import time
 
32
 
 
33
from openerp.tools import expose
 
34
 
 
35
import cherrypy
 
36
 
 
37
from openerp import rpc
 
38
from openerp import tools
 
39
from openerp import common
 
40
 
 
41
from openerp.controllers.base import SecuredController
 
42
 
 
43
from openerp.utils import TinyDict
 
44
from openerp.utils import TinyForm
 
45
 
 
46
import openerp.widgets as tw
 
47
 
 
48
class FieldPref(SecuredController):
 
49
 
 
50
    @expose(template="templates/fieldpref.mako")
 
51
    def index(self, **kw): #_terp_model, _terp_field, _terp_deps
 
52
 
 
53
        click_ok = None
 
54
        params, data = TinyDict.split(kw)
 
55
 
 
56
        return dict(model=params.model, click_ok=click_ok, field=params.field, deps=params.deps)
 
57
 
 
58
    @expose('json')
 
59
    def get(self, **kw):
 
60
        params, data = TinyDict.split(kw)
 
61
 
 
62
        field = params.field.split('/')
 
63
 
 
64
        prefix = '.'.join(field[:-1])
 
65
        field = field[-1]
 
66
 
 
67
        pctx = TinyForm(**kw).to_python(safe=True)
 
68
        ctx = pctx.chain_get(prefix) or pctx
 
69
 
 
70
        proxy = rpc.RPCProxy(params.model)
 
71
        res = proxy.fields_get(False, rpc.session.context)
 
72
 
 
73
        text = res[field].get('string')
 
74
        deps = []
 
75
 
 
76
        for name, attrs in res.items():
 
77
            if attrs.get('change_default', False):
 
78
                value = ctx.get(name)
 
79
                if value:
 
80
                    deps.append((name, name, value, value))
 
81
 
 
82
        return dict(text=text, deps=str(deps))
 
83
 
 
84
    @expose(template="templates/fieldpref.mako")
 
85
    def save(self, **kw):
 
86
        params, data = TinyDict.split(kw)
 
87
 
 
88
        deps = False
 
89
        if params.deps:
 
90
            for n, v in params.deps.items():
 
91
                deps = "%s=%s" %(n,v)
 
92
                break
 
93
 
 
94
        model = params.model
 
95
        field = params.field['name']
 
96
        value = params.field['value']
 
97
        click_ok = 1
 
98
 
 
99
        field = field.split('/')[-1]
 
100
 
 
101
        proxy = rpc.RPCProxy('ir.values')
 
102
        
 
103
        if type(value) == type('') and not len(value):
 
104
            value = False
 
105
        
 
106
        res = proxy.set('default', deps, field, [(model,False)], value, True, False, False, params.you or False, True)
 
107
 
 
108
        return dict(model=params.model, click_ok=click_ok, field=params.field, deps=params.deps2, should_close=True)
 
109
 
 
110
# vim: ts=4 sts=4 sw=4 si et
 
111