# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
-
-import os
-import base64
-import random
+import logging
from operator import attrgetter
from osv import osv, fields
-import tools
from tools.translate import _
import netsvc
import pooler
-
class res_config_configurable(osv.osv_memory):
''' Base classes for new-style configuration items
their view inherit from the related res_config_view_base view.
'''
_name = 'res.config'
+ _inherit = 'ir.wizard.screen'
logger = netsvc.Logger()
+ __logger = logging.getLogger(_name)
+
+ def get_current_progress(self, cr, uid, context=None):
+ '''Return a description the current progress of configuration:
+ a tuple of (non_open_todos:int, total_todos: int)
+ '''
+ return (self.pool.get('ir.actions.todo')\
+ .search_count(cr, uid, [('state','<>','open')], context),
+ self.pool.get('ir.actions.todo')\
+ .search_count(cr, uid, [], context))
def _progress(self, cr, uid, context=None):
- total = self.pool.get('ir.actions.todo')\
- .search_count(cr, uid, [], context)
- open = self.pool.get('ir.actions.todo')\
- .search_count(cr, uid, [('state','<>','open')], context)
+ closed, total = self.get_current_progress(cr, uid, context=context)
if total:
- return round(open*100./total)
+ return round(closed*100./total)
return 100.
- def _get_image(self, cr, uid, context=None):
- file_no = str(random.randint(1,3))
- path = os.path.join('base','res','config_pixmaps/%s.png'%file_no)
- file_data = tools.file_open(path,'rb').read()
- return base64.encodestring(file_data)
-
_columns = dict(
progress = fields.float('Configuration Progress', readonly=True),
- config_logo = fields.binary('Image', readonly=True),
- )
+ )
+
_defaults = dict(
progress = _progress,
- config_logo = _get_image
- )
+ )
- def _next_action(self, cr, uid):
+ def _next_action(self, cr, uid, context=None):
todos = self.pool.get('ir.actions.todo')
- self.logger.notifyChannel('actions', netsvc.LOG_INFO,
- 'getting next %s' % todos)
+ self.__logger.info('getting next %s', todos)
active_todos = todos.search(cr, uid, [('state','=','open')],
limit=1)
- dont_skip_todo = True
if active_todos:
todo_obj = todos.browse(cr, uid, active_todos[0], context=None)
todo_groups = map(lambda x:x.id, todo_obj.groups_id)
+ dont_skip_todo = True
if todo_groups:
- cr.execute("select 1 from res_groups_users_rel where uid=%s and gid=ANY(%s)",(uid, todo_groups,))
+ cr.execute("select 1 from res_groups_users_rel where uid=%s and gid IN %s",(uid, tuple(todo_groups),))
dont_skip_todo = bool(cr.fetchone())
if dont_skip_todo:
return todos.browse(cr, uid, active_todos[0], context=None)
return self._next_action(cr, uid)
return None
- def _set_previous_todo(self, cr, uid, state):
+ def _set_previous_todo(self, cr, uid, state, context=None):
""" lookup the previous (which is still the next at this point)
ir.actions.todo, set it to whatever state was provided.
# this is ultra brittle, but apart from storing the todo id
# into the res.config view, I'm not sure how to get the
# "previous" todo
- previous_todo = self._next_action(cr, uid)
+ previous_todo = self._next_action(cr, uid, context=context)
if not previous_todo:
raise LookupError(_("Couldn't find previous ir.actions.todo"))
if not state:
- raise ValueError(_("Can't set an ir.actions.todo's state to "
- "nothingness"))
+ raise ValueError(_("Can't set an ir.actions.todo's state to an empty value."))
previous_todo.write({'state':state})
- def _next(self, cr, uid):
- self.logger.notifyChannel('actions', netsvc.LOG_INFO,
- 'getting next operation')
+ def _next(self, cr, uid, context=None):
+ self.__logger.info('getting next operation')
next = self._next_action(cr, uid)
- self.logger.notifyChannel('actions', netsvc.LOG_INFO,
- 'next action is %s' % next)
+ self.__logger.info('next action is %s', next)
if next:
action = next.action_id
return {
'res_model': action.res_model,
'type': action.type,
'target': action.target,
- }
- self.logger.notifyChannel(
- 'actions', netsvc.LOG_INFO,
- 'all configuration actions have been executed')
+ }
+ self.__logger.info('all configuration actions have been executed')
current_user_menu = self.pool.get('res.users')\
.browse(cr, uid, uid).menu_id
""" Returns the next todo action to execute (using the default
sort order)
"""
- return self._next(cr, uid)
+ return self._next(cr, uid, context=context)
def execute(self, cr, uid, ids, context=None):
""" Method called when the user clicks on the ``Next`` button.
an action dictionary -- executes the action provided by calling
``next``.
"""
- self._set_previous_todo(cr, uid, state='done')
+ try:
+ self._set_previous_todo(cr, uid, state='done', context=context)
+ except Exception, e:
+ raise osv.except_osv(_('Error'), e.message)
next = self.execute(cr, uid, ids, context=None)
if next: return next
return self.next(cr, uid, ids, context=context)
an action dictionary -- executes the action provided by calling
``next``.
"""
- self._set_previous_todo(cr, uid, state='skip')
+ try:
+ self._set_previous_todo(cr, uid, state='skip', context=context)
+ except Exception, e:
+ raise osv.except_osv(_('Error'), e.message)
next = self.cancel(cr, uid, ids, context=None)
if next: return next
return self.next(cr, uid, ids, context=context)
an action dictionary -- executes the action provided by calling
``next``.
"""
- self._set_previous_todo(cr, uid, state='cancel')
+ try:
+ self._set_previous_todo(cr, uid, state='cancel', context=context)
+ except Exception, e:
+ raise osv.except_osv(_('Error'), e.message)
next = self.cancel(cr, uid, ids, context=None)
if next: return next
return self.next(cr, uid, ids, context=context)
"""
_name = 'res.config.installer'
_inherit = 'res.config'
+ __logger = logging.getLogger(_name)
_install_if = {}
def _already_installed(self, cr, uid, context=None):
""" For each module (boolean fields in a res.config.installer),
- check if it's already installed (neither uninstallable nor uninstalled)
+ check if it's already installed (either 'to install', 'to upgrade' or 'installed')
and if it is, check it by default
"""
modules = self.pool.get('ir.module.module')
cr, uid,
modules.search(cr, uid,
[('name','in',selectable),
- ('state','not in',['uninstallable', 'uninstalled'])],
+ ('state','in',['to install', 'installed', 'to upgrade'])],
context=context),
context=context)
self._already_installed(cr, uid, context=context)),
True))
- def fields_get(self, cr, uid, fields=None, context=None, read_access=True):
+ def fields_get(self, cr, uid, fields=None, context=None, write_access=True):
""" If an addon is already installed, set it to readonly as
res.config.installer doesn't handle uninstallations of already
installed addons
"""
fields = super(res_config_installer, self).fields_get(
- cr, uid, fields, context, read_access)
+ cr, uid, fields, context, write_access)
for module in self._already_installed(cr, uid, context=context):
+ if module.name not in fields:
+ continue
fields[module.name].update(
readonly=True,
help=fields[module.name].get('help', '') +
modules = self.pool.get('ir.module.module')
to_install = list(self.modules_to_install(
cr, uid, ids, context=context))
- self.logger.notifyChannel(
- 'installer', netsvc.LOG_INFO,
- 'Selecting addons %s to install'%to_install)
+ self.__logger.info('Selecting addons %s to install', to_install)
modules.state_update(
cr, uid,
modules.search(cr, uid, [('name','in',to_install)]),
'to install', ['uninstalled'], context=context)
- cr.commit()
-
+ cr.commit() #TOFIX: after remove this statement, installation wizard is fail
pooler.restart_pool(cr.dbname, update_module=True)
res_config_installer()
'''
_name='ir.actions.configuration.wizard'
_inherit = 'res.config'
+ __logger = logging.getLogger(_name)
def _next_action_note(self, cr, uid, ids, context=None):
next = self._next_action(cr, uid)
}
def execute(self, cr, uid, ids, context=None):
- self.logger.notifyChannel(
- 'configuration', netsvc.LOG_WARNING, DEPRECATION_MESSAGE)
+ self.__logger.warn(DEPRECATION_MESSAGE)
ir_actions_configuration_wizard()