Skip to content

Commit

Permalink
rolling back to past deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Carter committed Jan 5, 2018
1 parent c1de49b commit c5dce80
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 136 deletions.
9 changes: 5 additions & 4 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#to deploy: remove the application and version lines
application: lasanfound
version: 1
runtime: python27
Expand All @@ -13,9 +14,9 @@ libraries:
handlers:
- url: /stylesheets
static_dir: stylesheets
- url: /img
static_dir: images
- url: /.*
script: lasanfound.application

- url: /images
static_dir: images

- url: /.*
script: lasanfound.application
123 changes: 65 additions & 58 deletions lasanfound.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@
import re
import httplib
import json
#import cloudstorage as gcs
import imghdr
from datetime import datetime, timedelta
from google.appengine.api import app_identity
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import blobstore
from google.appengine.ext import ndb
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import smtplib

## see http://jinja.pocoo.org/docs/api/#autoescaping
#see http://jinja.pocoo.org/docs/api/#autoescaping
def guess_autoescape(template_name):
if template_name is None or '.' not in template_name:
return False
ext = template_name.rsplit('.', 1)[1]
return ext in ('xml', 'html', 'htm')

JINJA_ENVIRONMENT = jinja2.Environment(
autoescape=guess_autoescape, ## see http://jinja.pocoo.org/docs/api/#autoxscaping
autoescape=guess_autoescape, #see http://jinja.pocoo.org/docs/api/#autoxscaping
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'])

Expand All @@ -48,22 +51,12 @@ def render_json(self, d):
self.response.headers['Content-Type'] = 'application/json; charset=UTF-8'
self.write(json_txt)

#this probably needs to change to get the bucket to work
"""
def file_handle(self):
bucket_name = os.environ.get('BUCKET_NAME', app_identity.get_default_gcs_bucket_name())
#self.response.headers['Content-Type'] = 'text/plain'
logging.info('Demo GCS Application running from Version: ' + os.environ['CURRENT_VERSION_ID'] + '\n')
logging.info('Using bucket name: ' + bucket_name + '\n\n')
#self.response.write('Demo GCS Application running from Version: ' + os.environ['CURRENT_VERSION_ID'] + '\n')
#self.response.write('Using bucket name: ' + bucket_name + '\n\n')
"""

#Model for the item objects
class Item(db.Model):
title = db.StringProperty()
description = db.StringProperty()
location = db.StringProperty()
picture = db.BlobProperty()
created = db.DateTimeProperty(auto_now_add = True)

class Home(Handler):
Expand All @@ -72,87 +65,101 @@ def get(self):
items = db.GqlQuery("SELECT * FROM Item ORDER BY created DESC limit 10")
self.render("home.html", items=items)

class About(Handler):
def get(self):
self.render("about.html")

class NewItem(Handler):
def get(self):
logging.info("******** New Item GET ******")
upload_url = blobstore.create_upload_url('/upload')
#this needs to include a blob array
self.render("newitem.html", upload_url=upload_url)

def post(self):
#need to add error handling for a file too large
logging.info("******** New Item POST *******")
upload_url = blobstore.create_upload_url('/upload')
title = self.request.get("title")
desc = self.request.get("description")
location = self.request.get("location")
if(title==""):
logging.info("error, submitted blank title")
error="*Please Add a Title*"
self.render("newitem.html", error=error, descData=desc, locData=location, upload_url=upload_url)

else:
logging.info("no errors, posting item")
it = Item(title=title, description=desc, location=location)
it.put()
#item_id = it.key().id()
time.sleep(0.1)
self.redirect('/')

"""
class UploadHandler(Handler):
def get(self):
logging.info("enter uploader GET (shouldn't happen)")
def post(self):
logging.info("enter uploader POST")
try:
upload = self.get_uploads()[0]
user_photo = UserPhoto(
user=users.get_current_user().user_id(),
blob_key=upload.key())
user_photo.put()
title = cgi.escape(self.request.get("title"), quote=True)
desc = cgi.escape(self.request.get("description"), quote=True)
location = cgi.escape(self.request.get("location"), quote=True)
picture = self.request.get("file")
img_type = imghdr.what(None, picture)
img_type = str(img_type)
supportedtypes = ['png', 'jpeg', 'gif', 'tiff', 'bmp']
con = httplib.HTTPSConnection("www.google.com")
con.request("POST", "/recaptcha/api/siteverify", urllib.urlencode({"secret": "6LdVQTQUAAAAAEla2hBTZfXSiBOiaGUjYPVcbzIg", "response": self.request.get("g-recaptcha-response"), "remoteip": self.request.remote_addr}), {"Content-Type": "application/x-www-form-urlencoded"})
response = con.getresponse()
data = response.read()
success = json.loads(data)['success']
if success:
if title=="":
logging.info("error, submitted blank title")
titleError="*Please Add a Title*"
self.render("newitem.html", titleError=titleError, descData=desc, locData=location, upload_url=upload_url)
elif (img_type not in supportedtypes) and (img_type != "None"):
logging.info("error, invalid file type: "+img_type)
fileError="*Not Supported Filetype*<br><br>Supported Types: " + ", ".join(supportedtypes)
self.render("newitem.html", fileError=fileError, descData=desc, locData=location, upload_url=upload_url, titleData=title)
else:
logging.info("no errors, posting item")
if img_type!="None":
it = Item(title=title, description=desc, location=location, picture=db.Blob(picture))
else:
it = Item(title=title, description=desc, Location=location)
it.put()
time.sleep(0.1)
self.redirect('/')
except:
logging.info("ya done goofed boi YAYAYYAYA")
self.error(500)
"""

else:
self.render("newitem.html", descData=data, locData=location, upload_url=upload_url, )

class PermItem(Handler):
def get(self, item_id):
logging.info("entering the permalink for each lost item")
logging.info("id: "+str(item_id))
id_int = int(item_id)
item = Item.get_by_id(id_int)
logging.info(str(item))
self.render("item.html", item=item)

def post(self, item_id):
id_int = int(item_id)
item = Item.get_by_id(id_int)
logging.info("item: "+str(item.key()))
logging.info("this is if they want to claim an item")
logging.info(self.request.POST)
con = httplib.HTTPSConnection("www.google.com")
con.request("POST", "/recaptcha/api/siteverify", urllib.urlencode({"secret": "6LdVQTQUAAAAAEla2hBTZfXSiBOiaGUjYPVcbzIg", "response": self.request.get("g-recaptcha-response"), "remoteip": self.request.remote_addr}), {"Content-Type": "application/x-www-form-urlencoded"})
response = con.getresponse()
data = response.read()
success = json.loads(data)['success']
if success:
item.key.delete()
item.delete()
logging.info("key: "+str(item))
time.sleep(0.1)
self.redirect('/')
else:
self.render("item.html", item=item, error="Please complete reCaptcha")

class About(Handler):
class ImgHandler(Handler):
def get(self, img_id):
logging.info("img handler get")
item = Item.get_by_id(int(img_id))
if item.picture:
logging.info(item.title)
self.response.headers['Content-Type']="image"
self.response.out.write(item.picture)
else:
self.error(404)

class ErrorHandler(Handler):
def get(self):
logging.info("enter about get")
self.render("about.html")
file_handle(self)
self.render("error.html", error="404 page not found")


application = webapp2.WSGIApplication([
('/', Home),
('/new', NewItem),
('/about', About),
#('/upload', UploadHandler),
(r'/img/(\d+)', ImgHandler),
(r'/item/(\d+)', PermItem),
(r'/\S+', Home),#who needs 404 errors?
], debug=True)
('/.*', ErrorHandler),#who needs 404 errors?
], debug=True)
Binary file added lasanfound.pyc
Binary file not shown.
17 changes: 16 additions & 1 deletion stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ input[type="text"]{
font-weight: bold;
}

.pic-get{
max-width: 300px;
}

.home-pic{
max-height: 120px;
}

.pic{
border: 3px solid white;
box-shadow: 0 10px 10px rgba(0,0,0,0.3);
}

.claim{
font-size: 100%;
color: purple;
Expand All @@ -80,6 +93,7 @@ input[type="text"]{
font-weight: bold;
height: 30px;
width: 120px;
margin-bottom: 50px;
}

.error{
Expand All @@ -92,8 +106,9 @@ input[type="text"]{
text-decoration: none;
}

#home-container {
.page-container {
width: 70%;
min-width: 700px;
margin: auto;
}

24 changes: 13 additions & 11 deletions templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
<html>
<head>
<meta charset="utf-8">
<title>LASA 'n Found</title>
<title>LASA 'n Found - About</title>
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css">
</head>
<body>
<h1>Lost and Found, Reimagined!</h1>
<div class="toolbar">
<a class="tool-link" href="/">Home</a> |
<a class="tool-link" href="/new">New Item</a>
</div>
<h3>What is LASA 'n Found?</h3>
<p>LASA 'n Found is a crowdsourced solution to LASA's lost and found problem. You can either browse for a lost item, or submit a new one to our database.</p>
<h3>How it Works-</h3>
<p>Our homepage shows the 10 most recently submitted items in our database, to look further back in time, our archive function lets you look through all current Lost 'n Found items. An item in the database expires after 2 weeks, meaning if it isn't claimed, the item is deleted. To add an item that you have found, please go to the 'Report a New Lost Item' page.</p>
<body class="about">
<div class="page-container">
<h1>Lost and Found, Reimagined!</h1>
<div class="toolbar">
<a class="tool-link" href="/">Home</a> |
<a class="tool-link" href="/new">New Item</a>
</div>
<h3>What is LASA 'n Found?</h3>
<p>LASA 'n Found is a crowdsourced solution to LASA's lost and found problem. You can either browse for a lost item, or submit a new one to our database.</p>
<h3>How it Works</h3>
<p>Our homepage shows the 10 most recently submitted items in our database, to look further back in time, our archive function lets you look through all current Lost 'n Found items. An item in the database expires after 2 weeks, meaning if it isn't claimed, the item is deleted. To add an item that you have found, please go to the <b><a class="nostyle-link" href="/new">Report a New Lost Item</a></b> page. To claim an item, make sure it is actually yours, complete a Captcha, and hit 'Claim Me!'.</p>
</div>
</body>
</html>
20 changes: 20 additions & 0 deletions templates/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>LASA 'n Found - ERROR</title>
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css">
</head>
<body>
<div class="page-container">
<div id="home-container">
<h1>Error: {{error}}</h1>
<div class="toolbar">
<a class="tool-link" href="/">Home</a> |
<a class="tool-link" href="/about">About</a> |
<a class="tool-link" href="/new">New Item</a>
</div>
</div>
</div>
</body>
</html>
34 changes: 21 additions & 13 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css">
</head>
<body>
<h1>LASA's very own lost and found database</h1>
<div class="toolbar">
<a class="tool-link" href="/about">About</a> |
<a class="tool-link" href="/new">New Item</a>
</div>
<div class="items">
{% for item in items %}
<div class="item">
<div class="item-title">{{item.title}}</div>
<div class="item-date">{{item.created.date().strftime("%A %B %d, %Y")}} {{item.created.time().strftime("%X %z")}}</div>
<div class="item-description">{{item.description}}</div>
</div>
{% endfor %}
<div class="page-container">
<h1>LASA 'n Found</h1>
<div class="toolbar">
<a class="tool-link" href="/about">About</a> |
<a class="tool-link" href="/new">New Item</a>
</div>
<div class="items">
{% for item in items %}
<div class="item">
<div class="item-title"><a class="nostyle-link" href="/item/{{item.key().id()}}">{{item.title}}</a></div>
<div class="item-date">Submitted {{item.created.date().strftime("%A %B %d, %Y")}} {{item.created.time().strftime("%z")}}</div>
{% if item.location %}
<div class="item-location">Currently in: {{item.location}}</div>
{% endif %}
<div class="item-description">{{item.description}}</div><br>
{% if item.picture %}
<div class="picture"><a class="nostyle-link" href="/item/{{item.key().id()}}"><img class="home-pic pic" src="/img/{{item.key().id()}}"></a></img></div>
{% endif %}
</div>
{% endfor %}
</div>
</div>
</body>
</html>
Loading

0 comments on commit c5dce80

Please sign in to comment.