add qr code view to site
This commit is contained in:
parent
989c2200eb
commit
ffbc0d9f29
2 changed files with 20 additions and 1 deletions
|
@ -1,9 +1,10 @@
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from c3nav.site.views import main, map_image
|
from c3nav.site.views import main, map_image, qr_code
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^map/(?P<level>[a-z0-9-_:]+)/(?P<area>[a-z0-9-_:]+).png$', map_image, name='site.level_image'),
|
url(r'^map/(?P<level>[a-z0-9-_:]+)/(?P<area>[a-z0-9-_:]+).png$', map_image, name='site.level_image'),
|
||||||
|
url(r'^qr/(?P<location>[a-z0-9-_:]+).png$', qr_code, name='site.qr'),
|
||||||
url(r'^l/(?P<location>[a-z0-9-_:]+)/$', main, name='site.location'),
|
url(r'^l/(?P<location>[a-z0-9-_:]+)/$', main, name='site.location'),
|
||||||
url(r'^o/(?P<origin>[a-z0-9-_:]+)/$', main, name='site.origin'),
|
url(r'^o/(?P<origin>[a-z0-9-_:]+)/$', main, name='site.origin'),
|
||||||
url(r'^d/(?P<destination>[a-z0-9-_:]+)/$', main, name='site.destination'),
|
url(r'^d/(?P<destination>[a-z0-9-_:]+)/$', main, name='site.destination'),
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from calendar import timegm
|
from calendar import timegm
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
import qrcode
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
from django.http import Http404, HttpResponse, HttpResponseNotModified
|
from django.http import Http404, HttpResponse, HttpResponseNotModified
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
|
@ -48,6 +49,23 @@ def get_location_or_404(request, location):
|
||||||
return location
|
return location
|
||||||
|
|
||||||
|
|
||||||
|
def qr_code(request, location):
|
||||||
|
location = get_location_or_404(request, location)
|
||||||
|
|
||||||
|
qr = qrcode.QRCode(
|
||||||
|
version=1,
|
||||||
|
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
||||||
|
box_size=10,
|
||||||
|
border=4,
|
||||||
|
)
|
||||||
|
qr.add_data(request.build_absolute_uri(reverse('site.location', kwargs={'location': location.location_id})))
|
||||||
|
qr.make(fit=True)
|
||||||
|
|
||||||
|
response = HttpResponse(content_type='image/png')
|
||||||
|
qr.make_image().save(response, 'PNG')
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def main(request, location=None, origin=None, destination=None):
|
def main(request, location=None, origin=None, destination=None):
|
||||||
location = get_location_or_404(request, location)
|
location = get_location_or_404(request, location)
|
||||||
origin = get_location_or_404(request, origin)
|
origin = get_location_or_404(request, origin)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue