@@ -26,7 +26,7 @@ def get_unique_template_id():
2626 Get an unique id for a template as a string.
2727 :return: an unique id for a template.
2828 """
29- return uuid .uuid4 ().urn [9 :].replace ("-" , "" )
29+ return uuid .uuid4 ().urn [9 :].replace ('-' , '' )
3030
3131
3232def slugify_template_path (template_path ):
@@ -37,7 +37,7 @@ def slugify_template_path(template_path):
3737 :param template_path: string with the template path.
3838 :return: slug of the template path.
3939 """
40- return slugify (template_path .replace ("/" , "_" ).replace ("-" , "_" ))
40+ return slugify (template_path .replace ('/' , '_' ).replace ('-' , '_' ))
4141
4242
4343# Async include template tag.
@@ -52,44 +52,44 @@ def async_include(context, template_path, *args, **kwargs):
5252 slugified_template_path = slugify_template_path (template_path )
5353
5454 # Unique block id (uniqueness based on UUID)
55- block_id = " {0}__{1}" .format (
55+ block_id = ' {0}__{1}' .format (
5656 slugified_template_path , get_unique_template_id ()
5757 )
5858
5959 # Give the possibility to customize the HTML tag
60- html__tag = kwargs .pop (" html__tag" , " div" )
60+ html__tag = kwargs .pop (' html__tag' , ' div' )
6161
6262 # HTML tag class
63- html__tag__class = kwargs .pop (" html__tag__class" , slugified_template_path )
63+ html__tag__class = kwargs .pop (' html__tag__class' , slugified_template_path )
6464
6565 # Shall we show a spinner?
66- spinner__visible = kwargs .pop (" spinner__visible" , True )
66+ spinner__visible = kwargs .pop (' spinner__visible' , True )
6767
6868 # Spinner template path
6969 spinner__template_path = kwargs .pop (
70- " spinner__template_path" , " async_include/spinner.html"
70+ ' spinner__template_path' , ' async_include/spinner.html'
7171 )
7272
7373 # Recurrent requests
74- request__frequency = kwargs .pop (" request__frequency" , " once" )
74+ request__frequency = kwargs .pop (' request__frequency' , ' once' )
7575
7676 replacements = {
77- " template_path" : template_path ,
78- " block_id" : block_id ,
79- " html__tag" : html__tag ,
80- " html__tag__class" : html__tag__class ,
81- " spinner__visible" : spinner__visible ,
82- " spinner__template_path" : spinner__template_path ,
83- " request__frequency" : request__frequency ,
84- " context" : {}
77+ ' template_path' : template_path ,
78+ ' block_id' : block_id ,
79+ ' html__tag' : html__tag ,
80+ ' html__tag__class' : html__tag__class ,
81+ ' spinner__visible' : spinner__visible ,
82+ ' spinner__template_path' : spinner__template_path ,
83+ ' request__frequency' : request__frequency ,
84+ ' context' : {}
8585 }
8686
8787 for context_object_name , context_object in kwargs .items ():
8888 # For each passed parameter,
8989 # it can be a model object or a safe value (string or number)
9090 is_model_object = (
91- hasattr (context_object , "id" ) and
92- hasattr (context_object .__class__ , " __name__" )
91+ hasattr (context_object , 'id' ) and
92+ hasattr (context_object .__class__ , ' __name__' )
9393 )
9494
9595 # We store a reference of the model object based on its model name,
@@ -101,15 +101,15 @@ def async_include(context, template_path, *args, **kwargs):
101101 app_name = (
102102 ContentType .objects .get_for_model (context_object ).app_label
103103 )
104- model_object_as_str = " {0}-{1}-{2}" .format (
104+ model_object_as_str = ' {0}-{1}-{2}' .format (
105105 app_name , model_name , object_id
106106 )
107- replacements [" context" ][context_object_name ] = {
108- " type" : " model" ,
109- "id" : object_id ,
110- " app_name" : app_name ,
111- " model" : model_name ,
112- " __checksum__" : checksum .make (model_object_as_str )
107+ replacements [' context' ][context_object_name ] = {
108+ ' type' : ' model' ,
109+ 'id' : object_id ,
110+ ' app_name' : app_name ,
111+ ' model' : model_name ,
112+ ' __checksum__' : checksum .make (model_object_as_str )
113113 }
114114
115115 elif type (context_object ) == QuerySet :
@@ -123,32 +123,32 @@ def async_include(context, template_path, *args, **kwargs):
123123 key = settings .SECRET_KEY [:16 ], data = sql_query
124124 )
125125
126- replacements [" context" ][context_object_name ] = {
127- " type" : " QuerySet" ,
128- " query" : encrypted_sql .decode (" latin-1" ),
129- " params" : params ,
130- " nonce" : nonce .decode (" latin-1" ),
131- " tag" : tag .decode (" latin-1" ),
132- " app_name" : app_name ,
133- " model" : model_name ,
126+ replacements [' context' ][context_object_name ] = {
127+ ' type' : ' QuerySet' ,
128+ ' query' : encrypted_sql .decode (' latin-1' ),
129+ ' params' : params ,
130+ ' nonce' : nonce .decode (' latin-1' ),
131+ ' tag' : tag .decode (' latin-1' ),
132+ ' app_name' : app_name ,
133+ ' model' : model_name ,
134134 }
135135
136- # Safe values are sent " as is" to the view
136+ # Safe values are sent as is to the view
137137 # that will render the template
138138 else :
139- context_object_as_str = " {0}" .format (context_object )
140- replacements [" context" ][context_object_name ] = {
141- " type" : " safe_value" ,
142- " value" : context_object ,
143- " value_as_str" : context_object_as_str ,
144- " __checksum__" : checksum .make (context_object_as_str )
139+ context_object_as_str = ' {0}' .format (context_object )
140+ replacements [' context' ][context_object_name ] = {
141+ ' type' : ' safe_value' ,
142+ ' value' : context_object ,
143+ ' value_as_str' : context_object_as_str ,
144+ ' __checksum__' : checksum .make (context_object_as_str )
145145 }
146146
147147 # Serialization of context that will be sent
148- replacements [" context" ] = jsonpickle .dumps (replacements [" context" ])
148+ replacements [' context' ] = jsonpickle .dumps (replacements [' context' ])
149149
150150 # Pass language code
151- replacements [" language_code" ] = get_language ()
151+ replacements [' language_code' ] = get_language ()
152152
153153 # Render the template of this template tag
154154 try :
0 commit comments