##// END OF EJS Templates
translations: moved methods from new request subscriber to actual methods of custom class....
super-admin -
r4842:f24aa2bf default
parent child Browse files
Show More
@@ -330,7 +330,7 b' def create_repo_fork(form_data, cur_user'
330 return True
330 return True
331
331
332
332
333 @async_task(ignore_result=True)
333 @async_task(ignore_result=True, base=RequestContextTask)
334 def repo_maintenance(repoid):
334 def repo_maintenance(repoid):
335 from rhodecode.lib import repo_maintenance as repo_maintenance_lib
335 from rhodecode.lib import repo_maintenance as repo_maintenance_lib
336 log = get_logger(repo_maintenance)
336 log = get_logger(repo_maintenance)
@@ -345,7 +345,7 b' def repo_maintenance(repoid):'
345 log.debug('Repo `%s` not found or without a clone_url', repoid)
345 log.debug('Repo `%s` not found or without a clone_url', repoid)
346
346
347
347
348 @async_task(ignore_result=True)
348 @async_task(ignore_result=True, base=RequestContextTask)
349 def check_for_update(send_email_notification=True, email_recipients=None):
349 def check_for_update(send_email_notification=True, email_recipients=None):
350 from rhodecode.model.update import UpdateModel
350 from rhodecode.model.update import UpdateModel
351 from rhodecode.model.notification import EmailNotificationModel
351 from rhodecode.model.notification import EmailNotificationModel
@@ -380,14 +380,8 b' def check_for_update(send_email_notifica'
380 email_body_plaintext, email_body)
380 email_body_plaintext, email_body)
381
381
382 except Exception:
382 except Exception:
383 pass
383 log.exception('Failed to check for update')
384
384 raise
385
386 @async_task(ignore_result=False)
387 def beat_check(*args, **kwargs):
388 log = get_logger(beat_check)
389 log.info('%r: Got args: %r and kwargs %r', beat_check, args, kwargs)
390 return time.time()
391
385
392
386
393 def sync_last_update_for_objects(*args, **kwargs):
387 def sync_last_update_for_objects(*args, **kwargs):
@@ -409,6 +403,13 b' def sync_last_update_for_objects(*args, '
409 repo_gr.update_commit_cache()
403 repo_gr.update_commit_cache()
410
404
411
405
412 @async_task(ignore_result=True)
406 @async_task(ignore_result=True, base=RequestContextTask)
413 def sync_last_update(*args, **kwargs):
407 def sync_last_update(*args, **kwargs):
414 sync_last_update_for_objects(*args, **kwargs)
408 sync_last_update_for_objects(*args, **kwargs)
409
410
411 @async_task(ignore_result=False)
412 def beat_check(*args, **kwargs):
413 log = get_logger(beat_check)
414 log.info('%r: Got args: %r and kwargs %r', beat_check, args, kwargs)
415 return time.time()
@@ -21,6 +21,7 b''
21 from uuid import uuid4
21 from uuid import uuid4
22 from pyramid.decorator import reify
22 from pyramid.decorator import reify
23 from pyramid.request import Request as _Request
23 from pyramid.request import Request as _Request
24 from rhodecode.translation import _ as tsf
24
25
25
26
26 class Request(_Request):
27 class Request(_Request):
@@ -36,3 +37,14 b' class Request(_Request):'
36
37
37 def req_id_records_init(self):
38 def req_id_records_init(self):
38 self._req_id_bucket = list()
39 self._req_id_bucket = list()
40
41 def plularize(self, *args, **kwargs):
42 return self.localizer.pluralize(*args, **kwargs)
43
44 def translate(self, *args, **kwargs):
45 localizer = self.localizer
46
47 def auto_translate(*_args, **_kwargs):
48 return localizer.translate(tsf(*_args, **_kwargs))
49
50 return auto_translate(*args, **kwargs)
@@ -427,11 +427,11 b' class EmailNotificationModel(BaseModel):'
427 renders template for email, and returns a tuple of
427 renders template for email, and returns a tuple of
428 (subject, email_headers, email_html_body, email_plaintext_body)
428 (subject, email_headers, email_html_body, email_plaintext_body)
429 """
429 """
430 request = get_current_request()
431
430 # translator and helpers inject
432 # translator and helpers inject
431 _kwargs = self._update_kwargs_for_render(kwargs)
433 _kwargs = self._update_kwargs_for_render(kwargs)
432 request = get_current_request()
433 email_template = self.get_renderer(type_, request=request)
434 email_template = self.get_renderer(type_, request=request)
434
435 subject = email_template.render('subject', **_kwargs)
435 subject = email_template.render('subject', **_kwargs)
436
436
437 try:
437 try:
@@ -36,9 +36,7 b' from pyramid.settings import asbool'
36 from pyramid.path import AssetResolver
36 from pyramid.path import AssetResolver
37 from threading import Thread
37 from threading import Thread
38
38
39 from rhodecode.translation import _ as tsf
40 from rhodecode.config.jsroutes import generate_jsroutes_content
39 from rhodecode.config.jsroutes import generate_jsroutes_content
41 from rhodecode.lib import auth
42 from rhodecode.lib.base import get_auth_user
40 from rhodecode.lib.base import get_auth_user
43
41
44 import rhodecode
42 import rhodecode
@@ -60,17 +58,6 b' def add_renderer_globals(event):'
60 event['h'] = helpers
58 event['h'] = helpers
61
59
62
60
63 def add_localizer(event):
64 request = event.request
65 localizer = request.localizer
66
67 def auto_translate(*args, **kwargs):
68 return localizer.translate(tsf(*args, **kwargs))
69
70 request.translate = auto_translate
71 request.plularize = localizer.pluralize
72
73
74 def set_user_lang(event):
61 def set_user_lang(event):
75 request = event.request
62 request = event.request
76 cur_user = getattr(request, 'user', None)
63 cur_user = getattr(request, 'user', None)
@@ -110,8 +110,6 b' def includeme(config):'
110 'pyramid.events.BeforeRender')
110 'pyramid.events.BeforeRender')
111 config.add_subscriber('rhodecode.subscribers.set_user_lang',
111 config.add_subscriber('rhodecode.subscribers.set_user_lang',
112 'pyramid.events.NewRequest')
112 'pyramid.events.NewRequest')
113 config.add_subscriber('rhodecode.subscribers.add_localizer',
114 'pyramid.events.NewRequest')
115 config.add_subscriber('rhodecode.subscribers.reset_log_bucket',
113 config.add_subscriber('rhodecode.subscribers.reset_log_bucket',
116 'pyramid.events.NewRequest')
114 'pyramid.events.NewRequest')
117 config.add_subscriber('rhodecode.subscribers.add_request_user_context',
115 config.add_subscriber('rhodecode.subscribers.add_request_user_context',
General Comments 0
You need to be logged in to leave comments. Login now