@@ -149,8 +149,7 @@ def configure_enforcer_auto_save_and_load(cls):
149149 Returns:
150150 None
151151 """
152- auto_load_policy_interval = getattr (
153- settings , "CASBIN_AUTO_LOAD_POLICY_INTERVAL" , 0 )
152+ auto_load_policy_interval = getattr (settings , "CASBIN_AUTO_LOAD_POLICY_INTERVAL" , 0 )
154153 auto_save_policy = getattr (settings , "CASBIN_AUTO_SAVE_POLICY" , True )
155154
156155 # TODO: remove autoload in favor of cache invalidation?
@@ -166,7 +165,7 @@ def load_policy_if_needed(cls):
166165 """Load policy if the last load timestamp indicates it's needed.
167166
168167 This method checks if the policy needs to be reloaded comparing
169- the last load timestamp with the last modified timestamp in cache
168+ the last load timestamp with the last modified timestamp in cache
170169 and reloads it if necessary.
171170
172171 Returns:
@@ -179,13 +178,9 @@ def load_policy_if_needed(cls):
179178 if last_modified_timestamp is None :
180179 # No timestamp in cache; initialize it
181180 cache .set (cls .CACHE_KEY , current_timestamp , None )
182- logger .info (
183- f">>>> Initialized policy last modified timestamp in cache. { current_timestamp } " )
181+ logger .info (f">>>> Initialized policy last modified timestamp in cache. { current_timestamp } " )
184182
185- if (
186- cls ._last_policy_load_timestamp is None or
187- last_modified_timestamp > cls ._last_policy_load_timestamp
188- ):
183+ if cls ._last_policy_load_timestamp is None or last_modified_timestamp > cls ._last_policy_load_timestamp :
189184 # Policy has been modified since last load; reload it
190185 cls ._enforcer .load_policy ()
191186 cls ._last_policy_load_timestamp = current_timestamp
@@ -263,13 +258,11 @@ def _initialize_enforcer(cls) -> SyncedEnforcer:
263258 # issues when the app is not fully loaded (e.g., while pulling translations, etc.).
264259 initialize_enforcer (db_alias )
265260 except Exception as e :
266- logger .error (
267- f"Failed to initialize Casbin enforcer with DB alias '{ db_alias } ': { e } " )
261+ logger .error (f"Failed to initialize Casbin enforcer with DB alias '{ db_alias } ': { e } " )
268262 raise
269263
270264 adapter = ExtendedAdapter ()
271265 enforcer = SyncedEnforcer (settings .CASBIN_MODEL , adapter )
272- enforcer .add_function ("is_staff_or_superuser" ,
273- is_admin_or_superuser_check )
266+ enforcer .add_function ("is_staff_or_superuser" , is_admin_or_superuser_check )
274267
275268 return enforcer
0 commit comments