<commit_before>from django.conf import settings
from django.core.urlresolvers import reverse
from django.db import connection
from django.db.models import Max
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.shortcuts import render_to_response
from django.template import RequestContext

from google.appengine.api import users

import random
import urllib


from cms.forms import *
from cms.models import *


def home(request):

    bg_image_count = BackgroundImage.objects.count()

    if bg_image_count > 0:
        random_number = random.randrange(bg_image_count)
        bg_images = BackgroundImage.objects.all()
        bg_image = bg_images[random_number]
    else:
        bg_image = False

    categories = Category.objects.all()

    return render_to_response('home.html', { 
        'bg_image': bg_image, 
        'categories': categories, 
    }, context_instance=RequestContext(request))


def bg_image(request, bg_image_id):

    try:
        bg_image = BackgroundImage.objects.get(id=bg_image_id)
        response = HttpResponse(bg_image.image, mimetype=bg_image.content_type)
        return response
    except:
        raise Http404


def page(request, page_id):

    page = Page.objects.get(id=page_id)
    content = PageWYSIWYG.objects.get(page=page_id)

    return render_to_response('page.html', {
        'page': page, 
        'content': content,
    }, context_instance=RequestContext(request))

<commit_msg>add memcache for public bg_images<commit_after>from django.conf import settings
from django.core.urlresolvers import reverse
from django.db import connection
from django.db.models import Max
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.shortcuts import render_to_response
from django.template import RequestContext

from google.appengine.api import users
from google.appengine.api import memcache

import random
import urllib

from cms.forms import *
from cms.models import *


def home(request):

    bg_image_count = BackgroundImage.objects.count()

    if bg_image_count > 0:
        random_number = random.randrange(bg_image_count)
        bg_images = BackgroundImage.objects.all()
        bg_image = bg_images[random_number]
    else:
        bg_image = False

    categories = Category.objects.all()

    return render_to_response('home.html', { 
        'bg_image': bg_image, 
        'categories': categories, 
    }, context_instance=RequestContext(request))


def bg_image(request, bg_image_id):

    key = 'bg_image'+bg_image_id

    bg_image = memcache.get(key)

    if bg_image is not None:
        return HttpResponse(bg_image.image, mimetype=bg_image.content_type)
    else:
        try:
            bg_image = BackgroundImage.objects.get(id=bg_image_id)
            memcache.add(key, bg_image, 360000)
            return HttpResponse(bg_image.image, mimetype=bg_image.content_type)
        except:
            raise Http404


def page(request, page_id):

    page = Page.objects.get(id=page_id)
    content = PageWYSIWYG.objects.get(page=page_id)

    return render_to_response('page.html', {
        'page': page, 
        'content': content,
    }, context_instance=RequestContext(request))


{'fraction_non_alphanumeric': 0.0842170929507174, 'fraction_numerical': 0.006238303181534623, 'mean_word_length': 3.587982832618026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1717363', 'n_tokens_mistral': 989, 'n_tokens_neox': 940, 'n_words': 216}