We also wrote the following code in class. Tables for storing location (very simple version!): this goes in tables.py
:
db.define_table('location',
Field('name'),
Field('lat', 'double'),
Field('lon', 'double'),
)
We wrote the following code for the controller (put this e.g. in default.py). Note: the code has not been tested.
# Controller for UCSC map.
import json
MYSECRET = 'behappy'
def insert():
"""Format: as variables:
- secret
- name
- lat, lon
"""
secret = request.vars.secret
if secret != MYSECRET:
raise HTTP(400)
try:
name = request.vars.name
lat = float(request.vars.lat)
lon = float(request.vars.lon)
except Exception, e:
raise HTTP(400)
db.location.update_or_insert(db.location.name == name,
name = name,
lat = lat, lon = lon)
return dict(result='ok')
def getall():
"""Format: as variables:
- secret
"""
secret = request.vars.secret
if secret != MYSECRET:
raise HTTP(400)
rows = db(db.location.ALL).select().as_list()
return dict(result=rows)
This is how to attach images to a POST request. The rest of the code is unchanged from the HTTP code we gave in previous examples in class.
HttpPost request = new HttpPost(url);
HttpEntity fileEntity = new FileEntity(file, "image/jpeg");
request.setEntity(fileEntity);