pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Python pastebin - collaborative debugging tool View Help


Posted by Anonymous on Thu 15 May 07:56
report abuse | download | new post

  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2007 Google Inc.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. #     http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17.  
  18.  
  19.  
  20.  
  21. import wsgiref.handlers
  22. import os
  23.  
  24. from google.appengine.ext import webapp
  25. from google.appengine.ext.webapp import template
  26.  
  27. from django.utils import simplejson
  28.  
  29. import db_model
  30.  
  31. class MainHandler(webapp.RequestHandler):
  32.  
  33.   def get(self):
  34.     path = os.path.join(os.path.dirname(__file__), 'index.html')
  35.     self.response.out.write(template.render(path, {}))
  36.  
  37. class GridHandler(webapp.RequestHandler):
  38.   def post(self):
  39.     page = int(self.request.get('page'))
  40.     rp = int(self.request.get('rp'))
  41.     sortname = self.request.get('sortname')
  42.     sortorder = self.request.get('sortorder')
  43.     query = self.request.get('query')
  44.     qtype = self.request.get('qtype')
  45.  
  46.     if sortname == '' : sortname = 'name'
  47.     if sortorder == '' : sortorder = '-'
  48.  
  49.     start = (page - 1) * rp
  50.     if sortorder == 'desc' :
  51.       sortorder = '-'
  52.     else:
  53.       sortorder = ''
  54.  
  55.     countries = db_model.Country.all()
  56.     countries.order( sortorder  + sortname )
  57.     if query == '' :
  58.       rows = countries.fetch( rp, start )
  59.       count = countries.count()
  60.     else :
  61.       countries.filter( qtype + ' =', query.upper() )
  62.       rows = countries.fetch( rp, start )
  63.       count = countries.count()
  64.      
  65.     cells = [ [r.iso, r.name, r.printable_name, r.iso3, r.numcode] for r in rows ]
  66.     results = [ {'cell' : c } for c in cells ]
  67.      
  68.     ret = { 'page' : page,
  69.             'total' : count,
  70.             'rows' : results }
  71.     data = simplejson.dumps(ret)
  72.     self.response.out.write(data)
  73.  
  74. def main():
  75.   handlers = [ ('/', MainHandler),
  76.                ('/grid_data', GridHandler) ]
  77.   application = webapp.WSGIApplication(handlers, debug=False)
  78.   wsgiref.handlers.CGIHandler().run(application)
  79.  
  80.  
  81. if __name__ == '__main__':
  82.   main()

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post