Files
goodtimes/accounts/context_processors.py
rizwanisready db213d3228 wrong commit
2024-02-29 13:25:50 +05:30

48 lines
2.4 KiB
Python

from accounts import resource_action
from django.core.cache import cache
CACHE_KEY_RESOURCE_ACTION_CONSTANTS = 'resource_action_constants'
def resource_action_constants(request):
# Add debugging output
print("Resource and action constants context processor is executing.")
# Try to retrieve the constants from the cache
resource_action_constants = cache.get(CACHE_KEY_RESOURCE_ACTION_CONSTANTS)
# print(f"The value of '{CACHE_KEY_RESOURCE_ACTION_CONSTANTS}' in the cache is: {resource_action_constants}")
if resource_action_constants is None:
# Compute the constants if not found in the cache
resource_action_constants = compute_resource_action_constants()
print()
# Store the constants in the cache with a timeout (e.g., 3600 seconds for 1 hour)
cache.set(CACHE_KEY_RESOURCE_ACTION_CONSTANTS, resource_action_constants, 3600)
return {
'resource_context': resource_action_constants,
}
def compute_resource_action_constants():
constants_dict = {
'ACTION_CREATE': resource_action.ACTION_CREATE,
'ACTION_READ': resource_action.ACTION_READ,
'ACTION_UPDATE': resource_action.ACTION_UPDATE,
'ACTION_DELETE': resource_action.ACTION_DELETE,
'RESOURCE_MANAGE_DASHBOARD': resource_action.RESOURCE_MANAGE_DASHBOARD,
'RESOURCE_MANAGE_IAM': resource_action.RESOURCE_MANAGE_IAM,
'RESOURCE_MANAGE_CUSTOMER': resource_action.RESOURCE_MANAGE_CUSTOMER,
'RESOURCE_MANAGE_WALLET': resource_action.RESOURCE_MANAGE_WALLET,
'RESOURCE_MANAGE_PAYMENT': resource_action.RESOURCE_MANAGE_PAYMENT,
'RESOURCE_MANAGE_EVENTS': resource_action.RESOURCE_MANAGE_EVENTS,
'RESOURCE_MANAGE_CONTACT_US': resource_action.RESOURCE_MANAGE_CONTACT_US,
'RESOURCE_MANAGE_CMS': resource_action.RESOURCE_MANAGE_CMS,
'RESOURCE_MANAGE_REPORTS': resource_action.RESOURCE_MANAGE_REPORTS,
'RESOURCE_MANAGE_SUBSCRIPTIONS': resource_action.RESOURCE_MANAGE_SUBSCRIPTIONS,
'RESOURCE_MANAGE_REFERRALS': resource_action.RESOURCE_MANAGE_REFERRALS,
'RESOURCE_MANAGE_FEEDBACK': resource_action.RESOURCE_MANAGE_FEEDBACK,
'RESOURCE_IAM_PRINCIPAL': resource_action.RESOURCE_IAM_PRINCIPAL,
'RESOURCE_IAM_PRINCIPAL_GROUP': resource_action.RESOURCE_IAM_PRINCIPAL_GROUP,
'RESOURCE_IAM_GROUP': resource_action.RESOURCE_IAM_GROUP,
'RESOURCE_IAM_ROLE': resource_action.RESOURCE_IAM_ROLE,
}
return constants_dict