Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

add printing template endpoint #5

Merged
merged 1 commit into from
Jul 12, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions geonode/printing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
4 changes: 4 additions & 0 deletions geonode/printing/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from geonode.printing.models import PrintTemplate
from django.contrib import admin

admin.site.register(PrintTemplate)
1 change: 1 addition & 0 deletions geonode/printing/fixtures/initial_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"pk": 1, "model": "printing.printtemplate", "fields": {"contents": "<html width=\"{{ width|default:\"512\" }}\" height=\"{{ height|default:\"256\" }}\">\r\n <h1>{{ map_title }}</h1>\r\n <div id=\"mapframe\">\r\n {{ map_html|safe }}\r\n </div>\r\n</html>\r\n", "title": "Basic"}}]
12 changes: 12 additions & 0 deletions geonode/printing/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import models
from django.utils.translation import ugettext as _

class PrintTemplate(models.Model):
"""A template suitable for interpolation that can be printed with a map"""

title = models.CharField(_('Title'), max_length=30)
contents = models.TextField(_('Contents'))

def __unicode__(self):
return self.title

5 changes: 5 additions & 0 deletions geonode/printing/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.conf.urls.defaults import patterns, url

urlpatterns = patterns('geonode.printing.views',
url(r'^template/(?P<templateid>\d+)$', 'template_view', name='template_view'),
)
15 changes: 15 additions & 0 deletions geonode/printing/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.template import Context
from django.template import Template
from geonode.printing.models import PrintTemplate


def template_view(request, templateid):
"""interpolate the template with the given id"""

template_obj = get_object_or_404(PrintTemplate, pk=templateid)
template = Template(template_obj.contents)
context = Context(request.GET)
rendered = template.render(context)
return HttpResponse(rendered, content_type="text/html")
1 change: 1 addition & 0 deletions geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
'geonode.maps',
'geonode.layers',
'geonode.people',
'geonode.printing',
'geonode.proxy',
'geonode.security',
)
Expand Down
3 changes: 3 additions & 0 deletions geonode/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
(r'^people/', include('geonode.people.urls')),
(r'^avatar/', include('avatar.urls')),

# Printing
(r'^printing/', include('geonode.printing.urls')),

# Meta
url(r'^lang\.js$', 'django.views.generic.simple.direct_to_template',
{'template': 'lang.js', 'mimetype': 'text/javascript'}, name='lang'),
Expand Down