--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/qmsk/pngtile/pngtile.py Sat Oct 04 14:35:54 2014 +0300
@@ -0,0 +1,54 @@
+from __future__ import absolute_import
+
+from django.conf import settings
+import django.utils.http
+
+# the top-level pngtile package
+from pngtile.store import (
+ Error,
+ NotFound,
+ InvalidImage,
+ UncachedImage,
+ PNGTileStore,
+)
+
+class Store (PNGTileStore):
+ def __init__ (self, tileserver, **opts):
+ super(Store, self).__init__(**opts)
+
+ self.tileserver = tileserver
+
+ def breadcrumb (self, name):
+ """
+ Yield (name, title) tuples for breadcrumb to name
+ """
+
+ path = [ ]
+
+ for part in name.split('/'):
+ path.append(part)
+
+ yield '/'.join(path), part
+
+ def tiles_url (self, name, **query):
+ """
+ Return a tileserver URL.
+ """
+
+ url = self.tileserver
+
+ if name:
+ url += name
+
+ if query:
+ url += '?' + django.utils.http.urlencode(query)
+
+ return url
+
+STORE = Store(
+ # PNGTileStore
+ image_root = settings.QMSK_PNGTILE_ROOT,
+
+ # Store
+ tileserver = settings.QMSK_PNGTILE_SERVER,
+)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/qmsk/pngtile/templates/qmsk.pngtile/index.html Sat Oct 04 14:35:54 2014 +0300
@@ -0,0 +1,36 @@
+{% extends "site.html" %}
+
+{% block title %}{{ site_name }} :: {{ name }}{% endblock %}
+
+{% block header %}
+ <h1 class="page-header-title">
+ <a href="{% url 'index' '' %}">{{ site_name }}</a>
+ </h1>
+{% endblock %}
+
+{% block breadcrumb %}
+ <ol class="breadcrumb">
+ {% for name, title in breadcrumb %}
+ <li><a href="{% url 'index' name %}">{{ title }}</a></li>
+ {% endfor %}
+ </ol>
+{% endblock %}
+
+{% block nav %}
+ <ul class="nav">
+ {% for item in index_list %}
+ <li>
+ <a href="{{item}}">{{item}}</a>
+ </li>
+ {% endfor %}
+ </ul>
+{% endblock %}
+
+{% block content %}
+
+{% endblock %}
+
+{% block footer %}
+
+{% endblock %}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/qmsk/pngtile/urls.py Sat Oct 04 14:35:54 2014 +0300
@@ -0,0 +1,9 @@
+from django.conf.urls import patterns, include, url
+
+from qmsk.pngtile import views
+
+urlpatterns = patterns('',
+ url(r'^$', views.index, name='index', kwargs=dict(name='')),
+ url(r'^(?P<name>.*)/$', views.index, name='index'),
+ url(r'^(?P<name>.*\.\w+)$', views.image, name='image'),
+)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/qmsk/pngtile/views.py Sat Oct 04 14:35:54 2014 +0300
@@ -0,0 +1,30 @@
+from django import http
+from django.shortcuts import render, redirect
+
+from qmsk.pngtile import pngtile
+
+import pypngtile
+
+def index (request, name):
+ try:
+ items = pngtile.STORE.list(name)
+ except pngtile.NotFound:
+ raise http.Http404
+ except pngtile.InvalidImage:
+ return http.HttpResponseBadRequest(name)
+ except pngtile.UncachedImage:
+ return http.HttpResponseBadRequest(name)
+ except pngtile.Error as error:
+ return http.HttpResponseServerError(str(error))
+ except pypngtile.Error as error:
+ return http.HttpResponseServerError(str(error))
+
+ return render(request, 'qmsk.pngtile/index.html', dict(
+ site_name = u"...",
+ name = name,
+ breadcrumb = pngtile.STORE.breadcrumb(name),
+ index_list = items,
+ ))
+
+def image (request, name):
+ pass