diff --git a/rhodecode/lib/base.py b/rhodecode/lib/base.py --- a/rhodecode/lib/base.py +++ b/rhodecode/lib/base.py @@ -38,7 +38,7 @@ from pylons.controllers import WSGIContr from pylons.controllers.util import redirect from pylons.i18n import translation # marcink: don't remove this import -from pylons.templating import render_mako as render # noqa +from pylons.templating import render_mako, pylons_globals, literal, cached_template from pylons.i18n.translation import _ from webob.exc import HTTPFound @@ -65,6 +65,32 @@ from rhodecode.model.settings import Vcs log = logging.getLogger(__name__) +# hack to make the migration to pyramid easier +def render(template_name, extra_vars=None, cache_key=None, + cache_type=None, cache_expire=None): + """Render a template with Mako + + Accepts the cache options ``cache_key``, ``cache_type``, and + ``cache_expire``. + + """ + # Create a render callable for the cache function + def render_template(): + # Pull in extra vars if needed + globs = extra_vars or {} + + # Second, get the globals + globs.update(pylons_globals()) + + globs['_ungettext'] = globs['ungettext'] + # Grab a template reference + template = globs['app_globals'].mako_lookup.get_template(template_name) + + return literal(template.render_unicode(**globs)) + + return cached_template(template_name, render_template, cache_key=cache_key, + cache_type=cache_type, cache_expire=cache_expire) + def _filter_proxy(ip): """ Passed in IP addresses in HEADERS can be in a special format of multiple diff --git a/rhodecode/lib/partial_renderer.py b/rhodecode/lib/partial_renderer.py --- a/rhodecode/lib/partial_renderer.py +++ b/rhodecode/lib/partial_renderer.py @@ -64,7 +64,7 @@ class PyramidPartialRenderer(object): _kwargs = { '_': self.request.translate, - 'ungettext': self.request.plularize, + '_ungettext': self.request.plularize, 'h': self.get_helpers(), 'c': self.get_call_context(), diff --git a/rhodecode/lib/utils.py b/rhodecode/lib/utils.py --- a/rhodecode/lib/utils.py +++ b/rhodecode/lib/utils.py @@ -904,7 +904,7 @@ class PartialRenderer(object): 'h': self.h, 'c': self.c, 'request': self.request, - 'ungettext': self.ungettext, + '_ungettext': self.ungettext, } _kwargs.update(kwargs) return _kwargs diff --git a/rhodecode/templates/admin/repo_groups/repo_group_edit_advanced.mako b/rhodecode/templates/admin/repo_groups/repo_group_edit_advanced.mako --- a/rhodecode/templates/admin/repo_groups/repo_group_edit_advanced.mako +++ b/rhodecode/templates/admin/repo_groups/repo_group_edit_advanced.mako @@ -33,7 +33,7 @@ - ${ungettext('This repository group includes %s children repository group.', 'This repository group includes %s children repository groups.', c.repo_group.children.count()) % c.repo_group.children.count()} + ${_ungettext('This repository group includes %s children repository group.', 'This repository group includes %s children repository groups.', c.repo_group.children.count()) % c.repo_group.children.count()} @@ -42,7 +42,7 @@ - ${ungettext('This repository group includes %s repository.', 'This repository group includes %s repositories.', c.repo_group.repositories_recursive_count) % c.repo_group.repositories_recursive_count} + ${_ungettext('This repository group includes %s repository.', 'This repository group includes %s repositories.', c.repo_group.repositories_recursive_count) % c.repo_group.repositories_recursive_count} diff --git a/rhodecode/templates/admin/users/user_edit_advanced.mako b/rhodecode/templates/admin/users/user_edit_advanced.mako --- a/rhodecode/templates/admin/users/user_edit_advanced.mako +++ b/rhodecode/templates/admin/users/user_edit_advanced.mako @@ -87,7 +87,7 @@ % if not c.commit_ranges: diff --git a/rhodecode/templates/compare/compare_diff.mako b/rhodecode/templates/compare/compare_diff.mako --- a/rhodecode/templates/compare/compare_diff.mako +++ b/rhodecode/templates/compare/compare_diff.mako @@ -14,7 +14,7 @@ <%def name="breadcrumbs_links()"> - ${ungettext('%s commit','%s commits', len(c.commit_ranges)) % len(c.commit_ranges)} + ${_ungettext('%s commit','%s commits', len(c.commit_ranges)) % len(c.commit_ranges)} <%def name="menu_bar_nav()"> @@ -309,13 +309,13 @@ class="btn" href="#" onclick="$('.compare_select').show();$('.compare_select_hidden').hide(); return false"> - ${ungettext('Expand %s commit','Expand %s commits', len(c.commit_ranges)) % len(c.commit_ranges)} + ${_ungettext('Expand %s commit','Expand %s commits', len(c.commit_ranges)) % len(c.commit_ranges)} - ${ungettext('Collapse %s commit','Collapse %s commits', len(c.commit_ranges)) % len(c.commit_ranges)} + ${_ungettext('Collapse %s commit','Collapse %s commits', len(c.commit_ranges)) % len(c.commit_ranges)} diff --git a/rhodecode/templates/data_table/_dt_elements.mako b/rhodecode/templates/data_table/_dt_elements.mako --- a/rhodecode/templates/data_table/_dt_elements.mako +++ b/rhodecode/templates/data_table/_dt_elements.mako @@ -182,7 +182,7 @@
${h.secure_form(h.url('delete_repo_group', group_name=repo_group_name),method='delete')} ${h.submit('remove_%s' % repo_group_name,_('Delete'),class_="btn btn-link btn-danger", - onclick="return confirm('"+ungettext('Confirm to delete this group: %s with %s repository','Confirm to delete this group: %s with %s repositories',gr_count) % (repo_group_name, gr_count)+"');")} + onclick="return confirm('"+_ungettext('Confirm to delete this group: %s with %s repository','Confirm to delete this group: %s with %s repositories',gr_count) % (repo_group_name, gr_count)+"');")} ${h.end_form()}
diff --git a/rhodecode/templates/debug_style/buttons.html b/rhodecode/templates/debug_style/buttons.html --- a/rhodecode/templates/debug_style/buttons.html +++ b/rhodecode/templates/debug_style/buttons.html @@ -116,7 +116,7 @@
- diff --git a/rhodecode/templates/email_templates/pull_request_review.mako b/rhodecode/templates/email_templates/pull_request_review.mako --- a/rhodecode/templates/email_templates/pull_request_review.mako +++ b/rhodecode/templates/email_templates/pull_request_review.mako @@ -43,7 +43,7 @@ data = { ${pull_request.description} -* ${ungettext('Commit (%(num)s)', 'Commits (%(num)s)', len(pull_request_commits) ) % {'num': len(pull_request_commits)}}: +* ${_ungettext('Commit (%(num)s)', 'Commits (%(num)s)', len(pull_request_commits) ) % {'num': len(pull_request_commits)}}: % for commit_id, message in pull_request_commits: - ${h.short_id(commit_id)} @@ -73,7 +73,7 @@ data = { - +
- ${ungettext('This user owns %s repository.', 'This user owns %s repositories.', len(c.user.repositories)) % len(c.user.repositories)} + ${_ungettext('This user owns %s repository.', 'This user owns %s repositories.', len(c.user.repositories)) % len(c.user.repositories)} %if len(c.user.repositories) > 0: @@ -103,7 +103,7 @@
- ${ungettext('This user owns %s repository group.', 'This user owns %s repository groups.', len(c.user.repository_groups)) % len(c.user.repository_groups)} + ${_ungettext('This user owns %s repository group.', 'This user owns %s repository groups.', len(c.user.repository_groups)) % len(c.user.repository_groups)} %if len(c.user.repository_groups) > 0: @@ -119,7 +119,7 @@
- ${ungettext('This user owns %s user group.', 'This user owns %s user groups.', len(c.user.user_groups)) % len(c.user.user_groups)} + ${_ungettext('This user owns %s user group.', 'This user owns %s user groups.', len(c.user.user_groups)) % len(c.user.user_groups)} %if len(c.user.user_groups) > 0: diff --git a/rhodecode/templates/base/perms_summary.mako b/rhodecode/templates/base/perms_summary.mako --- a/rhodecode/templates/base/perms_summary.mako +++ b/rhodecode/templates/base/perms_summary.mako @@ -146,7 +146,7 @@ %if actions: %if section == 'repositories': - ${_('edit')} + ${_('edit')} %elif section == 'repositories_groups': ${_('edit')} %elif section == 'user_groups': diff --git a/rhodecode/templates/changeset/changeset.mako b/rhodecode/templates/changeset/changeset.mako --- a/rhodecode/templates/changeset/changeset.mako +++ b/rhodecode/templates/changeset/changeset.mako @@ -163,14 +163,14 @@
%if c.comments: - ${ungettext("%d Commit comment", "%d Commit comments", len(c.comments)) % len(c.comments)}, + ${_ungettext("%d Commit comment", "%d Commit comments", len(c.comments)) % len(c.comments)}, %else: - ${ungettext("%d Commit comment", "%d Commit comments", len(c.comments)) % len(c.comments)} + ${_ungettext("%d Commit comment", "%d Commit comments", len(c.comments)) % len(c.comments)} %endif %if c.inline_cnt: - ${ungettext("%d Inline Comment", "%d Inline Comments", c.inline_cnt) % c.inline_cnt} + ${_ungettext("%d Inline Comment", "%d Inline Comments", c.inline_cnt) % c.inline_cnt} %else: - ${ungettext("%d Inline Comment", "%d Inline Comments", c.inline_cnt) % c.inline_cnt} + ${_ungettext("%d Inline Comment", "%d Inline Comments", c.inline_cnt) % c.inline_cnt} %endif
diff --git a/rhodecode/templates/changeset/changeset_range.mako b/rhodecode/templates/changeset/changeset_range.mako --- a/rhodecode/templates/changeset/changeset_range.mako +++ b/rhodecode/templates/changeset/changeset_range.mako @@ -6,7 +6,7 @@ r${c.commit_ranges[0].revision}:${h.short_id(c.commit_ranges[0].raw_id)} ... r${c.commit_ranges[-1].revision}:${h.short_id(c.commit_ranges[-1].raw_id)} - ${ungettext('(%s commit)','(%s commits)', len(c.commit_ranges)) % len(c.commit_ranges)} + ${_ungettext('(%s commit)','(%s commits)', len(c.commit_ranges)) % len(c.commit_ranges)} %if c.rhodecode_name: · ${h.branding(c.rhodecode_name)} %endif @@ -17,7 +17,7 @@ r${c.commit_ranges[0].revision}:${h.short_id(c.commit_ranges[0].raw_id)} ... r${c.commit_ranges[-1].revision}:${h.short_id(c.commit_ranges[-1].raw_id)} - ${ungettext('(%s commit)','(%s commits)', len(c.commit_ranges)) % len(c.commit_ranges)} + ${_ungettext('(%s commit)','(%s commits)', len(c.commit_ranges)) % len(c.commit_ranges)} <%def name="menu_bar_nav()"> @@ -96,13 +96,13 @@ class="btn" href="#" onclick="$('.compare_select').show();$('.compare_select_hidden').hide(); return false"> - ${ungettext('Expand %s commit','Expand %s commits', len(c.commit_ranges)) % len(c.commit_ranges)} + ${_ungettext('Expand %s commit','Expand %s commits', len(c.commit_ranges)) % len(c.commit_ranges)} - ${ungettext('Collapse %s commit','Collapse %s commits', len(c.commit_ranges)) % len(c.commit_ranges)} + ${_ungettext('Collapse %s commit','Collapse %s commits', len(c.commit_ranges)) % len(c.commit_ranges)} diff --git a/rhodecode/templates/changeset/diff_block.mako b/rhodecode/templates/changeset/diff_block.mako --- a/rhodecode/templates/changeset/diff_block.mako +++ b/rhodecode/templates/changeset/diff_block.mako @@ -55,9 +55,9 @@ <%def name="diff_summary_text(changed_files, lines_added, lines_deleted, limited_diff=False)"> % if limited_diff: - ${ungettext('%(num)s file changed', '%(num)s files changed', changed_files) % {'num': changed_files}} + ${_ungettext('%(num)s file changed', '%(num)s files changed', changed_files) % {'num': changed_files}} % else: - ${ungettext('%(num)s file changed: %(linesadd)s inserted, ''%(linesdel)s deleted', + ${_ungettext('%(num)s file changed: %(linesadd)s inserted, ''%(linesdel)s deleted', '%(num)s files changed: %(linesadd)s inserted, %(linesdel)s deleted', changed_files) % {'num': changed_files, 'linesadd': lines_added, 'linesdel': lines_deleted}} %endif diff --git a/rhodecode/templates/codeblocks/diffs.mako b/rhodecode/templates/codeblocks/diffs.mako --- a/rhodecode/templates/codeblocks/diffs.mako +++ b/rhodecode/templates/codeblocks/diffs.mako @@ -127,10 +127,10 @@ collapse_all = len(diffset.files) > coll %if diffset.limited_diff: ${_('The requested commit is too big and content was truncated.')} - ${ungettext('%(num)s file changed.', '%(num)s files changed.', diffset.changed_files) % {'num': diffset.changed_files}} + ${_ungettext('%(num)s file changed.', '%(num)s files changed.', diffset.changed_files) % {'num': diffset.changed_files}} ${_('Show full diff')} %else: - ${ungettext('%(num)s file changed: %(linesadd)s inserted, ''%(linesdel)s deleted', + ${_ungettext('%(num)s file changed: %(linesadd)s inserted, ''%(linesdel)s deleted', '%(num)s files changed: %(linesadd)s inserted, %(linesdel)s deleted', diffset.changed_files) % {'num': diffset.changed_files, 'linesadd': diffset.lines_added, 'linesdel': diffset.lines_deleted}} %endif diff --git a/rhodecode/templates/compare/compare_commits.mako b/rhodecode/templates/compare/compare_commits.mako --- a/rhodecode/templates/compare/compare_commits.mako +++ b/rhodecode/templates/compare/compare_commits.mako @@ -65,8 +65,8 @@ %endfor
- ${ungettext('%s commit hidden','%s commits hidden', len(c.commit_ranges)) % len(c.commit_ranges)}, - ${ungettext('show it','show them', len(c.commit_ranges))} + ${_ungettext('%s commit hidden','%s commits hidden', len(c.commit_ranges)) % len(c.commit_ranges)}, + ${_ungettext('show it','show them', len(c.commit_ranges))}
${_('Source')}${base.tag_button(pull_request.source_ref_parts.name)} ${h.literal(_('%(source_ref_type)s of %(source_repo_url)s') % data)}
${_('Target')}${base.tag_button(pull_request.target_ref_parts.name)} ${h.literal(_('%(target_ref_type)s of %(target_repo_url)s') % data)}
${_('Description')}${pull_request.description}
${ungettext('%(num)s Commit', '%(num)s Commits', len(pull_request_commits)) % {'num': len(pull_request_commits)}}
${_ungettext('%(num)s Commit', '%(num)s Commits', len(pull_request_commits)) % {'num': len(pull_request_commits)}}
    % for commit_id, message in pull_request_commits:
  1. ${h.short_id(commit_id)}
    diff --git a/rhodecode/templates/pullrequests/pullrequest.mako b/rhodecode/templates/pullrequests/pullrequest.mako --- a/rhodecode/templates/pullrequests/pullrequest.mako +++ b/rhodecode/templates/pullrequests/pullrequest.mako @@ -353,9 +353,9 @@ var msg = ''; if (commitElements.length === 1) { - msg = "${ungettext('This pull request will consist of __COMMITS__ commit.', 'This pull request will consist of __COMMITS__ commits.', 1)}"; + msg = "${_ungettext('This pull request will consist of __COMMITS__ commit.', 'This pull request will consist of __COMMITS__ commits.', 1)}"; } else { - msg = "${ungettext('This pull request will consist of __COMMITS__ commit.', 'This pull request will consist of __COMMITS__ commits.', 2)}"; + msg = "${_ungettext('This pull request will consist of __COMMITS__ commit.', 'This pull request will consist of __COMMITS__ commits.', 2)}"; } msg += ' ${_('Show detailed compare.')}'.format(url); diff --git a/rhodecode/templates/pullrequests/pullrequest_show.mako b/rhodecode/templates/pullrequests/pullrequest_show.mako --- a/rhodecode/templates/pullrequests/pullrequest_show.mako +++ b/rhodecode/templates/pullrequests/pullrequest_show.mako @@ -154,7 +154,7 @@ %endif ${h.commit_status_lbl(c.pull_request_review_status)} - - ${ungettext('calculated based on %s reviewer vote', 'calculated based on %s reviewers votes', len(c.pull_request_reviewers)) % len(c.pull_request_reviewers)} + - ${_ungettext('calculated based on %s reviewer vote', 'calculated based on %s reviewers votes', len(c.pull_request_reviewers)) % len(c.pull_request_reviewers)} %endif @@ -183,9 +183,9 @@ <% outdated_comm_count_ver = len(c.inline_versions[c.at_version_num]['outdated']) %> <% general_outdated_comm_count_ver = len(c.comment_versions[c.at_version_num]['outdated']) %> - ${ungettext('{} version available for this pull request, show it.', '{} versions available for this pull request, show them.', len(c.versions)).format(len(c.versions))} + ${_ungettext('{} version available for this pull request, show it.', '{} versions available for this pull request, show them.', len(c.versions)).format(len(c.versions))} ## SHOW ALL VERSIONS OF PR @@ -443,13 +443,13 @@ class="btn" href="#" onclick="$('.compare_select').show();$('.compare_select_hidden').hide(); return false"> - ${ungettext('Expand %s commit','Expand %s commits', len(c.commit_ranges)) % len(c.commit_ranges)} + ${_ungettext('Expand %s commit','Expand %s commits', len(c.commit_ranges)) % len(c.commit_ranges)} - ${ungettext('Collapse %s commit','Collapse %s commits', len(c.commit_ranges)) % len(c.commit_ranges)} + ${_ungettext('Collapse %s commit','Collapse %s commits', len(c.commit_ranges)) % len(c.commit_ranges)} diff --git a/rhodecode/templates/summary/components.mako b/rhodecode/templates/summary/components.mako --- a/rhodecode/templates/summary/components.mako +++ b/rhodecode/templates/summary/components.mako @@ -154,7 +154,7 @@ ${_('Statistics are disabled for this repository')} % if h.HasPermissionAll('hg.admin')('enable stats on from summary'): - , ${h.link_to(_('enable statistics'),h.route_path('edit_repo',repo_name=c.repo_name, anchor='repo_enable_statistics'))} + , ${h.link_to(_('enable statistics'),h.route_path('edit_repo',repo_name=c.repo_name, _anchor='repo_enable_statistics'))} % endif % endif @@ -178,7 +178,7 @@ ${_('Downloads are disabled for this repository')} % if h.HasPermissionAll('hg.admin')('enable downloads on from summary'): - , ${h.link_to(_('enable downloads'),h.route_path('edit_repo',repo_name=c.repo_name, anchor='repo_enable_downloads'))} + , ${h.link_to(_('enable downloads'),h.route_path('edit_repo',repo_name=c.repo_name, _anchor='repo_enable_downloads'))} % endif % else: