diff --git a/core/forms.py b/core/forms.py index 7063f23..b16aa15 100644 --- a/core/forms.py +++ b/core/forms.py @@ -1,15 +1,41 @@ from django.forms import ModelForm -from models import Cave, Person, PersonExpedition, LogbookEntry, QM, Expedition +from models import Cave, Person, PersonExpedition, LogbookEntry, QM, Expedition, Entrance, CaveAndEntrance import django.forms as forms from django.forms.formsets import formset_factory +from django.forms.models 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: -# model = Cave +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 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: @@ -48,8 +74,8 @@ from tinymce.widgets import TinyMCE # super(LogbookEntryForm, self).__init__(*args, **kwargs) # self.fields['text'].help_text=self.wikiLinkHints()# -class CaveForm(forms.Form): - html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30})) +#class CaveForm(forms.Form): +# html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30})) def getTripForm(expedition): diff --git a/core/views_caves.py b/core/views_caves.py index 9fcf9b4..71fe668 100644 --- a/core/views_caves.py +++ b/core/views_caves.py @@ -1,10 +1,11 @@ -from troggle.core.models import Cave, CaveAndEntrance, Survey, Expedition, QM, CaveDescription +from troggle.core.models import Cave, CaveAndEntrance, Survey, Expedition, QM, CaveDescription, Entrance from troggle.core.forms import CaveForm import troggle.core.models as models import troggle.settings as settings from troggle.helper import login_required_if_public from django.forms.models import formset_factory +from django import forms from django.core.urlresolvers import reverse from utils import render_with_context # see views_logbooks for explanation on this. from django.http import HttpResponseRedirect @@ -63,16 +64,26 @@ def caveLogbook(request, slug): def caveSlug(request, slug): cave = Cave.objects.get(slug = slug) if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): - return render_with_context(request,'nonpublic.html', {'instance': cave}) + return render_with_context(request,'nonpublic.html', {'instance': cave, 'cave_editable': slug}) else: - return render_with_context(request,'cave.html', {'cave': cave}) + return render_with_context(request,'cave.html', {'cave': cave, 'cave_editable': slug}) @login_required_if_public -def editCave(request, slug=None): - form = CaveForm() +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) return render_with_context(request, - 'editcave.html', - {'form': form}) + 'editcave2.html', + {'form': form, + 'caveAndEntranceFormSet': ceFormSet + }) def qm(request,cave_id,qm_id,year,grade=None): year=int(year) diff --git a/templates/cavebase.html b/templates/cavebase.html index a0ffd4d..b3505a7 100644 --- a/templates/cavebase.html +++ b/templates/cavebase.html @@ -13,6 +13,7 @@ $( "#tabs" ).tabs(); }); +{% block extraheaders %}{% endblock %}
{% block content %}{% endblock %} diff --git a/templates/editcave2.html b/templates/editcave2.html new file mode 100644 index 0000000..feb4498 --- /dev/null +++ b/templates/editcave2.html @@ -0,0 +1,18 @@ +{% extends "cavebase.html" %} +{% load csrffaker %} +{% block title %}Edit Cave{% endblock %} +{% block extraheaders %} + + + + + +{% endblock %} +{% block content %} + This form does not do anything .... yet .... + + +{% endblock %} diff --git a/templates/menu.html b/templates/menu.html index 65b8544..bea6067 100644 --- a/templates/menu.html +++ b/templates/menu.html @@ -8,5 +8,6 @@