~openerp-community/openobject-addons/mgmtsystem

« back to all changes in this revision

Viewing changes to Translation/wizard/wizard_review_proposed_contributions.py

  • Committer: Dhara Shah
  • Date: 2008-03-13 13:24:26 UTC
  • Revision ID: dsh@tinyerp.com-e81d7411695adf6226de2fbf39d445c8b193e9f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import wizard
2
 
import tools
3
 
import csv
4
 
import pooler
5
 
from translation.translation import get_language
6
 
 
7
 
view_form_end = """<?xml version="1.0"?>
8
 
<form string="Language file loaded.">
9
 
    <image name="gtk-dialog-info" colspan="2"/>
10
 
    <group colspan="2" col="4">
11
 
        <separator string="Installation done" colspan="4"/>
12
 
        <label align="0.0" string="Csv file for the selected language has been successfully reviewed with the i18n file" colspan="4"/>
13
 
    </group>
14
 
</form>"""
15
 
 
16
 
view_form = """<?xml version="1.0"?>
17
 
<form string="Language Selection">
18
 
    <image name="gtk-dialog-info" colspan="2"/>
19
 
    <group colspan="2" col="4">
20
 
    <separator string="Language List" colspan="4"/>
21
 
        <label align="0.0" string="Choose a language to install:" colspan="4"/>
22
 
        <field name="lang" colspan="4"/>
23
 
        <label align="0.0" string="Note that this operation may take a few minutes." colspan="4"/>
24
 
    </group>
25
 
</form>"""
26
 
 
27
 
class wizard_review_proposed_contributions(wizard.interface):
28
 
    def _review_difference(self, cr, uid, data, context):
29
 
        lang = data['form']['lang']
30
 
        ir_translation = pooler.get_pool(cr.dbname).get('ir.translation')
31
 
        ir_translation_contrib = pooler.get_pool(cr.dbname).get('ir.translation.contribution')
32
 
        ids = ir_translation.search(cr,uid,[('lang','=',lang)])
33
 
        res = ir_translation.read(cr,uid,ids,['type','name','value','src'])
34
 
        new_res =map(lambda x:{'type':x['type'],'name':x['name'],'value':x['value'],'src':x['src']},res)
35
 
        filename = tools.config["root_path"] + "/i18n/" + lang + ".csv"
36
 
        reader = csv.DictReader(open(filename,'r'),delimiter=',')
37
 
        new_reader =map(lambda x:{'type':x['type'],'name':x['name'],'value':x['value'],'src':x['src']},reader)
38
 
        diff = []
39
 
        for l in new_res:
40
 
            if l in new_reader:
41
 
                continue
42
 
            diff.append(l)
43
 
        for d in diff:
44
 
            vals = {}
45
 
            ids = ir_translation.search(cr,uid,[('type','=',d['type']),('name','=',d['name']),('src','=',d['src']),('lang','=',lang)])
46
 
            res_id = ir_translation.read(cr,uid,ids,['res_id','lang'])[0]
47
 
            ids = ir_translation_contrib.search(cr,uid,[('type','=',d['type']),('name','=',d['name']),('src','=',d['src'])])
48
 
            if ids:
49
 
                ir_translation_contrib.write(cr,uid,ids,{'value':d['value'],'src':d['src']})
50
 
            if not ids:
51
 
                vals['type']=d['type']
52
 
                vals['name']=d['name']
53
 
                vals['src']=d['src']
54
 
                vals['value']=d['value']
55
 
                vals['res_id']=res_id['res_id']
56
 
                vals['lang'] = res_id['lang']
57
 
                vals['state']='draft'                            
58
 
                ir_translation_contrib.create(cr,uid,vals)
59
 
        return {}    
60
 
    def _get_language(sel, cr, uid,context):
61
 
        return get_language(cr,uid,context,model='ir_translation')
62
 
    
63
 
    fields_form = {
64
 
        'lang': {'string':'Language', 'type':'selection', 'selection':_get_language,
65
 
        },
66
 
    }    
67
 
    states = {
68
 
        'init': {
69
 
            'actions': [], 
70
 
            'result': {'type': 'form', 'arch': view_form, 'fields': fields_form,
71
 
                'state': [
72
 
                    ('end', 'Cancel', 'gtk-cancel'),
73
 
                    ('start', 'Review Difference', 'gtk-ok', True)
74
 
                ]
75
 
            }
76
 
        },
77
 
        'start': {
78
 
            'actions': [_review_difference],
79
 
            'result': {'type': 'form', 'arch': view_form_end, 'fields': {},
80
 
                'state': [
81
 
                    ('end', 'Ok', 'gtk-ok', True)
82
 
                ]
83
 
            }
84
 
        },
85
 
     }
86
 
wizard_review_proposed_contributions('review.proposed.contributions')
 
 
b'\\ No newline at end of file'