from django.conf import settings
from civictechprojects.caching.cache import ProjectCache
from common.helpers.constants import FrontEndSection


def about_project_preload(context, query_args):
    context = default_preload(context, query_args)
    project_id = query_args['id'][0]
    project_json = ProjectCache.get(project_id)
    if project_json is None:
        print('Failed to preload project info, no cache entry found: ' + project_id)
    context['title'] = project_json['project_name'] + ' | DemocracyLab'
    context['description'] = project_json['project_short_description'] or project_json['project_description'][:300]
    if 'project_thumbnail' in project_json:
        context['og_image'] = project_json['project_thumbnail']['publicUrl']
    return context


def default_preload(context, query_args):
    context['title'] = 'DemocracyLab'
    context['description'] = 'Everyone has something to contribute to the technical solutions society needs. ' \
                             'Volunteer today to connect with other professionals volunteering their time.'
    context['og_type'] = 'website'
    context['og_image'] = settings.STATIC_CDN_URL + '/img/Democracylab_is_a_global_volunteer_tech_for_good_nonprofit.png'
    return context


preload_urls = [
    {'section': FrontEndSection.AboutProject.value, 'handler': about_project_preload}
]


def context_preload(section, query_args, context):
    handler = next((preload_url['handler'] for preload_url in preload_urls if preload_url['section'] == section), default_preload)
    return handler(context, query_args)


@@ -345,16 +345,20 @@
 json is 
+not 
 None:%0A  
@@ -363,89 +363,8 @@
     
-    print('Failed to preload project info, no cache entry found: ' + project_id)%0A
     
@@ -427,32 +427,36 @@
 mocracyLab'%0A    
+ 
+   
 context%5B'descrip
@@ -551,16 +551,20 @@
 %5D%5B:300%5D%0A
+    
     if '
@@ -599,16 +599,20 @@
 t_json:%0A
+    
         
@@ -680,16 +680,111 @@
 icUrl'%5D%0A
+    else:%0A        print('Failed to preload project info, no cache entry found: ' + project_id)%0A
     retu

Handle condition where project is not cached