2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 15:21:52 +00:00

[svn] 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.
Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8308 by aaron @ 3/16/2009 7:27 PM
This commit is contained in:
substantialnoninfringinguser 2009-05-13 06:09:55 +01:00
parent d6244e1ef3
commit 6137f8baaa
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"),