From fd12e70f7818f42f7f569576369dec287fec7ccc Mon Sep 17 00:00:00 2001 From: Martin Green Date: Wed, 23 May 2012 09:23:40 +0100 Subject: [PATCH] Editing for entrances along with caves More detailed display of entrances --- core/forms.py | 38 +++++++++++------------ core/views_caves.py | 22 +++++++------ templates/cave_entrances.html | 58 +++++++++++++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 32 deletions(-) diff --git a/core/forms.py b/core/forms.py index b16aa15..c38a699 100644 --- a/core/forms.py +++ b/core/forms.py @@ -9,34 +9,32 @@ from datetime import date from tinymce.widgets import TinyMCE class CaveForm(ModelForm): - underground_description = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30})) - explorers = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - equipment = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - survey = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - kataster_status = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - underground_centre_line = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - notes = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - references = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) + underground_description = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 30})) + explorers = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) + equipment = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) + survey = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) + kataster_status = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) + underground_centre_line = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) + notes = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) + references = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) class Meta: model = Cave +class CaveAndEntranceForm(forms.Form): + entrance = forms.ChoiceField(choices=[("", "-----")] + + [(x.slug, x.slug) + for x + in Entrance.objects.all()]) + entrance_letter = forms.CharField(max_length=20) + non_public = forms.BooleanField() + +CaveAndEntranceFormSet = formset_factory(CaveAndEntranceForm) + class EntranceForm(ModelForm): class Meta: model = Entrance -class CaveForm(ModelForm): - underground_description = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30})) - explorers = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - equipment = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - survey = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - kataster_status = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - underground_centre_line = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - notes = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - references = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - class Meta: - model = Cave - #class PersonForm(ModelForm): # class Meta: # model = Person diff --git a/core/views_caves.py b/core/views_caves.py index 71fe668..8dc2ebe 100644 --- a/core/views_caves.py +++ b/core/views_caves.py @@ -1,5 +1,5 @@ from troggle.core.models import Cave, CaveAndEntrance, Survey, Expedition, QM, CaveDescription, Entrance -from troggle.core.forms import CaveForm +from troggle.core.forms import CaveForm, CaveAndEntranceFormSet import troggle.core.models as models import troggle.settings as settings from troggle.helper import login_required_if_public @@ -42,6 +42,7 @@ def caveEntrance(request, slug): return render_with_context(request,'nonpublic.html', {'instance': cave}) else: return render_with_context(request,'cave_entrances.html', {'cave': cave}) + def caveDescription(request, slug): cave = Cave.objects.get(slug = slug) if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): @@ -71,14 +72,17 @@ def caveSlug(request, slug): @login_required_if_public def edit_cave(request, slug=None): cave = Cave.objects.get(slug = slug) - form = CaveForm(instance=cave) - class CaveAndEntranceForm(forms.Form): - entrance = forms.ChoiceField(choices=[("", "-----")] + [(x.slug, x.slug) for x in Entrance.objects.all()]) - entrance_letter = forms.CharField(max_length=20) - non_public = forms.BooleanField() - CaveAndEntranceFormSet = formset_factory(CaveAndEntranceForm) - i = [{"entrance": x.entrance.slug, "entrance_letter": x.entrance_letter, "non_public": x.non_public} for x in cave.caveandentrance_set.all()] - ceFormSet = CaveAndEntranceFormSet(initial=i) + if request.POST: + form = CaveForm(request.POST, instance=cave) + ceFormSet = CaveAndEntranceFormSet(request.POST) + else: + form = CaveForm(instance=cave) + i = [{"entrance": x.entrance.slug, + "entrance_letter": x.entrance_letter, + "non_public": x.non_public} + for x + in cave.caveandentrance_set.all()] + ceFormSet = CaveAndEntranceFormSet(initial=i) return render_with_context(request, 'editcave2.html', {'form': form, diff --git a/templates/cave_entrances.html b/templates/cave_entrances.html index dbd450d..e871e41 100644 --- a/templates/cave_entrances.html +++ b/templates/cave_entrances.html @@ -1,12 +1,64 @@

{% if cave.entrances %}

Entrances

+ {% endif %}