From 599c59454a12a0cc4f9c7b0d88a5c1d8e054d2f2 Mon Sep 17 00:00:00 2001 From: Martin Green Date: Sat, 7 Jan 2012 19:05:25 +0000 Subject: [PATCH] Render a cave editing page. Nb it does not do save anything yet. --- core/forms.py | 38 ++++++++++++++++++++++++++++++++------ core/views_caves.py | 25 ++++++++++++++++++------- templates/cavebase.html | 1 + templates/editcave2.html | 18 ++++++++++++++++++ templates/menu.html | 1 + urls.py | 4 ++-- 6 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 templates/editcave2.html 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 .... +
{% csrf_token %} + {{ form }}{{caveAndEntranceFormSet}}
+

+
+ +{% 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 @@
  • Handbook
  • Reports
  • {% if editable %}
  • Edit this page
  • {% endif %} +{% if cave_editable %}
  • Edit this cave
  • {% endif %} {% endif %} diff --git a/urls.py b/urls.py index ea0ce0a..02bd134 100644 --- a/urls.py +++ b/urls.py @@ -57,7 +57,7 @@ actualurlpatterns = patterns('', url(r'^jgtuploadfile$', view_surveys.jgtuploadfile, name="jgtuploadfile"), url(r'^cave/(?P[^/]+)/?(?P[^/])$', ent), - #(r'^cave/(?P[^/]+)/edit/$', edit_cave), + url(r'^cave/(?P[^/]+)/edit/$', edit_cave, name="edit_cave"), #(r'^cavesearch', caveSearch), @@ -83,7 +83,7 @@ actualurlpatterns = patterns('', url(r'^eyecandy$', views_other.eyecandy), (r'^admin/doc/?', include('django.contrib.admindocs.urls')), - url(r'^admin/(.*)', admin.site.root, name="admin"), + url(r'^admin/(.*)', admin.site.get_urls, name="admin"), # don't know why this needs troggle/ in here. nice to get it out url(r'^troggle/media-admin/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ADMIN_DIR, 'show_indexes':True}),