Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve name support for tours

  • Loading branch information...
commit 8b9c75ed577b027d7bdbd5a86bd09e3b3e1d43f9 1 parent df1d97d
@cnorthwood cnorthwood authored
View
4 molly/apps/tours/models.py
@@ -10,6 +10,10 @@ class Tour(models.Model):
def get_absolute_url(self):
return reverse('tours:tour-start', args=[self.id])
+
+ def __unicode__(self):
+ return self.name
+
class StopOnTour(models.Model):
View
2  molly/apps/tours/templates/tours/index.html
@@ -14,7 +14,7 @@
</div>
<ul class="link-list">
{% for tour in tours %}
- <li><a href="{{ tour.get_absolute_url }}">{{ tour }}</a></li>
+ <li><a href="{{ tour.get_absolute_url }}">{{ tour.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
View
17 molly/apps/tours/views.py
@@ -1,3 +1,5 @@
+from datetime import datetime
+
from django.core.urlresolvers import reverse
from django.contrib.gis.measure import D
from django.db.models import Q
@@ -14,6 +16,7 @@
from molly.routing import generate_route, optimise_points
from molly.apps.tours.models import Tour, StopOnTour
+
class IndexView(BaseView):
@BreadcrumbFactory
@@ -38,6 +41,7 @@ def initial_context(self, request):
def handle_GET(self, request, context):
return self.render(request, context, 'tours/index')
+
class CreateView(BaseView):
@BreadcrumbFactory
@@ -89,8 +93,14 @@ def handle_GET(self, request, context, entities):
context['entities'] = optimise_points([(entity, entity.location) for entity in context['entities']])
context['optimised_entities'] = True
+ # Come up with a name for this tour
+ name = _('Visiting %(number)d places (created on %(creation)s)') % {
+ 'number': len(context['entities']),
+ 'creation': datetime.now().strftime('%c')
+ }
+
# Save back to database
- tour = Tour.objects.create()
+ tour = Tour.objects.create(name=name)
for i, entity in enumerate(context['entities']):
StopOnTour.objects.create(entity=entity, tour=tour, order=i)
@@ -112,12 +122,15 @@ def handle_GET(self, request, context, entities):
return super(SaveView, self).handle_GET(request, context, entities)
+
class PdfView(BaseView):
pass
+
class PodcastView(BaseView):
pass
+
class TourView(BaseView):
@BreadcrumbFactory
@@ -126,7 +139,7 @@ def breadcrumb(self, request, context, tour, page=None):
return Breadcrumb(
self.conf.local_name,
lazy_parent('index'),
- context['stop'].entity.title if page else _('Tour'),
+ context['stop'].entity.title if page else context['tour'].name,
lazy_reverse('tour', args=(context['tour'].pk, page)),
)
Please sign in to comment.
Something went wrong with that request. Please try again.