daily pastebin goal
74%
SHARE
TWEET

Untitled

a guest Apr 11th, 2012 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # coding: utf-8
  2. # runme.py
  3.  
  4. import os
  5. import webapp2
  6. import logging
  7. import string
  8. import random
  9. import itertools
  10. from google.appengine.ext import db
  11.  
  12. def generate_token(length = 16):
  13.         return u''.join(random.choice(string.ascii_letters + string.digits) for _ in itertools.repeat(None, length))
  14.  
  15.  
  16. class Qwerty(db.Model):
  17.         token = db.StringProperty('Token')
  18.  
  19.  
  20. class IndexHandler(webapp2.RequestHandler):
  21.         def get(self):
  22.                 items = Qwerty.all().fetch(1000)
  23.                 return self.response.out.write(
  24.                         '<a href="/add">Add one more</a><br/>' +
  25.                         '<br/>'.join(['<a href="/show/{token}">{token}</a>'.format(token = item.token) for item in items])
  26.                 )
  27.  
  28.  
  29. class AddHandler(webapp2.RequestHandler):
  30.         def get(self):
  31.                 item = Qwerty(token = generate_token())
  32.                 logging.info('### Added {token}'.format(token = item.token))
  33.                 item.save()
  34.                 return self.redirect('/')
  35.  
  36.  
  37. class ShowHandler(webapp2.RequestHandler):
  38.         def get(self, token):
  39.                 item = Qwerty.all().filter('token', token).get()
  40.                 logging.info('### Loaded {token}'.format(token = item.token))
  41.                 return self.response.out.write('<a href="/">Index</a><br /> {token}'.format(token = item.token))
  42.  
  43.  
  44. app = webapp2.WSGIApplication([
  45.         (r'/', IndexHandler),
  46.         (r'/add', AddHandler),
  47.         (r'/show/(.*)', ShowHandler),
  48. ], debug = os.getenv('SERVER_SOFTWARE', '').startswith('Dev'))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top