##// END OF EJS Templates
core: dropped deprecated PartialRenderer that depends on pylons.
marcink -
r2310:d2e9d950 default
parent child Browse files
Show More
@@ -859,78 +859,6 b' class BasePasterCommand(Command):'
859 859 initialize_database(config)
860 860
861 861
862 class PartialRenderer(object):
863 """
864 Partial renderer used to render chunks of html used in datagrids
865 use like::
866
867 _render = PartialRenderer('data_table/_dt_elements.mako')
868 _render('quick_menu', args, kwargs)
869 PartialRenderer.h,
870 c,
871 _,
872 ungettext
873 are the template stuff initialized inside and can be re-used later
874
875 :param tmpl_name: template path relate to /templates/ dir
876 """
877
878 def __init__(self, tmpl_name):
879 import rhodecode
880 from pylons import request, tmpl_context as c
881 from pylons.i18n.translation import _, ungettext
882 from rhodecode.lib import helpers as h
883
884 self.tmpl_name = tmpl_name
885 self.rhodecode = rhodecode
886 self.c = c
887 self._ = _
888 self.ungettext = ungettext
889 self.h = h
890 self.request = request
891
892 def _mako_lookup(self):
893 _tmpl_lookup = self.rhodecode.CONFIG['pylons.app_globals'].mako_lookup
894 return _tmpl_lookup.get_template(self.tmpl_name)
895
896 def _update_kwargs_for_render(self, kwargs):
897 """
898 Inject params required for Mako rendering
899 """
900 _kwargs = {
901 '_': self._,
902 'h': self.h,
903 'c': self.c,
904 'request': self.request,
905 '_ungettext': self.ungettext,
906 }
907 _kwargs.update(kwargs)
908 return _kwargs
909
910 def _render_with_exc(self, render_func, args, kwargs):
911 try:
912 return render_func.render(*args, **kwargs)
913 except:
914 log.error(exceptions.text_error_template().render())
915 raise
916
917 def _get_template(self, template_obj, def_name):
918 if def_name:
919 tmpl = template_obj.get_def(def_name)
920 else:
921 tmpl = template_obj
922 return tmpl
923
924 def render(self, def_name, *args, **kwargs):
925 lookup_obj = self._mako_lookup()
926 tmpl = self._get_template(lookup_obj, def_name=def_name)
927 kwargs = self._update_kwargs_for_render(kwargs)
928 return self._render_with_exc(tmpl, args, kwargs)
929
930 def __call__(self, tmpl, *args, **kwargs):
931 return self.render(tmpl, *args, **kwargs)
932
933
934 862 def password_changed(auth_user, session):
935 863 # Never report password change in case of default user or anonymous user.
936 864 if auth_user.username == User.DEFAULT_USER or auth_user.user_id is None:
@@ -26,11 +26,11 b' Model for notifications'
26 26 import logging
27 27 import traceback
28 28
29 from pyramid.threadlocal import get_current_request
29 30 from sqlalchemy.sql.expression import false, true
30 31
31 32 import rhodecode
32 33 from rhodecode.lib import helpers as h
33 from rhodecode.lib.utils import PartialRenderer
34 34 from rhodecode.model import BaseModel
35 35 from rhodecode.model.db import Notification, User, UserNotification
36 36 from rhodecode.model.meta import Session
@@ -343,9 +343,9 b' class EmailNotificationModel(BaseModel):'
343 343 def whitespace_filter(self, text):
344 344 return text.replace('\n', '').replace('\t', '')
345 345
346 def get_renderer(self, type_):
346 def get_renderer(self, type_, request):
347 347 template_name = self.email_types[type_]
348 return PartialRenderer(template_name)
348 return request.get_partial_renderer(template_name)
349 349
350 350 def render_email(self, type_, **kwargs):
351 351 """
@@ -354,8 +354,8 b' class EmailNotificationModel(BaseModel):'
354 354 """
355 355 # translator and helpers inject
356 356 _kwargs = self._update_kwargs_for_render(kwargs)
357
358 email_template = self.get_renderer(type_)
357 request = get_current_request()
358 email_template = self.get_renderer(type_, request=request)
359 359
360 360 subject = email_template.render('subject', **_kwargs)
361 361
@@ -1,16 +1,35 b''
1 1 import collections
2 # -*- coding: utf-8 -*-
3
4 # Copyright (C) 2010-2017 RhodeCode GmbH
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License, version 3
8 # (only), as published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #
18 # This program is dual-licensed. If you wish to learn more about the
19 # RhodeCode Enterprise Edition, including its added features, Support services,
20 # and proprietary license terms, please see https://rhodecode.com/licenses/
2 21
3 22 import pytest
4 23
5 from rhodecode.lib.utils import PartialRenderer
24 from rhodecode.lib.partial_renderer import PyramidPartialRenderer
6 25 from rhodecode.lib.utils2 import AttributeDict
7 26 from rhodecode.model.notification import EmailNotificationModel
8 27
9 28
10 def test_get_template_obj(app):
29 def test_get_template_obj(app, request_stub):
11 30 template = EmailNotificationModel().get_renderer(
12 EmailNotificationModel.TYPE_TEST)
13 assert isinstance(template, PartialRenderer)
31 EmailNotificationModel.TYPE_TEST, request_stub)
32 assert isinstance(template, PyramidPartialRenderer)
14 33
15 34
16 35 def test_render_email(app, http_host_only_stub):
General Comments 0
You need to be logged in to leave comments. Login now