
Untitled
By: a guest on Jan 28th, 2012 | syntax:
None | size: 1.26 KB | hits: 12 | expires: Never
from django.template import Context, Template
from django.http import HttpResponseRedirect
from ragendja.template import render_to_response
from google.appengine.api import mail
from google.appengine.api import urlfetch
from django.utils import simplejson
from google.appengine.ext.db import Query
from django.template.loader import get_template
import random
from contact.models import Prospect, Feedback, Ad
# the new added String and os class
import string
import os
def get_ad():
total_count = Ad.all().count()
all_Ads = Query(Ad).fetch(1000)
memcache.add("total_count_of_ads", total_count)
# assume total_ads to be less than 1000 for now
a_random_Ad = random.randint(0, total_count - 1)
my_random_Ad = all_Ads[a_random_Ad]
#print my_random_Ad.name
# if you are using Django templates, it can be passed to the HTMl form as
template_values = dict()
template_values['ad_url'] = my_random_Ad.adurl
# and then pass this template values and render the template
# render_to_response(request, template, data, mimetype)
template_path = string.join(os.path.dirname(__file__).split('/')[:-1], '/')+ '/templates/root.html'
t = get_template(template_path)
html = t.render(Context(template_values))
return html
#get_ad()