[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.
This commit is contained in:
aaron 2009-03-16 20:27:52 +01:00
parent 6f62771552
commit 333705092f
6 changed files with 15 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)})

View File

@ -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):

View File

@ -56,7 +56,9 @@
</tr>
{% endfor %}
</table>
{% if newQMlink %}
<a href="{{newQMlink}}">Add QM found on this trip</a>
{% endif %}
</div>
<div id="col1">

View File

@ -23,7 +23,7 @@ urlpatterns = patterns('',
url(r'^expedition/(\d+)$', views_logbooks.expedition, name="expedition"),
url(r'^personexpedition/(?P<first_name>[A-Z]*[a-z]*)[^a-zA-Z]*(?P<last_name>[A-Z]*[a-z]*)/(?P<year>\d+)/?$', views_logbooks.personexpedition, name="personexpedition"),
url(r'^logbookentry/(.+)$', views_logbooks.logbookentry,name="logbookentry"),
url(r'^logbookentry/(?P<date>.*)/(?P<slug>.*)/?$', views_logbooks.logbookentry,name="logbookentry"),
url(r'^survexblock/(.+)$', views_caves.survexblock, name="survexblock"),
url(r'^cavehref/(.+)$', views_caves.cavehref, name="cave"),