From 333705092f44003a133bfac38f620f54145a81e4 Mon Sep 17 00:00:00 2001 From: aaron Date: Mon, 16 Mar 2009 20:27:52 +0100 Subject: [PATCH] [svn r8308] Logbook entries are now at /YYYY-MM-DD/slug . Try editing a logbook entry title in the admin now. The django built in auto slug field is fun and javascripty. --- troggle/expo/admin.py | 1 + troggle/expo/models.py | 4 +++- troggle/expo/views_logbooks.py | 4 ++-- troggle/parsers/logbooks.py | 7 ++++++- troggle/templates/logbookentry.html | 2 ++ troggle/urls.py | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/troggle/expo/admin.py b/troggle/expo/admin.py index a1d4fe0bb..9b8a39987 100644 --- a/troggle/expo/admin.py +++ b/troggle/expo/admin.py @@ -24,6 +24,7 @@ class QMInline(admin.TabularInline): #class LogbookEntryAdmin(VersionAdmin): class LogbookEntryAdmin(admin.ModelAdmin): + prepopulated_fields = {'slug':("title",)} search_fields = ('title','expedition__year') #inlines = (QMInline,) #doesn't work because QM has two foreignkeys to Logbookentry- need workaround diff --git a/troggle/expo/models.py b/troggle/expo/models.py index 56fbf01ba..485468c84 100644 --- a/troggle/expo/models.py +++ b/troggle/expo/models.py @@ -10,6 +10,7 @@ import os from django.conf import settings import datetime from decimal import Decimal, getcontext +from django.core.urlresolvers import reverse getcontext().prec=2 #use 2 significant figures for decimal calculations from models_survex import * @@ -211,6 +212,7 @@ class LogbookEntry(TroggleModel): cave = models.ForeignKey('Cave',blank=True,null=True) place = models.CharField(max_length=100,blank=True,null=True) text = models.TextField() + slug = models.SlugField(max_length=100) #href = models.CharField(max_length=100) @@ -224,7 +226,7 @@ class LogbookEntry(TroggleModel): ordering = ('-date',) def get_absolute_url(self): - return settings.URL_ROOT + "/logbookentry/" + str(self.pk) + return settings.URL_ROOT + reverse('logbookentry',kwargs={'date':self.date,'slug':self.slug}) def __unicode__(self): return "%s: (%s)" % (self.date, self.title) diff --git a/troggle/expo/views_logbooks.py b/troggle/expo/views_logbooks.py index 13468dc25..894be2a4a 100644 --- a/troggle/expo/views_logbooks.py +++ b/troggle/expo/views_logbooks.py @@ -87,8 +87,8 @@ def newQMlink(logbookentry): nextQMnumber=biggestQMnumber+1 return settings.URL_ROOT + r'/admin/expo/qm/add/?' + r'found_by=' + str(logbookentry.pk) +'&number=' + str(nextQMnumber) -def logbookentry(request, logbookentry_pk): - logbookentry = LogbookEntry.objects.get(pk = logbookentry_pk) +def logbookentry(request, date, slug): + logbookentry = LogbookEntry.objects.get(date=date, slug=slug) return render_response(request, 'logbookentry.html', {'logbookentry': logbookentry, 'newQMlink':newQMlink(logbookentry)}) diff --git a/troggle/parsers/logbooks.py b/troggle/parsers/logbooks.py index 9566d2d38..976d71aa5 100644 --- a/troggle/parsers/logbooks.py +++ b/troggle/parsers/logbooks.py @@ -6,6 +6,8 @@ import troggle.expo.models as models from troggle.parsers.people import GetPersonExpeditionNameLookup from troggle.parsers.cavetab import GetCaveLookup +from django.template.defaultfilters import slugify + import csv import re import datetime @@ -286,7 +288,7 @@ def SetDatesFromLogbookEntries(expedition): # lprevlogbookentry = logbookentry # This combined date / number key is a weird way of doing things. Use the primary key instead. If we are going to use the date for looking up entries, we should set it up to allow multiple results. -# # order by date for setting the references + # order by date for setting the references # lprevlogbookentry = None # for logbookentry in expedition.logbookentry_set.order_by('date'): # if lprevlogbookentry and lprevlogbookentry.date == logbookentry.date: @@ -297,6 +299,9 @@ def SetDatesFromLogbookEntries(expedition): # logbookentry.href = "%s" % logbookentry.date # logbookentry.save() # lprevlogbookentry = logbookentry + for logbookentry in expedition.logbookentry_set.all(): + logbookentry.slug = slugify(logbookentry.title) + logbookentry.save() def LoadLogbookForExpedition(expedition): diff --git a/troggle/templates/logbookentry.html b/troggle/templates/logbookentry.html index 812197a7d..89069e885 100644 --- a/troggle/templates/logbookentry.html +++ b/troggle/templates/logbookentry.html @@ -56,7 +56,9 @@ {% endfor %} +{% if newQMlink %} Add QM found on this trip +{% endif %}
diff --git a/troggle/urls.py b/troggle/urls.py index f63393eec..409c8649e 100644 --- a/troggle/urls.py +++ b/troggle/urls.py @@ -23,7 +23,7 @@ urlpatterns = patterns('', url(r'^expedition/(\d+)$', views_logbooks.expedition, name="expedition"), url(r'^personexpedition/(?P[A-Z]*[a-z]*)[^a-zA-Z]*(?P[A-Z]*[a-z]*)/(?P\d+)/?$', views_logbooks.personexpedition, name="personexpedition"), - url(r'^logbookentry/(.+)$', views_logbooks.logbookentry,name="logbookentry"), + url(r'^logbookentry/(?P.*)/(?P.*)/?$', views_logbooks.logbookentry,name="logbookentry"), url(r'^survexblock/(.+)$', views_caves.survexblock, name="survexblock"), url(r'^cavehref/(.+)$', views_caves.cavehref, name="cave"),