mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-14 17:57:08 +00:00
edit logbooks, new logbook format, increased database normalisation
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from django.forms import ModelForm
|
||||
from models import Cave, Person, LogbookEntry, QM
|
||||
from models import Cave, Person, PersonExpedition, LogbookEntry, QM
|
||||
import django.forms as forms
|
||||
from django.forms.formsets import formset_factory
|
||||
from django.contrib.admin.widgets import AdminDateWidget
|
||||
import string
|
||||
from datetime import date
|
||||
from tinymce.widgets import TinyMCE
|
||||
|
||||
class CaveForm(ModelForm):
|
||||
class Meta:
|
||||
@@ -45,4 +46,43 @@ class LogbookEntryForm(ModelForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(LogbookEntryForm, self).__init__(*args, **kwargs)
|
||||
self.fields['text'].help_text=self.wikiLinkHints()
|
||||
self.fields['text'].help_text=self.wikiLinkHints()
|
||||
|
||||
def getTripForm(expedition):
|
||||
|
||||
class TripForm(forms.Form):
|
||||
date = forms.DateField()
|
||||
title = forms.CharField(max_length=200)
|
||||
caves = [cave.reference() for cave in Cave.objects.all()]
|
||||
caves.sort()
|
||||
caves = ["-----"] + caves
|
||||
cave = forms.ChoiceField([(c, c) for c in caves], required=False)
|
||||
location = forms.CharField(max_length=200, required=False)
|
||||
caveOrLocation = forms.ChoiceField([("cave", "Cave"), ("location", "Location")], widget = forms.widgets.RadioSelect())
|
||||
html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
||||
|
||||
def clean(self):
|
||||
print dir(self)
|
||||
if self.cleaned_data.get("caveOrLocation") == "cave" and not self.cleaned_data.get("cave"):
|
||||
self._errors["cave"] = self.error_class(["This field is required"])
|
||||
if self.cleaned_data.get("caveOrLocation") == "location" and not self.cleaned_data.get("location"):
|
||||
self._errors["location"] = self.error_class(["This field is required"])
|
||||
return self.cleaned_data
|
||||
|
||||
class PersonTripForm(forms.Form):
|
||||
def get_name(pe):
|
||||
if pe.nickname:
|
||||
return pe.nickname
|
||||
else:
|
||||
return pe.person.first_name
|
||||
names = [get_name(pe) for pe in PersonExpedition.objects.filter(expedition = expedition)]
|
||||
names.sort()
|
||||
names = ["-----"] + names
|
||||
name = forms.ChoiceField([(n, n) for n in names])
|
||||
TU = forms.FloatField(required=False)
|
||||
author = forms.BooleanField(required=False)
|
||||
|
||||
PersonTripFormSet = formset_factory(PersonTripForm, extra=1)
|
||||
|
||||
return PersonTripFormSet, TripForm
|
||||
|
||||
|
||||
Reference in New Issue
Block a user