Skip to content

Commit

Permalink
Public PDF for touristic contents/events (fixes #1206)
Browse files Browse the repository at this point in the history
  • Loading branch information
gutard committed Feb 23, 2015
1 parent 65a4bc5 commit c2d0551
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 7 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ tests: test test_js test_nav
serve:
bin/django runserver_plus --threaded $(listen)

services:
@echo "Stop convertit"
kill `netstat -tlp 2>/dev/null | grep ':6543' | sed 's;.*LISTEN \([0-9]*\)/python;\1;'`; true
@echo "Stop screamshotter"
kill `netstat -tlp 2>/dev/null | grep ':8001' | sed 's;.*LISTEN \([0-9]*\)/python;\1;'`; true
@echo "Start convertit"
bin/convertit lib/src/convertit/development.ini &
@echo "Start screamshotter"
bin/django runserver --settings=screamshotter.settings 8001 &

update:
bin/develop update -f
bin/django collectstatic --clear --noinput --verbosity=0
Expand Down
11 changes: 9 additions & 2 deletions geotrek/common/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-02-20 17:40+0100\n"
"POT-Creation-Date: 2015-02-23 14:12+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -83,8 +83,15 @@ msgstr "Thèmes"
msgid "Topology is not valid."
msgstr "L'événement n'est pas valide"

msgid ""
"This project is co-financed by the European Union through FEDER Massif Alpin."
msgstr "Ce projet est co-financé par l'Union Européenne au travers du FEDER Massif Alpin"

msgid "Powered by http://geotrek.fr"
msgstr "Propulsé par http://geotrek.fr"

msgid "Any year"
msgstr "N'import quelle année"
msgstr "N'importe quelle année"

msgid "Paths"
msgstr "Tronçons"
Expand Down
3 changes: 3 additions & 0 deletions geotrek/common/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.core.exceptions import ValidationError
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.shortcuts import render
from django.contrib.auth.decorators import login_required, user_passes_test
Expand Down Expand Up @@ -56,6 +57,8 @@ def get_context_data(self, **kwargs):
modelname = self.get_model()._meta.object_name.lower()
context['object'] = self.get_object()
context['mapimage_ratio'] = settings.EXPORT_MAP_IMAGE_SIZE[modelname]
context['financed_by'] = _('This project is co-financed by the European Union through FEDER Massif Alpin.')
context['powered_by'] = _('Powered by http://geotrek.fr')
return context

def render_to_response(self, context, **response_kwargs):
Expand Down
6 changes: 5 additions & 1 deletion geotrek/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,14 @@ def gettext_noop(s):
EXPORT_MAP_IMAGE_SIZE = {
'trek': (14.1, 11),
'poi': (14.1, 11),
'touristiccontent': (14.1, 11),
'touristicevent': (14.1, 11),
}
EXPORT_HEADER_IMAGE_SIZE = {
'trek': (10.7, 5.035), # Keep ratio of THUMBNAIL_ALIASES['print']
'poi': (10.7, 5.035) # Keep ratio of THUMBNAIL_ALIASES['print']
'poi': (10.7, 5.035), # Keep ratio of THUMBNAIL_ALIASES['print']
'touristiccontent': (10.7, 5.035), # Keep ratio of THUMBNAIL_ALIASES['print']
'touristicevent': (10.7, 5.035), # Keep ratio of THUMBNAIL_ALIASES['print']
}

COMPLETENESS_FIELDS = {
Expand Down
11 changes: 10 additions & 1 deletion geotrek/tourism/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-02-20 17:40+0100\n"
"POT-Creation-Date: 2015-02-23 15:13+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -243,6 +243,9 @@ msgstr "Évènement touristique"
msgid "Touristic events"
msgstr "Évènements touristiques"

msgid "from {begin} to {end}"
msgstr "du {begin} au {end}"

msgid "Tourism"
msgstr "Tourisme"

Expand All @@ -261,6 +264,12 @@ msgstr "Pas de résultat"
msgid "Choose value(s)"
msgstr "Choisir valeur(s)"

msgid "Public print"
msgstr "Impression grand public"

msgid "Print"
msgstr "Impr."

msgid "Thumbnail"
msgstr "Aperçu"

Expand Down
46 changes: 46 additions & 0 deletions geotrek/tourism/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.contrib.gis.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.functional import lazy
from django.utils.formats import date_format

from easy_thumbnails.alias import aliases
from easy_thumbnails.exceptions import InvalidImageFormatError
Expand Down Expand Up @@ -295,6 +296,32 @@ class Meta:
def __unicode__(self):
return self.name

@models.permalink
def get_document_public_url(self):
""" Override ``geotrek.common.mixins.PublishableMixin``
"""
return ('tourism:touristiccontent_document_public', [str(self.pk)])

@property
def districts_display(self):
return ', '.join([unicode(d) for d in self.districts])

@property
def type1_label(self):
return self.category.type1_label

@property
def type2_label(self):
return self.category.type2_label

@property
def types1_display(self):
return ', '.join([unicode(n) for n in self.type1.all()])

@property
def types2_display(self):
return ', '.join([unicode(n) for n in self.type2.all()])

Topology.add_property('touristic_contents', lambda self: intersecting(TouristicContent, self, distance=settings.TOURISM_INTERSECTION_MARGIN), _(u"Touristic contents"))
TouristicContent.add_property('touristic_contents', lambda self: intersecting(TouristicContent, self, distance=settings.TOURISM_INTERSECTION_MARGIN), _(u"Touristic contents"))

Expand Down Expand Up @@ -359,6 +386,12 @@ class Meta:
def __unicode__(self):
return self.name

@models.permalink
def get_document_public_url(self):
""" Override ``geotrek.common.mixins.PublishableMixin``
"""
return ('tourism:touristicevent_document_public', [str(self.pk)])

@property
def type1(self):
return [self.type] if self.type else []
Expand All @@ -367,6 +400,19 @@ def type1(self):
def type2(self):
return []

@property
def districts_display(self):
return ', '.join([unicode(d) for d in self.districts])

@property
def dates_display(self):
if self.begin_date == self.end_date:
return date_format(self.begin_date, 'SHORT_DATE_FORMAT')
else:
return _(u"from {begin} to {end}").format(
begin=date_format(self.begin_date, 'SHORT_DATE_FORMAT'),
end=date_format(self.end_date, 'SHORT_DATE_FORMAT'))

TouristicEvent.add_property('touristic_contents', lambda self: intersecting(TouristicContent, self, distance=settings.TOURISM_INTERSECTION_MARGIN), _(u"Touristic events"))
Topology.add_property('touristic_events', lambda self: intersecting(TouristicEvent, self, distance=settings.TOURISM_INTERSECTION_MARGIN), _(u"Touristic events"))
TouristicContent.add_property('touristic_events', lambda self: intersecting(TouristicEvent, self, distance=settings.TOURISM_INTERSECTION_MARGIN), _(u"Touristic events"))
Expand Down
12 changes: 11 additions & 1 deletion geotrek/tourism/templates/tourism/touristiccontent_detail.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{% extends "mapentity/mapentity_detail.html" %}
{% load i18n mapentity_tags %}
{% load i18n static mapentity_tags %}


{% block download %}
{{ block.super }}
</div>

<div class="btn-group pull-right">
<a class="btn btn-mini" href="{% url 'tourism:touristiccontent_printable' object.pk %}" title="{% trans "Public print" %}" target="_blank"><img src="{% static "paperclip/fileicons/pdf.png" %}"/> {% trans "Print" %}</a>
{% endblock download %}


{% block detailspanel %}
<table class="table-striped table-bordered table">
Expand Down
Binary file not shown.
12 changes: 11 additions & 1 deletion geotrek/tourism/templates/tourism/touristicevent_detail.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{% extends "mapentity/mapentity_detail.html" %}
{% load i18n mapentity_tags %}
{% load i18n static mapentity_tags %}


{% block download %}
{{ block.super }}
</div>

<div class="btn-group pull-right">
<a class="btn btn-mini" href="{% url 'tourism:touristicevent_printable' object.pk %}" title="{% trans "Public print" %}" target="_blank"><img src="{% static "paperclip/fileicons/pdf.png" %}"/> {% trans "Print" %}</a>
{% endblock download %}


{% block detailspanel %}
<table class="table-striped table-bordered table">
Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions geotrek/tourism/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@


class TouristicContentEntityOptions(PublishableEntityOptions):
document_public_view = tourism_views.TouristicContentDocumentPublic

def get_serializer(self):
return tourism_serializers.TouristicContentSerializer

Expand All @@ -31,6 +33,8 @@ def get_queryset(self):


class TouristicEventEntityOptions(PublishableEntityOptions):
document_public_view = tourism_views.TouristicEventDocumentPublic

def get_serializer(self):
return tourism_serializers.TouristicEventSerializer

Expand Down
48 changes: 47 additions & 1 deletion geotrek/tourism/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
from mapentity.views import (JSONResponseMixin, MapEntityCreate,
MapEntityUpdate, MapEntityLayer, MapEntityList,
MapEntityDetail, MapEntityDelete, MapEntityViewSet,
MapEntityFormat)
MapEntityFormat, MapEntityDocument)
from mapentity.serializers import plain_text
from rest_framework import generics as rest_generics
from rest_framework import permissions as rest_permissions

from geotrek.authent.decorators import same_structure_required
from geotrek.common.views import DocumentPublic
from geotrek.tourism.models import DataSource, InformationDesk

from .filters import TouristicContentFilterSet, TouristicEventFilterSet
Expand Down Expand Up @@ -178,6 +180,28 @@ def dispatch(self, *args, **kwargs):
return super(TouristicContentDelete, self).dispatch(*args, **kwargs)


class TouristicContentDocument(MapEntityDocument):
queryset = TouristicContent.objects.existing()


class TouristicContentDocumentPublic(DocumentPublic):
queryset = TouristicContent.objects.existing()

def get_context_data(self, **kwargs):
context = super(TouristicContentDocumentPublic, self).get_context_data(**kwargs)
content = self.get_object()

context['headerimage_ratio'] = settings.EXPORT_HEADER_IMAGE_SIZE['touristiccontent']

# Replace HTML text with plain text
for attr in ['description', 'description_teaser', 'contact', 'practical_info']:
setattr(content, attr, plain_text(getattr(content, attr)))

context['object'] = context['content'] = content

return context


class TouristicEventLayer(MapEntityLayer):
queryset = TouristicEvent.objects.existing()
properties = ['name']
Expand Down Expand Up @@ -232,6 +256,28 @@ def dispatch(self, *args, **kwargs):
return super(TouristicEventDelete, self).dispatch(*args, **kwargs)


class TouristicEventDocument(MapEntityDocument):
queryset = TouristicEvent.objects.existing()


class TouristicEventDocumentPublic(DocumentPublic):
queryset = TouristicEvent.objects.existing()

def get_context_data(self, **kwargs):
context = super(TouristicEventDocumentPublic, self).get_context_data(**kwargs)
event = self.get_object()

context['headerimage_ratio'] = settings.EXPORT_HEADER_IMAGE_SIZE['touristiccontent']

# Replace HTML text with plain text
for attr in ['description', 'description_teaser', 'contact', 'booking', 'practical_info']:
setattr(event, attr, plain_text(getattr(event, attr)))

context['object'] = context['event'] = event

return context


class TouristicContentViewSet(MapEntityViewSet):
queryset = TouristicContent.objects.existing().transform(settings.API_SRID, field_name='geom')
serializer_class = TouristicContentSerializer
Expand Down

0 comments on commit c2d0551

Please sign in to comment.