mirror of
https://expo.survex.com/repositories/expoweb/.git/
synced 2024-11-27 01:32:03 +00:00
[svn r8314] Added wikilink hints to logbook admin page. Also added some inlines in admin
Change get_absolute_url methods to use reverse() to decouple from urlconf.
This commit is contained in:
parent
5438ce9d60
commit
c9d1b31207
@ -2,6 +2,7 @@ from troggle.expo.models import *
|
||||
from django.contrib import admin
|
||||
from django.forms import ModelForm
|
||||
import django.forms as forms
|
||||
from expo.forms import LogbookEntryForm
|
||||
#from troggle.reversion.admin import VersionAdmin #django-reversion version control
|
||||
|
||||
class RoleInline(admin.TabularInline):
|
||||
@ -22,15 +23,29 @@ class QMInline(admin.TabularInline):
|
||||
model=QM
|
||||
extra = 4
|
||||
|
||||
class PhotoInline(admin.TabularInline):
|
||||
model = Photo
|
||||
exclude = ['is_mugshot', ]
|
||||
extra = 1
|
||||
|
||||
class PersonTripInline(admin.TabularInline):
|
||||
model = PersonTrip
|
||||
exclude = ['persontrip_next','Delete']
|
||||
extra = 1
|
||||
|
||||
#class LogbookEntryAdmin(VersionAdmin):
|
||||
class LogbookEntryAdmin(admin.ModelAdmin):
|
||||
prepopulated_fields = {'slug':("title",)}
|
||||
search_fields = ('title','expedition__year')
|
||||
inlines = (PersonTripInline, PhotoInline)
|
||||
form = LogbookEntryForm
|
||||
#inlines = (QMInline,) #doesn't work because QM has two foreignkeys to Logbookentry- need workaround
|
||||
|
||||
class PersonExpeditionInline(admin.TabularInline):
|
||||
model = PersonExpedition
|
||||
extra = 1
|
||||
|
||||
|
||||
|
||||
class PersonAdmin(admin.ModelAdmin):
|
||||
search_fields = ('first_name','last_name')
|
||||
|
@ -1,5 +1,9 @@
|
||||
from django.forms import ModelForm
|
||||
from models import Cave, Person
|
||||
from models import Cave, Person, LogbookEntry
|
||||
import django.forms as forms
|
||||
from django.forms.formsets import formset_factory
|
||||
from django.contrib.admin.widgets import AdminDateWidget
|
||||
import string
|
||||
|
||||
class CaveForm(ModelForm):
|
||||
class Meta:
|
||||
@ -8,3 +12,29 @@ class CaveForm(ModelForm):
|
||||
class PersonForm(ModelForm):
|
||||
class Meta:
|
||||
model = Person
|
||||
|
||||
class LogbookEntryForm(ModelForm):
|
||||
class Meta:
|
||||
model = LogbookEntry
|
||||
|
||||
def wikiLinkHints(LogbookEntry=None):
|
||||
res = ["Please use the following wikilinks, which are related to this logbook entry:"]
|
||||
|
||||
res.append(r'</p><p style="float: left;"><b>QMs found:</b>')
|
||||
for QM in LogbookEntry.instance.QMs_found.all():
|
||||
res.append(QM.wiki_link())
|
||||
|
||||
res.append(r'</p><p style="float: left;"><b>QMs ticked off:</b>')
|
||||
for QM in LogbookEntry.instance.QMs_ticked_off.all():
|
||||
res.append(QM.wiki_link())
|
||||
|
||||
res.append(r'</p><p style="float: left; "><b>People</b>')
|
||||
for persontrip in LogbookEntry.instance.persontrip_set.all():
|
||||
res.append(QM.wiki_link())
|
||||
res.append(r'</p>')
|
||||
|
||||
return string.join(res, r'<br />')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(LogbookEntryForm, self).__init__(*args, **kwargs)
|
||||
self.fields['text'].help_text=self.wikiLinkHints()
|
@ -39,7 +39,9 @@ class Expedition(TroggleModel):
|
||||
get_latest_by = 'date_from'
|
||||
|
||||
def get_absolute_url(self):
|
||||
return settings.URL_ROOT + "/expedition/%s" % self.year
|
||||
#return settings.URL_ROOT + "/expedition/%s" % self.year
|
||||
return settings.URL_ROOT + reverse('expedition',args=[self.year])
|
||||
|
||||
|
||||
# lose these two functions (inelegant, and we may create a file with the dates that we can load from)
|
||||
def GuessDateFrom(self):
|
||||
@ -87,7 +89,7 @@ class Person(TroggleModel):
|
||||
#bisnotable = models.BooleanField()
|
||||
user = models.OneToOneField(User, null=True, blank=True)
|
||||
def get_absolute_url(self):
|
||||
return settings.URL_ROOT + "/person/%s_%s/" % (self.first_name, self.last_name)
|
||||
return settings.URL_ROOT + reverse('person',kwargs={'first_name':self.first_name,'last_name':self.last_name})
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "People"
|
||||
@ -202,7 +204,8 @@ class PersonExpedition(TroggleModel):
|
||||
return self.person.first_name
|
||||
|
||||
def get_absolute_url(self):
|
||||
return settings.URL_ROOT + '/personexpedition/' + str(self.person.first_name) + '_' + str(self.person.last_name) + '/' +self.expedition.year
|
||||
#return settings.URL_ROOT + '/personexpedition/' + str(self.person.first_name) + '_' + str(self.person.last_name) + '/' +self.expedition.year
|
||||
return settings.URL_ROOT + reverse('personexpedition',kwargs={'first_name':self.person.first_name,'last_name':self.person.last_name,'year':self.expedition.year})
|
||||
|
||||
class LogbookEntry(TroggleModel):
|
||||
date = models.DateField()
|
||||
@ -249,8 +252,8 @@ class PersonTrip(TroggleModel):
|
||||
logbook_entry = models.ForeignKey(LogbookEntry)
|
||||
is_logbook_entry_author = models.BooleanField()
|
||||
|
||||
persontrip_next = models.ForeignKey('PersonTrip', related_name='pnext', blank=True,null=True)
|
||||
persontrip_prev = models.ForeignKey('PersonTrip', related_name='pprev', blank=True,null=True)
|
||||
#persontrip_next = models.ForeignKey('PersonTrip', related_name='pnext', blank=True,null=True)
|
||||
#persontrip_prev = models.ForeignKey('PersonTrip', related_name='pprev', blank=True,null=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return "%s %s (%s)" % (self.person_expedition, self.place, self.date)
|
||||
@ -325,7 +328,9 @@ class Cave(TroggleModel):
|
||||
href = self.unofficial_number
|
||||
else:
|
||||
href = official_name.lower()
|
||||
return settings.URL_ROOT + '/cave/' + href + '/'
|
||||
#return settings.URL_ROOT + '/cave/' + href + '/'
|
||||
return settings.URL_ROOT + reverse('cave',kwargs={'cave_id':href,})
|
||||
|
||||
|
||||
|
||||
def __unicode__(self):
|
||||
@ -480,7 +485,8 @@ class QM(TroggleModel):
|
||||
return str(QMnumber)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return settings.URL_ROOT + '/cave/' + self.found_by.cave.kataster_number + '/' + str(self.found_by.date.year) + '-' + '%02d' %self.number
|
||||
#return settings.URL_ROOT + '/cave/' + self.found_by.cave.kataster_number + '/' + str(self.found_by.date.year) + '-' + '%02d' %self.number
|
||||
return settings.URL_ROOT + reverse('qm',kwargs={'cave_id':self.cave.kataster_number,'year':self.found_by.date.year,'qm_id':self.number,'grade':self.grade})
|
||||
|
||||
def get_next_by_id(self):
|
||||
return QM.objects.get(id=self.id+1)
|
||||
@ -488,10 +494,16 @@ class QM(TroggleModel):
|
||||
def get_previous_by_id(self):
|
||||
return QM.objects.get(id=self.id-1)
|
||||
|
||||
def wiki_link(self):
|
||||
res = '[[cave:' + str(self.found_by.cave.kataster_number) + ' '
|
||||
res += 'QM:' + str(self.found_by.date.year) + '-'
|
||||
res += str(self.number) + self.grade + ']]'
|
||||
return res
|
||||
|
||||
photoFileStorage = FileSystemStorage(location=settings.PHOTOS_ROOT, base_url=settings.PHOTOS_URL)
|
||||
class Photo(TroggleModel):
|
||||
caption = models.CharField(max_length=1000,blank=True,null=True)
|
||||
contains_person_trip = models.ManyToManyField(PersonTrip,blank=True,null=True)
|
||||
contains_logbookentry = models.ForeignKey(LogbookEntry,blank=True,null=True)
|
||||
contains_person = models.ManyToManyField(Person,blank=True,null=True)
|
||||
file = models.ImageField(storage=photoFileStorage, upload_to='.',)
|
||||
is_mugshot = models.BooleanField(default=False)
|
||||
|
@ -22,7 +22,7 @@ def caveindex(request):
|
||||
notablecaves = [Cave.objects.get(kataster_number=kataster_number) for kataster_number in notablecavehrefs ]
|
||||
return render_response(request,'caveindex.html', {'caves': caves, 'notablecaves':notablecaves})
|
||||
|
||||
def cavehref(request, cave_id='', offical_name=''):
|
||||
def cave(request, cave_id='', offical_name=''):
|
||||
return render_response(request,'cave.html', {'cave': getCave(cave_id),})
|
||||
|
||||
def qm(request,cave_id,qm_id,year,grade=None):
|
||||
|
Loading…
Reference in New Issue
Block a user