Guest

Untitled

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 1.26 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. from django.template import Context, Template
  2. from django.http import HttpResponseRedirect
  3. from ragendja.template import render_to_response
  4. from google.appengine.api import mail
  5. from google.appengine.api import urlfetch
  6. from django.utils import simplejson
  7. from google.appengine.ext.db import Query
  8. from django.template.loader import get_template
  9. import random
  10. from contact.models import Prospect, Feedback, Ad
  11. # the new added String and os class
  12. import string
  13. import os
  14.  
  15.  
  16.  
  17. def get_ad():
  18.   total_count = Ad.all().count()
  19.   all_Ads = Query(Ad).fetch(1000)
  20.   memcache.add("total_count_of_ads", total_count)
  21.  
  22.   # assume total_ads to be less than 1000 for now
  23.   a_random_Ad = random.randint(0, total_count - 1)
  24.   my_random_Ad = all_Ads[a_random_Ad]
  25.   #print my_random_Ad.name
  26.  
  27.   # if you are using Django templates, it can be passed to the HTMl form as
  28.   template_values = dict()
  29.   template_values['ad_url'] = my_random_Ad.adurl
  30.  
  31.   # and then pass this template values and render the template
  32.   # render_to_response(request, template, data, mimetype)
  33.   template_path = string.join(os.path.dirname(__file__).split('/')[:-1], '/')+ '/templates/root.html'
  34.  
  35.   t = get_template(template_path)
  36.   html = t.render(Context(template_values))
  37.   return html
  38.  
  39. #get_ad()