[IMP] web/database manager: admin login & country
Add inputs e-mail address and country when creating a newdatabase This will provide the installation of the correct chart of accounts at the installation of Accounting Use the provided login as the admin login, and set the email on the partner if the login set is an email Set the country on the company (and its partner) The countries are parsed from XML country list We take the opportunity to repair the `label for` which bind the label with the input only if the `id` attribute of the input is set with what is set in the `for` attribute of the label
This commit is contained in:
committed by
Denis Ledoux
parent
036e3cc253
commit
903733a320
@@ -636,6 +636,7 @@ class Database(http.Controller):
|
||||
d['insecure'] = openerp.tools.config['admin_passwd'] == 'admin'
|
||||
d['list_db'] = openerp.tools.config['list_db']
|
||||
d['langs'] = openerp.service.db.exp_list_lang()
|
||||
d['countries'] = openerp.service.db.exp_list_countries()
|
||||
# databases list
|
||||
d['databases'] = []
|
||||
try:
|
||||
@@ -657,7 +658,9 @@ class Database(http.Controller):
|
||||
@http.route('/web/database/create', type='http', auth="none", methods=['POST'], csrf=False)
|
||||
def create(self, master_pwd, name, lang, password, **post):
|
||||
try:
|
||||
request.session.proxy("db").create_database(master_pwd, name, bool(post.get('demo')), lang, password)
|
||||
# country code could be = "False" which is actually True in python
|
||||
country_code = post.get('country_code') or False
|
||||
request.session.proxy("db").create_database(master_pwd, name, bool(post.get('demo')), lang, password, post.get('login'), country_code)
|
||||
request.session.authenticate(name, 'admin', password)
|
||||
return http.local_redirect('/web/')
|
||||
except Exception, e:
|
||||
|
||||
@@ -37,38 +37,58 @@
|
||||
<input type="hidden" name="master_pwd" class="form-control" value="admin"/>
|
||||
{% else %}
|
||||
<label for="master_pwd" class="control-label">Master Password</label>
|
||||
<input type="password" name="master_pwd" class="form-control" required="required" autofocus="autofocus"/>
|
||||
<input id="master_pwd" type="password" name="master_pwd" class="form-control" required="required" autofocus="autofocus"/>
|
||||
{% endif %}
|
||||
</div>
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro create_form() -%}
|
||||
<p>Fill in this form to create an Odoo database. You may create
|
||||
databases for different companies or for different goals (testing,
|
||||
production). Once the database is created, you will be able to
|
||||
install your first application.</p>
|
||||
<p>Odoo is up and running! <br />
|
||||
Create a new database by filling out the form,
|
||||
you'll be able to install your first app in a minute.</p>
|
||||
{{ master_input() }}
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="col-md-12">
|
||||
<label for="name" class="control-label">Database Name</label>
|
||||
<input type="text" name="name" class="form-control" required="required" autocomplete="off"/>
|
||||
<input id="name" type="text" name="name" class="form-control" required="required" autocomplete="off"/>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label for="name" class="control-label">Language</label>
|
||||
<select name="lang" class="form-control" required="required" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<label for="login" class="control-label">Email</label>
|
||||
<input id="login" type="text" name="login" class="form-control" autocomplete="off"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label for="password" class="control-label">Password</label>
|
||||
<input id="password" type="password" name="password" class="form-control" required="required" autocomplete="off"/>
|
||||
<span class="fa fa-eye o_little_eye form-control-feedback" aria-hidden="true" style="cursor: pointer; pointer-events: auto"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<label for="lang" class="control-label">Language</label>
|
||||
<select id="lang" name="lang" class="form-control" required="required" autocomplete="off">
|
||||
{% for lang in langs %}
|
||||
<option {% if lang[0] == "en_US" %}selected="selected" {% endif %}value="{{ lang[0] }}">{{ lang[1] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label for="country" class="control-label">Country</label>
|
||||
<select id="country" name="country_code" class="form-control" autocomplete="off">
|
||||
<option value=""></option>
|
||||
{% for country in countries %}
|
||||
<option value="{{ country[0] }}">{{ country[1] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label for="password" class="control-label">Password of <em>admin</em> user</label>
|
||||
<input type="password" name="password" class="form-control" required="required" autocomplete="off"/>
|
||||
<span class="fa fa-eye o_little_eye form-control-feedback" aria-hidden="true" style="cursor: pointer; pointer-events: auto"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
@@ -173,11 +193,11 @@
|
||||
{{ master_input() }}
|
||||
<div class="form-group">
|
||||
<label for="backup_file" class="control-label">File</label>
|
||||
<input type="file" name="backup_file" class="required"/>
|
||||
<input id="backup_file" type="file" name="backup_file" class="required"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="name" class="control-label">Database Name</label>
|
||||
<input type="text" name="name" class="form-control" required="required"/>
|
||||
<input id="name" type="text" name="name" class="form-control" required="required"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="checkbox">
|
||||
@@ -211,7 +231,7 @@
|
||||
{{ master_input() }}
|
||||
<div class="form-group has-feedback">
|
||||
<label for="master_pwd_new" class="control-label">New Master Password</label>
|
||||
<input type="password" name="master_pwd_new" class="form-control" required="required" autocomplete="off"/>
|
||||
<input id="master_pwd_new" type="password" name="master_pwd_new" class="form-control" required="required" autocomplete="off"/>
|
||||
<span class="fa fa-eye o_little_eye form-control-feedback" aria-hidden="true" style="cursor: pointer; pointer-events: auto"></span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -237,11 +257,11 @@
|
||||
{{ master_input() }}
|
||||
<div class="form-group">
|
||||
<label for="name" class="control-label">Database Name</label>
|
||||
<input type="text" name="name" class="form-control" required="required" readonly="readonly"/>
|
||||
<input id="name" type="text" name="name" class="form-control" required="required" readonly="readonly"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="new_name" class="control-label">New Name</label>
|
||||
<input type="text" name="new_name" class="form-control" required="required"/>
|
||||
<input id="new_name" type="text" name="new_name" class="form-control" required="required"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
@@ -265,7 +285,7 @@
|
||||
{{ master_input() }}
|
||||
<div class="form-group">
|
||||
<label for="name" class="control-label">Database</label>
|
||||
<input type="text" name="name" class="form-control" required="required" readonly="readonly"/>
|
||||
<input id="name" type="text" name="name" class="form-control" required="required" readonly="readonly"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
@@ -289,11 +309,11 @@
|
||||
{{ master_input() }}
|
||||
<div class="form-group">
|
||||
<label for="name" class="control-label">Database Name</label>
|
||||
<input type="text" name="name" class="form-control" required="required" readonly="readonly"/>
|
||||
<input id="name" type="text" name="name" class="form-control" required="required" readonly="readonly"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="backup_format" class="control-label">Backup Format</label>
|
||||
<select name="backup_format" id="backup_format" class="form-control" required="required">
|
||||
<select id="backup_format" name="backup_format" id="backup_format" class="form-control" required="required">
|
||||
<option value="zip">zip (includes filestore)</option>
|
||||
<option value="dump">pg_dump custom format (without filestore)</option>
|
||||
</select>
|
||||
|
||||
+24
-4
@@ -7,6 +7,7 @@ import shutil
|
||||
import tempfile
|
||||
import threading
|
||||
import traceback
|
||||
import xml.etree.ElementTree as ET
|
||||
import zipfile
|
||||
|
||||
from functools import wraps
|
||||
@@ -36,7 +37,7 @@ def check_super(passwd):
|
||||
raise openerp.exceptions.AccessDenied()
|
||||
|
||||
# This should be moved to openerp.modules.db, along side initialize().
|
||||
def _initialize_db(id, db_name, demo, lang, user_password):
|
||||
def _initialize_db(id, db_name, demo, lang, user_password, login='admin', country_code=None):
|
||||
try:
|
||||
db = openerp.sql_db.db_connect(db_name)
|
||||
with closing(db.cursor()) as cr:
|
||||
@@ -54,8 +55,18 @@ def _initialize_db(id, db_name, demo, lang, user_password):
|
||||
mids = modobj.search(cr, SUPERUSER_ID, [('state', '=', 'installed')])
|
||||
modobj.update_translations(cr, SUPERUSER_ID, mids, lang)
|
||||
|
||||
# update admin's password and lang
|
||||
if country_code:
|
||||
countries = registry['res.country'].search_read(cr, SUPERUSER_ID, [('code', 'ilike', country_code)], fields=['id'])
|
||||
if countries:
|
||||
registry['res.company'].write(cr, SUPERUSER_ID, 1, {'country_id': countries[0]['id']})
|
||||
|
||||
# update admin's password and lang and login
|
||||
values = {'password': user_password, 'lang': lang}
|
||||
if login:
|
||||
values['login'] = login
|
||||
emails = openerp.tools.email_split(login)
|
||||
if emails:
|
||||
values['email'] = emails[0]
|
||||
registry['res.users'].write(cr, SUPERUSER_ID, [SUPERUSER_ID], values)
|
||||
|
||||
cr.execute('SELECT login, password FROM res_users ORDER BY login')
|
||||
@@ -75,11 +86,11 @@ def _create_empty_database(name):
|
||||
cr.autocommit(True) # avoid transaction block
|
||||
cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE "%s" """ % (name, chosen_template))
|
||||
|
||||
def exp_create_database(db_name, demo, lang, user_password='admin'):
|
||||
def exp_create_database(db_name, demo, lang, user_password='admin', login='admin', country_code=None):
|
||||
""" Similar to exp_create but blocking."""
|
||||
_logger.info('Create database `%s`.', db_name)
|
||||
_create_empty_database(db_name)
|
||||
_initialize_db(id, db_name, demo, lang, user_password)
|
||||
_initialize_db(id, db_name, demo, lang, user_password, login, country_code)
|
||||
return True
|
||||
|
||||
def exp_duplicate_database(db_original_name, db_name):
|
||||
@@ -332,6 +343,15 @@ def exp_list(document=False):
|
||||
def exp_list_lang():
|
||||
return openerp.tools.scan_languages()
|
||||
|
||||
def exp_list_countries():
|
||||
list_countries = []
|
||||
root = ET.parse(os.path.join(openerp.tools.config['root_path'], 'addons/base/res/res_country_data.xml')).getroot()
|
||||
for country in root.find('data').findall('record[@model="res.country"]'):
|
||||
name = country.find('field[@name="name"]').text
|
||||
code = country.find('field[@name="code"]').text
|
||||
list_countries.append([code, name])
|
||||
return sorted(list_countries, key=lambda c: c[1])
|
||||
|
||||
def exp_server_version():
|
||||
""" Return the version of the server
|
||||
Used by the client to verify the compatibility with its own version
|
||||
|
||||
Reference in New Issue
Block a user