Compare commits

...

4 Commits

Author SHA1 Message Date
James Turk
5ee569ca03 s/custom_radius/default_radius 2010-03-29 14:38:40 -04:00
James Turk
c2858fa0fa add new POI attributes 2010-03-04 17:11:39 -05:00
James Turk
6a6b3af7d3 start developing 0.2.0 2010-03-04 16:47:50 -05:00
James Turk
fb46c3e18f new parameters 2010-03-04 16:43:08 -05:00
5 changed files with 75 additions and 13 deletions

View File

@ -2,6 +2,12 @@
Changelog Changelog
========= =========
0.2.0
================
- add custom radius handling
- made accuracy and radius optional
- new parameters: alt, search2/3, slider2/3, checkboxes
0.1.1 - March 4 2009 0.1.1 - March 4 2009
==================== ====================
- fix packaging issues - fix packaging issues

2
README
View File

@ -5,7 +5,7 @@ Django generic view for making `Layar <http://layar.com>`_ endpoints.
Provides abstract class that responds to Layar API requests in the appropriate format. By implementing two small functions it is possible to add a layer to the Layar augmented reality application for Android and iPhone. Provides abstract class that responds to Layar API requests in the appropriate format. By implementing two small functions it is possible to add a layer to the Layar augmented reality application for Android and iPhone.
django-layar is a project of Sunlight Labs (c) 2009. django-layar is a project of Sunlight Labs (c) 2010.
Written by James Turk <jturk@sunlightfoundation.com> Written by James Turk <jturk@sunlightfoundation.com>
Source: http://github.com/sunlightlabs/django-layar/ Source: http://github.com/sunlightlabs/django-layar/

View File

@ -42,16 +42,16 @@ master_doc = 'index'
# General information about the project. # General information about the project.
project = u'django-layar' project = u'django-layar'
copyright = u'2009, James Turk' copyright = u'2010, James Turk'
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = '0.1.0' version = '0.2.0'
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = '0.1.0' release = '0.2.0'
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.

View File

@ -36,15 +36,28 @@ class POI(object):
additional lines of detail (use special token %distance% to additional lines of detail (use special token %distance% to
display distance to POI) (<= 35 chars) display distance to POI) (<= 35 chars)
``type`` ``type``
numerical type (0-3), can set meaning when publishing Layar numerical type, can set meaning when publishing Layar
``attribution`` ``attribution``
bottom line of display, shown in small font (<= 45 chars) bottom line of display, shown in small font (<= 45 chars)
``dimension``
changes how POI is displayed (defaults to 1)
1 - point marker (default)
2 - image used for POI
3 - 3d object used for POI
``alt``
Real altitude of object in meters.
``relative_alt``
Relative altitude (in meters) of object with respect to user.
``actions`` ``actions``
list of dictionaries with 'label' and 'uri' keys list of dictionaries with ``label`` and ``uri`` keys
as of Layar v3 the dictionaries may optionally include
``autoTriggerOnly`` and ``autoTriggerOnly``
''' '''
def __init__(self, id, lat, lon, title, actions=None, image_url=None, def __init__(self, id, lat, lon, title, actions=None, image_url=None,
line2=None, line3=None, line4=None, type=0, attribution=None): line2=None, line3=None, line4=None, type=0, attribution=None,
dimension=1, alt=None, transform=None, object_detail=None,
relative_alt=None):
self.id = str(id) self.id = str(id)
self.lat = lat self.lat = lat
self.lon = lon self.lon = lon
@ -53,13 +66,24 @@ class POI(object):
self.line2 = line2 # recommended max len 35 self.line2 = line2 # recommended max len 35
self.line3 = line3 self.line3 = line3
self.line4 = line4 self.line4 = line4
self.type = type # must be 0..3 self.type = type
self.attribution = attribution # recommended max len 45 self.attribution = attribution # recommended max len 45
self.dimension = dimension
self.alt = alt
self.transform = transform
self.object = object_detail
self.relativeAlt = relative_alt
self.actions = actions self.actions = actions
def to_dict(self): def to_dict(self):
d = dict(self.__dict__) d = dict(self.__dict__)
# don't include optional attributes if not set
remove_if_none = ('alt', 'transform', 'object', 'relativeAlt')
for k in remove_if_none:
if not d[k]:
del d[k]
# do lat/long conversion # do lat/long conversion
if isinstance(self.lat, (float, Decimal)): if isinstance(self.lat, (float, Decimal)):
d['lat'] = int(self.lat*1000000) d['lat'] = int(self.lat*1000000)
@ -108,10 +132,13 @@ class LayarView(object):
controls the maximum number of results across all pages (default: 50) controls the maximum number of results across all pages (default: 50)
``verify_hash`` ``verify_hash``
set to False to disable hash verification (useful for testing) set to False to disable hash verification (useful for testing)
``default_radius``
radius to use if a radius is not passed
''' '''
results_per_page = 15 results_per_page = 15
max_results = 50 max_results = 50
default_radius = 1000
verify_hash = True verify_hash = True
def __init__(self): def __init__(self):
@ -119,6 +146,9 @@ class LayarView(object):
def __call__(self, request): def __call__(self, request):
try: try:
# parameters from http://layar.pbworks.com/GetPointsOfInterest
# required parameters
user_id = request.GET['userId'] user_id = request.GET['userId']
developer_id = request.GET['developerId'] developer_id = request.GET['developerId']
developer_hash = request.GET['developerHash'] developer_hash = request.GET['developerHash']
@ -126,12 +156,31 @@ class LayarView(object):
layer_name = request.GET['layerName'] layer_name = request.GET['layerName']
lat = float(request.GET['lat']) lat = float(request.GET['lat'])
lon = float(request.GET['lon']) lon = float(request.GET['lon'])
accuracy = int(request.GET['accuracy'])
radius = int(request.GET['radius']) # optional
accuracy = request.GET.get('accuracy')
if accuracy:
accuracy = int(accuracy)
radius = request.GET.get('radius')
if radius:
radius = int(radius)
alt = request.GET.get('alt')
if alt:
alt = int(alt)
page = int(request.GET.get('pageKey', 0))
# user defined UI elements
radio_option = request.GET.get('RADIOLIST') radio_option = request.GET.get('RADIOLIST')
search = request.GET.get('SEARCHBOX') search = request.GET.get('SEARCHBOX')
search2 = request.GET.get('SEARCHBOX_2')
search3 = request.GET.get('SEARCHBOX_3')
slider = request.GET.get('CUSTOM_SLIDER') slider = request.GET.get('CUSTOM_SLIDER')
page = int(request.GET.get('pageKey', 0)) slider2 = request.GET.get('CUSTOM_SLIDER_2')
slider3 = request.GET.get('CUSTOM_SLIDER_3')
checkboxes = request.GET.get('CHECKBOXLIST')
if checkboxes:
checkboxes = checkboxes.split(',')
except KeyError, e: except KeyError, e:
return HttpResponseBadRequest('missing required parameter: %s' % e) return HttpResponseBadRequest('missing required parameter: %s' % e)
@ -154,7 +203,10 @@ class LayarView(object):
qs = qs_func(latitude=lat, longitude=lon, radius=radius, qs = qs_func(latitude=lat, longitude=lon, radius=radius,
radio_option=radio_option, search_query=search, radio_option=radio_option, search_query=search,
slider_value=slider)[:self.max_results] search_query2=search2, search_query3=search3,
slider_value=slider, slider_value2=slider2,
slider_value3=slider3, checkboxes=checkboxes)
qs = qs[:self.max_results]
# do pagination if results_per_page is set # do pagination if results_per_page is set
if self.results_per_page: if self.results_per_page:
@ -177,6 +229,10 @@ class LayarView(object):
pois = [poi_func(item) for item in qs] pois = [poi_func(item) for item in qs]
layar_response['hotspots'] = [poi.to_dict() for poi in pois] layar_response['hotspots'] = [poi.to_dict() for poi in pois]
# if radius wasn't sent pass back the radius used
if not radius:
layar_response['radius'] = self.default_radius
except LayarException, e: except LayarException, e:
layar_response['errorCode'] = e.code layar_response['errorCode'] = e.code
layar_response['errorString'] = e.message layar_response['errorString'] = e.message

View File

@ -4,7 +4,7 @@ long_description = open('README').read()
setup( setup(
name='django-layar', name='django-layar',
version="0.1.0", version="0.2.0",
package_dir={'layar': 'layar'}, package_dir={'layar': 'layar'},
packages=['layar'], packages=['layar'],
description='helper for publishing data to Layar augmented reality browser from Django', description='helper for publishing data to Layar augmented reality browser from Django',