瀏覽代碼

Closes #173: Hack: Charger le context dans les thread webdav

Bastien Sevajol (Algoo) 8 年之前
父節點
當前提交
80d3d38c3b
共有 2 個文件被更改,包括 28 次插入0 次删除
  1. 10 0
      tracim/tracim/lib/notifications.py
  2. 18 0
      tracim/tracim/lib/utils.py

+ 10 - 0
tracim/tracim/lib/notifications.py 查看文件

4
 from email.mime.text import MIMEText
4
 from email.mime.text import MIMEText
5
 
5
 
6
 import lxml
6
 import lxml
7
+import tg
7
 from lxml.html.diff import htmldiff
8
 from lxml.html.diff import htmldiff
8
 
9
 
9
 from mako.template import Template
10
 from mako.template import Template
10
 
11
 
11
 from tg.i18n import lazy_ugettext as l_
12
 from tg.i18n import lazy_ugettext as l_
12
 from tg.i18n import ugettext as _
13
 from tg.i18n import ugettext as _
14
+from tg.support.registry import StackedObjectProxy
13
 
15
 
14
 from tracim.lib.base import logger
16
 from tracim.lib.base import logger
15
 from tracim.lib.email import SmtpConfiguration
17
 from tracim.lib.email import SmtpConfiguration
16
 from tracim.lib.email import EmailSender
18
 from tracim.lib.email import EmailSender
17
 from tracim.lib.user import UserApi
19
 from tracim.lib.user import UserApi
20
+from tracim.lib.utils import initialize_app
18
 from tracim.lib.workspace import WorkspaceApi
21
 from tracim.lib.workspace import WorkspaceApi
19
 
22
 
20
 from tracim.model.serializers import Context
23
 from tracim.model.serializers import Context
225
         user = UserApi(None).get_one(event_actor_id)
228
         user = UserApi(None).get_one(event_actor_id)
226
         logger.debug(self, 'Content: {}'.format(event_content_id))
229
         logger.debug(self, 'Content: {}'.format(event_content_id))
227
 
230
 
231
+        # HACK, view https://github.com/tracim/tracim/issues/173
232
+        try:
233
+            context = StackedObjectProxy(name="context")
234
+            context.translator
235
+        except TypeError:
236
+            initialize_app(tg.config.get('__file__'))
237
+
228
         content = ContentApi(user, show_archived=True, show_deleted=True).get_one(event_content_id, ContentType.Any) # TODO - use a system user instead of the user that has triggered the event
238
         content = ContentApi(user, show_archived=True, show_deleted=True).get_one(event_content_id, ContentType.Any) # TODO - use a system user instead of the user that has triggered the event
229
         main_content = content.parent if content.type==ContentType.Comment else content
239
         main_content = content.parent if content.type==ContentType.Comment else content
230
         notifiable_roles = WorkspaceApi(user).get_notifiable_roles(content.workspace)
240
         notifiable_roles = WorkspaceApi(user).get_notifiable_roles(content.workspace)

+ 18 - 0
tracim/tracim/lib/utils.py 查看文件

145
     if string == '0':
145
     if string == '0':
146
         return False
146
         return False
147
     return bool(string)
147
     return bool(string)
148
+
149
+
150
+def initialize_app(config_file_name: str='development.ini') -> None:
151
+    from webtest import TestApp
152
+    from paste.deploy import loadapp
153
+    import os
154
+
155
+    wsgi_app = loadapp(
156
+        'config:{}'.format(config_file_name),
157
+        relative_to=os.getcwd(),
158
+        global_conf={
159
+            'disable_daemons': 'true',
160
+        }
161
+    )
162
+    test_app = TestApp(wsgi_app)
163
+
164
+    # Make available the tg.request and other global variables
165
+    tresponse = test_app.get('/_test_vars')