Compare commits

..

No commits in common. "master" and "0.1.0" have entirely different histories.

10 changed files with 40 additions and 117 deletions

3
CHANGELOG Normal file
View File

@ -0,0 +1,3 @@
0.1.0 - October 22 2009
=======================
- initial working release

View File

@ -1,19 +0,0 @@
=========
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
====================
- fix packaging issues
- lat/lng conversion on Decimal objects
- warn when POI.actions is a dict
0.1.0 - October 22 2009
=======================
- initial working release

View File

@ -1,6 +1,3 @@
License
=======
Copyright (c) 2009, Sunlight Foundation Copyright (c) 2009, Sunlight Foundation
All rights reserved. All rights reserved.

View File

@ -1 +0,0 @@
include *.rst

13
README
View File

@ -1,13 +0,0 @@
django-layar
============
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.
django-layar is a project of Sunlight Labs (c) 2010.
Written by James Turk <jturk@sunlightfoundation.com>
Source: http://github.com/sunlightlabs/django-layar/
Documentation: http://packages.python.org/django-layar/README.html

View File

@ -11,8 +11,6 @@ Written by James Turk <jturk@sunlightfoundation.com>
Source: http://github.com/sunlightlabs/django-layar/ Source: http://github.com/sunlightlabs/django-layar/
Documentation: http://packages.python.org/django-layar/README.html
Requirements Requirements
============ ============
@ -20,6 +18,15 @@ python >= 2.4
django >= 1.0 django >= 1.0
Installation
============
To install run
``python setup.py install``
which will install the application into the site-packages directory.
Usage Usage
===== =====
@ -80,3 +87,14 @@ In urls.py it is then necessary to map a URL directly to ``busstop_layar``::
url(r'^layar_endpoint/$', 'myapp.views.busstop_layar'), url(r'^layar_endpoint/$', 'myapp.views.busstop_layar'),
) )
Additional Settings
-------------------
Your :class:`LayarView`-derived class can also set a number of options. These options should be suitable for most purposes as Layar doesn't display more than 50 points, but are available should you for any reason need to change them.
``results_per_page``
controls the number of results returned at once (default: 15)
``max_results``
controls the maximum number of results across all pages (default: 50)
``verify_hash``
set to False to disable hash verification (useful for testing, shouldn't be False in production)

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'2010, James Turk' copyright = u'2009, 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.2.0' version = '0.1.0'
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = '0.2.0' release = '0.1.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

@ -10,10 +10,8 @@ Contents:
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2
main README
layar-autodoc layar-autodoc
CHANGELOG
LICENSE
Indices and tables Indices and tables
================== ==================

View File

@ -1,4 +1,3 @@
from decimal import Decimal
from django.conf import settings from django.conf import settings
from django.http import HttpResponse, HttpResponseBadRequest from django.http import HttpResponse, HttpResponseBadRequest
from django.utils.hashcompat import sha_constructor as sha1 from django.utils.hashcompat import sha_constructor as sha1
@ -36,28 +35,15 @@ 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, can set meaning when publishing Layar numerical type (0-3), 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 dictionary mapping names of actions to URIs
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
@ -66,36 +52,22 @@ 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 self.type = type # must be 0..3
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):
d['lat'] = int(self.lat*1000000) d['lat'] = int(self.lat*1000000)
if isinstance(self.lon, (float, Decimal)): if isinstance(self.lon, float):
d['lon'] = int(self.lon*1000000) d['lon'] = int(self.lon*1000000)
# convert actions dictionary into expected format # convert actions dictionary into expected format
if isinstance(self.actions, dict): if self.actions:
raise DeprecationWarning('passing a dictionary for actions is deprecated - order will be lost')
d['actions'] = [{'label':k, 'uri':v} for k,v in self.actions.iteritems()] d['actions'] = [{'label':k, 'uri':v} for k,v in self.actions.iteritems()]
elif isinstance(self.actions, list):
pass
else: else:
d['actions'] = [] d['actions'] = []
@ -132,13 +104,10 @@ 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):
@ -146,9 +115,6 @@ 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']
@ -156,31 +122,12 @@ 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'])
# optional radius = int(request.GET['radius'])
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')
slider2 = request.GET.get('CUSTOM_SLIDER_2') page = int(request.GET.get('pageKey', 0))
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)
@ -203,10 +150,7 @@ 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,
search_query2=search2, search_query3=search3, slider_value=slider)[:self.max_results]
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:
@ -229,10 +173,6 @@ 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

@ -1,10 +1,10 @@
from distutils.core import setup from distutils.core import setup
long_description = open('README').read() long_description = open('README.rst').read()
setup( setup(
name='django-layar', name='django-layar',
version="0.2.0", version="0.1.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',