~openerp-community/openobject-addons/mgmtsystem

« back to all changes in this revision

Viewing changes to Translation/wizard/wizard_download_file_for_contrib.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 base64
5
 
import xmlrpclib
6
 
from translation.translation import get_language
7
 
 
8
 
s = xmlrpclib.Server("http://192.168.0.4:8000")
9
 
 
10
 
view_form_end = """<?xml version="1.0"?>
11
 
<form string="Language file loaded.">
12
 
    <image name="gtk-dialog-info" colspan="2"/>
13
 
    <group colspan="2" col="4">
14
 
        <separator string="Installation done" colspan="4"/>
15
 
        <label align="0.0" string="Csv file for the selected language has been successfully installed in i18n" colspan="4"/>
16
 
    </group>
17
 
</form>"""
18
 
 
19
 
view_form = """<?xml version="1.0"?>
20
 
<form string="Language Selection">
21
 
    <image name="gtk-dialog-info" colspan="2"/>
22
 
    <group colspan="2" col="4">
23
 
    <separator string="Language List" colspan="4"/>
24
 
        <label align="0.0" string="Choose a language to install:" colspan="4"/>
25
 
        <field name="lang" colspan="4"/>
26
 
        <label align="0.0" string="Note that this operation may take a few minutes." colspan="4"/>
27
 
    </group>
28
 
</form>"""
29
 
 
30
 
 
31
 
class wizard_download_file_for_contrib(wizard.interface):
32
 
    def _lang_install(self, cr, uid, data, context):
33
 
        lang = data['form']['lang']
34
 
        fname = lang + ".csv"
35
 
        try :
36
 
            text = s.get_release(fname)
37
 
            filename = tools.config["root_path"] + "/i18n/" + lang + ".csv"
38
 
            fp = file(filename,'wb').write(text.encode('utf8'))
39
 
            tools.s(cr.dbname, filename, lang)                 
40
 
        except Exception,e:
41
 
            print e
42
 
            raise wizard.except_wizard('Error !',"server is not properly configuraed")
43
 
        return {}
44
 
    
45
 
    def _get_language(sel, cr, uid,context):
46
 
        return get_language(cr,uid,context,user='contributor')
47
 
 
48
 
    fields_form = {
49
 
        'lang': {'string':'Language', 'type':'selection', 'selection':_get_language,
50
 
        },
51
 
    }
52
 
 
53
 
    states = {
54
 
        'init': {
55
 
            'actions': [], 
56
 
            'result': {'type': 'form', 'arch': view_form, 'fields': fields_form,
57
 
                'state': [
58
 
                    ('end', 'Cancel', 'gtk-cancel'),
59
 
                    ('start', 'Download File', 'gtk-ok', True)
60
 
                ]
61
 
            }
62
 
        },
63
 
        'start': {
64
 
            'actions': [_lang_install],
65
 
            'result': {'type': 'form', 'arch': view_form_end, 'fields': {},
66
 
                'state': [
67
 
                    ('end', 'Ok', 'gtk-ok', True)
68
 
                ]
69
 
            }
70
 
        },
71
 
    }
72
 
wizard_download_file_for_contrib('download.contrib.file')