Compare commits

...

12 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
James Turk
d3dc25efbe updated changelog 2010-03-04 16:15:53 -05:00
James Turk
1491458861 convert Decimals too 2010-03-04 15:03:06 -05:00
James Turk
b62b4020cd warn when POI.actions is a dict 2010-03-03 14:44:44 -05:00
James Turk
8e992566e1 typo in setup.py -- fixes github #1 2010-03-03 14:17:00 -05:00
James Turk
392e417956 removed installation blurb, people can use pip/easy_install/setup.py whatever they want 2009-10-28 16:57:37 -04:00
James Turk
0fbaa899dc doc shuffle 2009-10-28 16:47:13 -04:00
James Turk
7213274fc9 add doc link 2009-10-23 14:50:33 -04:00
James Turk
616237e95a add doc link 2009-10-23 14:50:16 -04:00
10 changed files with 117 additions and 40 deletions

View File

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

19
CHANGELOG.rst Normal file
View File

@ -0,0 +1,19 @@
=========
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,3 +1,6 @@
License
=======
Copyright (c) 2009, Sunlight Foundation Copyright (c) 2009, Sunlight Foundation
All rights reserved. All rights reserved.

1
MANIFEST.in Normal file
View File

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

13
README Normal file
View File

@ -0,0 +1,13 @@
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

@ -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

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

View File

@ -1,3 +1,4 @@
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
@ -35,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``
dictionary mapping names of actions to URIs 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
@ -52,22 +66,36 @@ 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): if isinstance(self.lat, (float, Decimal)):
d['lat'] = int(self.lat*1000000) d['lat'] = int(self.lat*1000000)
if isinstance(self.lon, float): if isinstance(self.lon, (float, Decimal)):
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 self.actions: if isinstance(self.actions, dict):
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'] = []
@ -104,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):
@ -115,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']
@ -122,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)
@ -150,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:
@ -173,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

@ -11,6 +11,8 @@ 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
============ ============
@ -18,15 +20,6 @@ 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
===== =====
@ -87,14 +80,3 @@ 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

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