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>""" % '/upload')#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 = self.request.get('model')#str((self.get_uploads('model'))[0].key())
60
# Testing model compression to gz
61
cModel = zlib.compressobj()
62
cModel.compress(collada.model)
63
collada.compress = cModel.flush()
65
# Get and assign fiducial marker
66
fiducials = db.GqlQuery("SELECT * FROM Fiducial WHERE used = False")
67
if fiducials.count() > 0:
69
marker = (fiducials.fetch(1))[0]
71
# Currently stores string, fix later
72
collada.fiducial = marker.name
73
marker.model = collada.author
75
# Send an email with an attachment
77
(sender="jnoraky@gmail.com",
81
Attached is your ARTag. Print it and bring it to your destination.
82
Your unique ARTag identifier is %s. This will be used to load your
87
attachments=[(marker.name, marker.pic)]
90
# Disable ARTag for other models
98
def redirect(self, uri, permanent=False):
100
msg = "Model successfully written to the database. Please \
101
check your email for the ARTag!"
103
# Add debug info later
104
msg = "Sorry, your model could not be uploaded. Please \
106
self.response.out.write(
109
<script language="javascript" type="text/javascript">
111
window.location="%s";
117
# For use only in development. In actual instantiation, all
118
# fiducial markers will be loaded beforehand.
119
class FiducialUploader(webapp.RequestHandler):
121
self.response.out.write("""
123
<head><title>Fiducial Uploader</title></head>
125
<form action="/fiducialupload" enctype="multipart/form-data" method="POST">
126
Please enter the marker name:<br>
127
<input name="marker" type="text" size="30">
129
Please upload the image of the fiducial:<br>
130
<input name="pic" type="file">
132
Please upload the pattern file of the fiducial:<br>
133
<input name="fiducial" type="file">
135
<input type="submit" value="Submit">
141
class UploadFiducial(webapp.RequestHandler):
143
fiducial = Fiducial()
144
fiducial.name = self.request.get('marker')
145
fiducial.pic = db.Blob(self.request.get('pic'))
146
fiducial.marker = db.Blob(self.request.get('fiducial'))
147
fiducial.used = False
149
self.redirect('/fiducial')
151
class Download(webapp.RequestHandler):
152
def get(self, resource):
153
resource = str(urllib.unquote(resource))
154
models = db.GqlQuery("SELECT * FROM ColladaModel WHERE author= 'jnoraky@gmail.com'")
155
if models.count() > 0:
156
model = (models.fetch(1))[0]
157
self.response.headers['Content-Type'] = 'text/xml'
158
dModel = zlib.decompressobj()
159
dModel.decompress(model.compress)
160
self.response.out.write(dModel.flush())
163
# Currently will download first entry in db query list
164
class Download(blobstore_handlers.BlobstoreDownloadHandler):
165
def get(self, resource):
166
resource = str(urllib.unquote(resource))
167
models = db.GqlQuery("SELECT * FROM ColladaModel WHERE model = '%s'" % resource)
168
if models.count() > 0:
169
model = (models.fetch(1))[0]
170
self.send_blob(model.model, save_as="model.dae")
172
application = webapp.WSGIApplication(
174
('/upload', UploadModel),
175
('/fiducial', FiducialUploader),
176
('/fiducialupload', UploadFiducial),
177
('/download/([^/]+)?', Download)],
181
run_wsgi_app(application)
183
if __name__ == "__main__":