File tree 4 files changed +52
-9
lines changed
4 files changed +52
-9
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ class ReactConfig(AppConfig):
7
7
name = 'react'
8
8
9
9
def ready (self ):
10
+ react .conf .settings ._PROXY_DJANGO_SETTINGS = True
10
11
react .conf .settings .configure (
11
12
** getattr (settings , 'REACT' , {})
12
- )
13
+ )
Original file line number Diff line number Diff line change 1
- from optional_django import conf
1
+ class Conf (object ):
2
+ _render_url = 'http://127.0.0.1:9009/render'
3
+ _render = True
4
+ _PROXY_DJANGO_SETTINGS = False
2
5
6
+ @property
7
+ def RENDER_URL (self ):
8
+ if not self ._PROXY_DJANGO_SETTINGS :
9
+ return self ._render_url
3
10
4
- class Conf (conf .Conf ):
5
- RENDER_URL = 'http://127.0.0.1:9009/render'
6
- RENDER = True
11
+ from django .conf import settings
7
12
8
- settings = Conf ()
13
+ if hasattr (settings , 'REACT' ):
14
+ return settings .REACT .get ('RENDER_URL' , self ._render_url )
15
+
16
+ return self ._render_url
17
+
18
+ @property
19
+ def RENDER (self ):
20
+ if not self ._PROXY_DJANGO_SETTINGS :
21
+ return self ._render
22
+
23
+ from django .conf import settings
24
+
25
+ if hasattr (settings , 'REACT' ):
26
+ return settings .REACT .get ('RENDER' , self ._render )
27
+
28
+ return self ._render
29
+
30
+ def configure (self , RENDER_URL = None , RENDER = None ):
31
+ if RENDER_URL is not None :
32
+ self ._render_url = RENDER_URL
33
+ if RENDER is not None :
34
+ self ._render = RENDER
35
+
36
+ settings = Conf ()
Original file line number Diff line number Diff line change 14
14
TEST_ROOT = os .path .dirname (__file__ )
15
15
COMPONENT_ROOT = os .path .join (TEST_ROOT , 'components' )
16
16
17
+ DATABASES = {
18
+ 'default' : {
19
+ 'ENGINE' : 'django.db.backends.sqlite3' ,
20
+ 'NAME' : 'mydatabase' ,
21
+ }
22
+ }
23
+
17
24
18
25
class Components (object ):
19
26
HELLO_WORLD_JS = os .path .join (COMPONENT_ROOT , 'HelloWorld.js' )
Original file line number Diff line number Diff line change 1
1
import json
2
2
import datetime
3
- import unittest
3
+ from django . test import TestCase
4
4
from django .utils import timezone
5
5
from optional_django .env import DJANGO_CONFIGURED
6
6
from react .render import render_component
7
+ from react import conf
7
8
from .settings import Components
8
9
9
10
10
- class TestDjangoIntegration (unittest . TestCase ):
11
+ class TestDjangoIntegration (TestCase ):
11
12
__test__ = DJANGO_CONFIGURED
12
13
13
14
def test_can_serialize_datetime_values_in_props (self ):
@@ -33,4 +34,10 @@ def test_can_serialize_datetime_values_in_props(self):
33
34
34
35
def test_relative_paths_are_resolved_via_the_static_file_finder (self ):
35
36
component = render_component (Components .DJANGO_REL_PATH , to_static_markup = True )
36
- self .assertEqual (str (component ), '<span>You found me.</span>' )
37
+ self .assertEqual (str (component ), '<span>You found me.</span>' )
38
+
39
+ def test_django_settings_are_proxied (self ):
40
+ self .assertEqual (conf .settings .RENDER , True )
41
+ with self .settings (REACT = {'RENDER' : False }):
42
+ self .assertEqual (conf .settings .RENDER , False )
43
+
You can’t perform that action at this time.
0 commit comments