Exemplo n.º 1
0
def g11n(request):
    """
    This context processor returns meta informations contained in cached files. 
    If there aren't cache it calculates dictionary to return
    """
    context_extras = {}
    if not request.is_ajax() and hasattr(request ,'upy_context') and request.upy_context['PAGE']:
        page = request.upy_context['PAGE']
        node = request.upy_context['NODE']
        context_extras['PAGE'] = page
        context_extras['NODE'] = node
        pub_extended = request.upy_context['PUB_EXTENDED']
        context_extras['PUBLICATION'] = pub_extended.publication
        
        publication = pub_extended.publication
        
                                
        context_extras['ROOT'] = pub_extended.root
        
        filename="meta-%s-%s-%s.json" % (publication.pk,page.pk,node.pk)
        if os.path.exists("%s%s" % (settings.UPYCACHE_DIR,filename)):
            file_cache = open(u'%s%s' % (settings.UPYCACHE_DIR,filename))
            json = simplejson.loads(file_cache.read())
            meta_temp = MetaContent()
            meta_temp.jsonToMeta(json['META'])
            context_extras['META'] = meta_temp
            context_extras['MEDIA_CSS'] = json['MEDIA_CSS']
            context_extras['MEDIA_JS_HEADER'] = json['MEDIA_JS_HEADER']
            context_extras['MEDIA_JS_FOOTER'] = json['MEDIA_JS_FOOTER']
            return context_extras
        
        cache_json = {}
        
        try:
            context_extras['ROOT'] = pub_extended.root
            struct_js = pub_extended.tree_structure.js.all().order_by("jstreestructureposition")
            struct_css = [clean_path(css) for css in pub_extended.tree_structure.css.all().order_by("csstreestructureposition")]
            context_extras['STRUCT_CSS'] = struct_css
            
        except Exception, e:
            print "Error in %s: %s" %(__file__,e)
        finally:
Exemplo n.º 2
0
         return context_extras
     
     cache_json = {}
     
     try:
         context_extras['ROOT'] = pub_extended.root
         struct_js = pub_extended.tree_structure.js.all().order_by("jstreestructureposition")
         struct_css = [clean_path(css) for css in pub_extended.tree_structure.css.all().order_by("csstreestructureposition")]
         context_extras['STRUCT_CSS'] = struct_css
         
     except Exception, e:
         print "Error in %s: %s" %(__file__,e)
     finally:
         if page:
             page_js = page.template.js.all().order_by("jstemplateposition")
             page_css = [clean_path(css) for css in page.template.css.all().order_by("csstemplateposition")]
             context_extras['PAGE_CSS'] = page_css
 
             all_js_header = []
             all_js_footer = []
             for js in struct_js:
                 if js.html_position == "header":
                     all_js_header.append(js.url)
                 else:
                     all_js_footer.append(js.url)
 
             for js in page_js:
                 if js.html_position == "header":
                     all_js_header.append(js.url)
                 else:
                     all_js_footer.append(js.url)