Created
December 10, 2015 07:51
-
-
Save websiddu/aab6aff4bafe371b4eb3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Copyright 2007 Google Inc. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
import webapp2, os, urllib, urllib2, json, logging, sha, time, datetime | |
import jinja2 | |
from google.appengine.ext import db | |
from google.appengine.ext.db import Key | |
from google.appengine.api import users | |
from google.appengine.ext import webapp | |
class Request(db.Model): | |
name = db.StringProperty() | |
gender = db.StringProperty() | |
what = db.StringProperty() | |
phone = db.StringProperty() | |
opt_contact = db.StringProperty() | |
duration = db.IntegerProperty() | |
post_time = db.IntegerProperty() | |
expire_time = db.IntegerProperty() | |
location_lat = db.StringProperty() | |
location_lon = db.StringProperty() | |
location_name = db.StringProperty() | |
JINJA_ENVIRONMENT = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), | |
extensions=['jinja2.ext.autoescape'], | |
autoescape=True) | |
class MainHandler(webapp2.RequestHandler): | |
# vals = {} | |
def get(self): | |
# global vals | |
vals={} | |
# posts = | |
key = self.request.get('key') | |
if key: | |
keyclass = Key(key) | |
db.get(keyclass) | |
self.redirect('/') | |
posts = Request.all() | |
vals['data'] = posts | |
template = JINJA_ENVIRONMENT.get_template('frontpage.html') | |
self.response.write(template.render(vals)) | |
def post(self): | |
# global vals | |
vals = {} | |
newpost = Request() | |
newpost.name = self.request.get('name') | |
newpost.gender = self.request.get('sex') | |
newpost.what = self.request.get('description') | |
newpost.phone = self.request.get('phone') | |
newpost.opt_contact = '' | |
opt = self.request.get('optional_contact') | |
if opt: | |
newpost.opt_contact = 'Optional Contact Info: ' + opt | |
newpost.duration = int(self.request.get('duration')) | |
submit_time = int(datetime.datetime.now().strftime("%s")) * 1000 | |
newpost.post_time = submit_time | |
newpost.expire_time = newpost.post_time+newpost.duration*1000 | |
newpost.location_lat = self.request.get('lat') | |
newpost.location_lon = self.request.get('lon') | |
newpost.location_name = self.request.get('location') | |
newpost_key = newpost.put() | |
self.redirect('/?key=' + str(newpost_key)) | |
# newpost = newpost_key.get() | |
# currenttime = int(datetime.datetime.now().strftime("%s")) * 1000 | |
# logging.info("Now time: %s",currenttime) | |
# time.sleep(0.1) | |
# self.redirect('/' ) | |
# posts = Request.query(Request.expire_time>int(datetime.datetime.now().strftime("%s")) * 1000) | |
# posts = [newpost, Request.query(Request.expire_time>int(datetime.datetime.now().strftime("%s")) * 1000)] | |
# vals['data'] = posts | |
# template = JINJA_ENVIRONMENT.get_template('frontpage.html') | |
# self.response.write(template.render(vals)) | |
application = webapp2.WSGIApplication([ \ | |
('/', MainHandler) | |
], | |
debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment