Skip to content

Instantly share code, notes, and snippets.

@rukku
Forked from rburhum/urls.py
Created May 27, 2013 09:55
Show Gist options
  • Save rukku/5656238 to your computer and use it in GitHub Desktop.
Save rukku/5656238 to your computer and use it in GitHub Desktop.
...
url(r'^v1/tiles/(?P<tile_user>([^/]+))/(?P<tile_layer>([^/]+))/(?P<tile_zoom>(\d+))/(?P<tile_column>(\d+))/(?P<tile_row>(\d+))\.(?P<tile_format>([a-z]+))$', TileManager.as_view(), name='tile_manager'),
...
from django.http import HttpResponse, HttpResponseServerError
from ModestMaps.Core import Coordinate
from TileStache import getTile, parseConfigfile
from TileStache.Core import KnownUnknown
from django.contrib.auth.models import User
from django.views.generic import View
from django.contrib.sites.models import Site
#include my custom permission mixin see Django docs on several ways to do this
from utils import APIPermissionMixin
class TileManager(APIPermissionMixin, View):
"""
Returns tiles
"""
def get(self, request, *args, **kwargs):
try:
#the mixin already checked that the layers and users exist
user = User.objects.get(username__exact=kwargs['tile_user'])
config = parseConfigfile(user.get_profile().tile_config_file)
layer = config.layers[kwargs['tile_layer']]
coord = Coordinate(int(kwargs['tile_row']), int(kwargs['tile_column']), int(kwargs['tile_zoom']))
tile_mimetype, tile_content = getTile(layer, coord, kwargs['tile_format'], ignore_cached=False)
return HttpResponse(mimetype=tile_mimetype, content=tile_content)
except KnownUnknown, e:
return HttpResponseServerError(str(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment