Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update_translations #21

Merged
merged 2 commits into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions anthem/lyrics/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,13 @@ def load_csv_stream(ctx, model, data,
rows = list(_rows)
if rows:
load_rows(ctx, model, header, rows)


def update_translations(ctx, modules):
""" Update translations from module list

:param modules: a list of modules
"""
for module in modules:
ctx.env['ir.module.module'].with_context(overwrite=True).search(
[('name', '=', module)]).update_translations()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is great, but should not be in the loaders which should be the place for lyrics that load records (using csv, xml, yaml or whatever).

I think we should have a module modules.py which contains update_translations and uninstall (which should be moved from uninstaller.py but uninstaller.py should be kept with a import of uninstall for backward compat).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are forcing the reload of po files. But as we target a module, it makes sense to create a new modules.py. Doing the change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leemannd I just notice now, this code is still there :'-( (and in modules.py as well)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, wouldn't be better since you gonna touch it ;P to do search([('name', 'in', modules)]).update_translations() w/out looping?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaaaaaaaand support filter_lang=None to update just one lang when needed

29 changes: 29 additions & 0 deletions anthem/lyrics/modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Copyright 2016-2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from ..exceptions import AnthemError


def uninstall(ctx, module_list):
""" uninstall module """
if not module_list:
raise AnthemError(u"You have to provide a list of "
"module's name to uninstall")

mods = ctx.env['ir.module.module'].search([('name', 'in', module_list)])
try:
mods.button_immediate_uninstall()
except:
raise AnthemError(u'Cannot uninstall modules. See the logs')


def update_translations(ctx, module_list):
""" Update translations from module list"""
if not module_list:
raise AnthemError(u"You have to provide a list of "
"module's name to update the translations")

for module in module_list:
ctx.env['ir.module.module'].with_context(overwrite=True).search(
[('name', '=', module)]).update_translations()
14 changes: 4 additions & 10 deletions anthem/lyrics/uninstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@
# Copyright 2016-2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from ..exceptions import AnthemError
from . import modules


def uninstall(ctx, module_list):
""" uninstall module """
if not module_list:
raise AnthemError(u"You have to provide a list of "
"module's name to uninstall")

mods = ctx.env['ir.module.module'].search([('name', 'in', module_list)])
try:
mods.button_immediate_uninstall()
except:
raise AnthemError(u'Cannot uninstall modules. See the logs')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you print a warning using ctx.log_line? ("Deprecated: use anthem.lyrics.modules.uninstall instead of anthem.lyrics.uninstaller.uninstall")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guewen Updated!

modules.uninstall(ctx, module_list)
ctx.log_line(u'Deprecated: use anthem.lyrics.modules.uninstall instead of '
'anthem.lyrics.uninstaller.uninstall')