2009-05-13 05:22:38 +01:00
|
|
|
from django.forms import ModelForm
|
2009-06-10 00:05:02 +01:00
|
|
|
from models import Cave, Person, LogbookEntry, QM
|
2009-05-13 06:13:31 +01:00
|
|
|
import django.forms as forms
|
|
|
|
from django.forms.formsets import formset_factory
|
|
|
|
from django.contrib.admin.widgets import AdminDateWidget
|
|
|
|
import string
|
2009-05-13 05:22:38 +01:00
|
|
|
|
|
|
|
class CaveForm(ModelForm):
|
|
|
|
class Meta:
|
2009-05-13 05:48:10 +01:00
|
|
|
model = Cave
|
|
|
|
|
|
|
|
class PersonForm(ModelForm):
|
|
|
|
class Meta:
|
2009-05-13 06:08:04 +01:00
|
|
|
model = Person
|
2009-05-13 06:13:31 +01:00
|
|
|
|
|
|
|
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())
|
|
|
|
|
2009-05-13 06:14:42 +01:00
|
|
|
# res.append(r'</p><p style="float: left; "><b>People</b>')
|
|
|
|
# for persontrip in LogbookEntry.instance.persontrip_set.all():
|
|
|
|
# res.append(persontrip.wiki_link())
|
|
|
|
# res.append(r'</p>')
|
2009-05-13 06:13:31 +01:00
|
|
|
|
|
|
|
return string.join(res, r'<br />')
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(LogbookEntryForm, self).__init__(*args, **kwargs)
|
2009-06-10 00:05:02 +01:00
|
|
|
self.fields['text'].help_text=self.wikiLinkHints()
|
|
|
|
|
|
|
|
class QMsFoundInlineForm(ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = QM
|
|
|
|
exclude = 'ticked_off_by'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(QMsFoundInlineForm, self).__init__(*args, **kwargs)
|
|
|
|
#self.fields['number'].initial=nextQMinyear()#work on that one
|
|
|
|
|
|
|
|
|