<commit_before>from __future__ import print_function

import json

from django.shortcuts import render_to_response
from django.template.loader import render_to_string
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.template import RequestContext
from django.core.urlresolvers import reverse

# cache related
from django.core.cache import cache
from django.views.decorators.cache import cache_page

from dataverse_org.context_processors import baseurl


def get_navbar_as_string(request):

    return render_to_string('navbar_details.html'\
                            , {}\
                            , context_instance=RequestContext(request))


@cache_page(60 * 60 * 6)    # 6 hours
def view_nav_only(request):
    """
    Return the navbar HTML
    """
    return HttpResponse(get_navbar_as_string(request))


CACHE_TIMEOUT = 60 * 60 * 6   # 6 hours

def view_nav_only_as_json(request):
    """
    Return the navbar HTML as JSON
    """
    CACHE_KEY_FOR_NAVBAR = 'NAVBAR_JSON_DATA_RENDERED'
    
    # Is the navbar cached?
    navbar_data_json = cache.get(CACHE_KEY_FOR_NAVBAR)
    
    # No, create navbar
    #
    if navbar_data_json is None:
        
        # Render navbar as string
        #
        menu_string = get_navbar_as_string(request)

        # Add navbar to dict
        #
        dataverse_dot_org_homepage_url = baseurl(request).get('BASE_URL','') + reverse('view_homepage', kwargs={})
        navbar_data = { 'navbar_html' : menu_string\
                    , 'dataverse_dot_org_homepage_url': dataverse_dot_org_homepage_url
         }

        # Convert dict to JSON string
        #<commit_msg>change cache from 1 hr to 2<commit_after>from __future__ import print_function

import json

from django.shortcuts import render_to_response
from django.template.loader import render_to_string
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.template import RequestContext
from django.core.urlresolvers import reverse

# cache related
from django.core.cache import cache
from django.views.decorators.cache import cache_page

from dataverse_org.context_processors import baseurl


def get_navbar_as_string(request):

    return render_to_string('navbar_details.html'\
                            , {}\
                            , context_instance=RequestContext(request))


@cache_page(60 * 60 * 1)    # 1 hour(s)
def view_nav_only(request):
    """
    Return the navbar HTML
    """
    return HttpResponse(get_navbar_as_string(request))


CACHE_TIMEOUT = 60 * 60 * 1   # 1 hour(s)
def view_nav_only_as_json(request):
    """
    Return the navbar HTML as JSON
    """
    CACHE_KEY_FOR_NAVBAR = 'NAVBAR_JSON_DATA_RENDERED'
    
    # Is the navbar cached?
    navbar_data_json = cache.get(CACHE_KEY_FOR_NAVBAR)
    
    # No, create navbar
    #
    if navbar_data_json is None:
        
        # Render navbar as string
        #
        menu_string = get_navbar_as_string(request)

        # Add navbar to dict
        #
        dataverse_dot_org_homepage_url = baseurl(request).get('BASE_URL','') + reverse('view_homepage', kwargs={})
        navbar_data = { 'navbar_html' : menu_string\
                    , 'dataverse_dot_org_homepage_url': dataverse_dot_org_homepage_url
         }

        # Convert dict to JSON string
        #
{'fraction_non_alphanumeric': 0.07389606488434966, 'fraction_numerical': 0.009612496245118654, 'mean_word_length': 2.9737470167064437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1667162', 'n_tokens_mistral': 1054, 'n_tokens_neox': 999, 'n_words': 232}