5
from google.appengine.api import users
6
from google.appengine.api import mail
8
from google.appengine.ext import webapp
9
from google.appengine.ext.webapp.util import run_wsgi_app
10
from google.appengine.ext import db
12
from google.appengine.ext import blobstore
13
from google.appengine.ext.webapp import blobstore_handlers
16
Version 2: Using the Blobstore API to handle larger model files
19
class ColladaModel(db.Model):
20
author = db.StringProperty(multiline=True)
21
model = db.StringProperty(multiline=True)
22
fiducial = db.StringProperty(multiline=False)
24
class Fiducial(db.Model):
25
name = db.StringProperty(multiline=False)
26
marker = db.BlobProperty()
27
pic = db.BlobProperty()
28
used = db.BooleanProperty()
29
model = db.StringProperty(multiline=False)
32
class MainPage(webapp.RequestHandler):
34
blob_url = blobstore.create_upload_url('/upload')
35
self.response.out.write("""
37
<head><title>Model Uploader</title></head>
39
<form action="%s" enctype="multipart/form-data" method="POST">
40
Please enter your email:<br>
41
<input name="author" type="text" size="30">
43
Please select your model:<br>
44
<input name="model" type="file">
46
<input type="submit" value="Submit">
49
</html>""" % blob_url)
51
class UploadModel(blobstore_handlers.BlobstoreUploadHandler):
54
collada = ColladaModel()
55
# Need to enforce email
56
collada.author = self.request.get('author')
57
# Only one blobstore upload, first elem in the list
58
collada.model = str((self.get_uploads('model')[0].key()))
60
# Get and assign fiducial marker
61
fiducials = db.GqlQuery("SELECT * FROM Fiducial WHERE used = False")
62
if fiducials.count() > 0:
64
marker = (fiducials.fetch(1))[0]
66
# Currently stores string, fix later
67
collada.fiducial = marker.name
68
marker.model = collada.author
70
# Send an email with an attachment
72
(sender="jnoraky@gmail.com",
76
Attached is your ARTag. Print it and bring it to your destination.
77
Your unique ARTag identifier is %s. This will be used to load your
82
attachments=[(marker.name, marker.pic)]
85
# Disable ARTag for other models
93
def redirect(self, uri, permanent=False):
95
msg = "Model successfully written to the database. Please \
96
check your email for the ARTag!"
98
# Add debug info later
99
msg = "Sorry, your model could not be uploaded. Please \
101
self.response.out.write(
104
<script language="javascript" type="text/javascript">
106
window.location="%s";
112
# For use only in development. In actual instantiation, all
113
# fiducial markers will be loaded beforehand.
114
class FiducialUploader(webapp.RequestHandler):
116
self.response.out.write("""
118
<head><title>Fiducial Uploader</title></head>
120
<form action="/fiducialupload" enctype="multipart/form-data" method="POST">
121
Please enter the marker name:<br>
122
<input name="marker" type="text" size="30">
124
Please upload the image of the fiducial:<br>
125
<input name="pic" type="file">
127
Please upload the pattern file of the fiducial:<br>
128
<input name="fiducial" type="file">
130
<input type="submit" value="Submit">
136
class UploadFiducial(webapp.RequestHandler):
138
fiducial = Fiducial()
139
fiducial.name = self.request.get('marker')
140
fiducial.pic = db.Blob(self.request.get('pic'))
141
fiducial.marker = db.Blob(self.request.get('fiducial'))
142
fiducial.used = False
144
self.redirect('/fiducial')
146
# Currently will download first entry in db query list
147
class Download(blobstore_handlers.BlobstoreDownloadHandler):
148
def get(self, resource):
149
resource = str(urllib.unquote(resource))
150
models = db.GqlQuery("SELECT * FROM ColladaModel WHERE model = '%s'" % resource)
151
if models.count() > 0:
152
model = (models.fetch(1))[0]
153
self.send_blob(model.model, save_as="model.dae")
155
application = webapp.WSGIApplication(
157
('/upload', UploadModel),
158
('/fiducial', FiducialUploader),
159
('/fiducialupload', UploadFiducial),
160
('/download/([^/]+)?', Download)],
164
run_wsgi_app(application)
166
if __name__ == "__main__":