This commit is contained in:
Martin 2012-08-14 23:49:26 +02:00
commit 71289d9b0f
8 changed files with 63 additions and 24 deletions

View File

@ -16,12 +16,21 @@ class CaveForm(ModelForm):
underground_centre_line = forms.CharField(required = False, widget=forms.Textarea()) underground_centre_line = forms.CharField(required = False, widget=forms.Textarea())
notes = forms.CharField(required = False, widget=forms.Textarea()) notes = forms.CharField(required = False, widget=forms.Textarea())
references = forms.CharField(required = False, widget=forms.Textarea()) references = forms.CharField(required = False, widget=forms.Textarea())
slug = forms.CharField(required = True)
url = forms.CharField(required = True) url = forms.CharField(required = True)
class Meta: class Meta:
model = Cave model = Cave
exclude = ("filename",) exclude = ("filename",)
def clean(self):
if self.cleaned_data.get("kataster_number") == "" and self.cleaned_data.get("unofficial_number") == "":
self._errors["unofficial_number"] = self.error_class(["Either the kataster or unoffical number is required."])
if self.cleaned_data.get("kataster_number") != "" and self.cleaned_data.get("official_name") == "":
self._errors["official_name"] = self.error_class(["This field is required when there is a kataster number."])
if self.cleaned_data.get("area") == []:
self._errors["area"] = self.error_class(["This field is required."])
return self.cleaned_data
class VersionControlCommentForm(forms.Form): class VersionControlCommentForm(forms.Form):
description_of_change = forms.CharField(required = True, widget=forms.Textarea()) description_of_change = forms.CharField(required = True, widget=forms.Textarea())
@ -41,7 +50,6 @@ class EntranceForm(ModelForm):
northing = forms.CharField(required=False) # Trying to change this to a singl;e line entry northing = forms.CharField(required=False) # Trying to change this to a singl;e line entry
easting = forms.CharField(required=False) # Trying to change this to a singl;e line entry easting = forms.CharField(required=False) # Trying to change this to a singl;e line entry
alt = forms.CharField(required=False) # Trying to change this to a singl;e line entry alt = forms.CharField(required=False) # Trying to change this to a singl;e line entry
slug = forms.CharField()
class Meta: class Meta:
model = Entrance model = Entrance
exclude = ("cached_primary_slug", "filename",) exclude = ("cached_primary_slug", "filename",)
@ -50,6 +58,11 @@ class EntranceForm(ModelForm):
CaveAndEntranceFormSet = modelformset_factory(CaveAndEntrance, exclude=('cave')) CaveAndEntranceFormSet = modelformset_factory(CaveAndEntrance, exclude=('cave'))
class EntranceLetterForm(ModelForm):
class Meta:
model = CaveAndEntrance
exclude = ('cave', 'entrance')
#class PersonForm(ModelForm): #class PersonForm(ModelForm):
# class Meta: # class Meta:
# model = Person # model = Person

View File

@ -577,13 +577,13 @@ class Entrance(TroggleModel):
def find_location(self): def find_location(self):
if self.tag_station: if self.tag_station:
s = SurvexStation.objects.lookup(self.tag_station) s = SurvexStation.objects.lookup(self.tag_station)
return "%sE %sN %sAlt" % (s.x, s.y, s.z) return "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z)
if self.exact_station: if self.exact_station:
s = SurvexStation.objects.lookup(self.exact_station) s = SurvexStation.objects.lookup(self.exact_station)
return "%sE %sN %sAlt" % (s.x, s.y, s.z) return "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z)
if self.other_station: if self.other_station:
s = SurvexStation.objects.lookup(self.other_station) s = SurvexStation.objects.lookup(self.other_station)
return "%sE %sN %sAlt %s" % (s.x, s.y, s.z, self.other_description) return "%0.0fE %0.0fN %0.0fAlt %s" % (s.x, s.y, s.z, self.other_description)
if self.bearings: if self.bearings:
return self.bearings return self.bearings

View File

@ -1,5 +1,5 @@
from troggle.core.models import CaveSlug, Cave, CaveAndEntrance, Survey, Expedition, QM, CaveDescription, EntranceSlug, Entrance, Area from troggle.core.models import CaveSlug, Cave, CaveAndEntrance, Survey, Expedition, QM, CaveDescription, EntranceSlug, Entrance, Area
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm
import troggle.core.models as models import troggle.core.models as models
import troggle.settings as settings import troggle.settings as settings
from troggle.helper import login_required_if_public from troggle.helper import login_required_if_public
@ -104,11 +104,21 @@ def edit_cave(request, slug=None):
versionControlForm = VersionControlCommentForm(request.POST) versionControlForm = VersionControlCommentForm(request.POST)
if form.is_valid() and ceFormSet.is_valid() and versionControlForm.is_valid(): if form.is_valid() and ceFormSet.is_valid() and versionControlForm.is_valid():
cave = form.save(commit = False) cave = form.save(commit = False)
cave.filename = form.cleaned_data["slug"] + ".html" if slug is None:
for a in form.cleaned_data["area"]:
if a.kat_area():
myArea = a.kat_area()
if form.cleaned_data["kataster_number"]:
myslug = "%s-%s" % (myArea, form.cleaned_data["kataster_number"])
else:
myslug = "%s-%s" % (myArea, form.cleaned_data["unofficial_number"])
else:
myslug = slug
cave.filename = myslug + ".html"
cave.save() cave.save()
form.save_m2m() form.save_m2m()
if slug is None: if slug is None:
cs = CaveSlug(cave = cave, slug = form.cleaned_data["slug"], primary = True) cs = CaveSlug(cave = cave, slug = myslug, primary = True)
cs.save() cs.save()
ceinsts = ceFormSet.save(commit=False) ceinsts = ceFormSet.save(commit=False)
for ceinst in ceinsts: for ceinst in ceinsts:
@ -129,7 +139,8 @@ def edit_cave(request, slug=None):
}) })
@login_required_if_public @login_required_if_public
def editEntrance(request, slug=None): def editEntrance(request, caveslug, slug=None):
cave = Cave.objects.get(caveslug__slug = caveslug)
if slug is not None: if slug is not None:
entrance = Entrance.objects.get(entranceslug__slug = slug) entrance = Entrance.objects.get(entranceslug__slug = slug)
else: else:
@ -137,25 +148,38 @@ def editEntrance(request, slug=None):
if request.POST: if request.POST:
form = EntranceForm(request.POST, instance = entrance) form = EntranceForm(request.POST, instance = entrance)
versionControlForm = VersionControlCommentForm(request.POST) versionControlForm = VersionControlCommentForm(request.POST)
if form.is_valid() and versionControlForm.is_valid(): if slug is None:
entletter = EntranceLetterForm(request.POST)
else:
entletter = None
if form.is_valid() and versionControlForm.is_valid() and (slug is not None or entletter.is_valid()):
entrance = form.save(commit = False) entrance = form.save(commit = False)
entrance.filename = form.cleaned_data["slug"] + ".html"
if slug is None: if slug is None:
entrance.cached_primary_slug = form.cleaned_data["slug"] slugname = cave.slug() + entletter.cleaned_data["entrance_letter"]
entrance.cached_primary_slug = slugname
entrance.filename = slugname + ".html"
entrance.save() entrance.save()
if slug is None: if slug is None:
es = EntranceSlug(entrance = entrance, slug = form.cleaned_data["slug"], primary = True) es = EntranceSlug(entrance = entrance, slug = slugname, primary = True)
es.save() es.save()
el = entletter.save(commit = False)
el.cave = cave
el.entrance = entrance
el.save()
entrance.writeDataFile() entrance.writeDataFile()
return HttpResponseRedirect("/" + entrance.url) return HttpResponseRedirect("/" + cave.url)
else: else:
form = EntranceForm(instance = entrance) form = EntranceForm(instance = entrance)
versionControlForm = VersionControlCommentForm() versionControlForm = VersionControlCommentForm()
if slug is None:
entletter = EntranceLetterForm(request.POST)
else:
entletter = None
return render_with_context(request, return render_with_context(request,
'editentrance.html', 'editentrance.html',
{'form': form, {'form': form,
'versionControlForm': versionControlForm 'versionControlForm': versionControlForm,
'entletter': entletter
}) })
def qm(request,cave_id,qm_id,year,grade=None): def qm(request,cave_id,qm_id,year,grade=None):

View File

@ -8,6 +8,8 @@ import re
def readcaves(): def readcaves():
newArea = models.Area(short_name = "1623", parent = None) newArea = models.Area(short_name = "1623", parent = None)
newArea.save() newArea.save()
newArea = models.Area(short_name = "1626", parent = None)
newArea.save()
print "Entrances" print "Entrances"
for filename in os.walk(settings.ENTRANCEDESCRIPTIONS).next()[2]: #Should be a better way of getting a list of files for filename in os.walk(settings.ENTRANCEDESCRIPTIONS).next()[2]: #Should be a better way of getting a list of files
readentrance(filename) readentrance(filename)

View File

@ -7,7 +7,7 @@
{{ ent.entrance_letter|safe }} {{ ent.entrance_letter|safe }}
{% if ent.entrance.name %} {% if ent.entrance.name %}
{{ ent.entrance.name|safe }} {{ ent.entrance.name|safe }}
{% endif %}<a href="{% url editentrance ent.entrance.slug %}">Edit</a> {% endif %}<a href="{% url editentrance cave.slug ent.entrance.slug %}">Edit</a>
<dl> <dl>
{% if ent.entrance.marking %} {% if ent.entrance.marking %}
<dt>Marking</dt><dd>{{ ent.entrance.marking_val|safe }}</dd> <dt>Marking</dt><dd>{{ ent.entrance.marking_val|safe }}</dd>
@ -67,5 +67,5 @@
</ul> </ul>
{% endif %}</p> {% endif %}</p>
<a href="{% url newentrance %}">New Entrance</a> <a href="{% url newentrance cave.slug %}">New Entrance</a>
</div> </div>

View File

@ -10,7 +10,7 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
<table>{{ form }}</table> <table>{{entletter}}{{ form }}</table>
{{ versionControlForm }} {{ versionControlForm }}
<p><input type="submit" value="Submit" /></p> <p><input type="submit" value="Submit" /></p>
</form> </form>

View File

@ -14,7 +14,7 @@
{% for name, area in areas %} {% for name, area in areas %}
<h2>{{name|safe}}</h2> <h2>{{name|safe}}</h2>
<table border=\"1\" width="100%"> <table border=\"1\" width="100%">
<col><col><col><col><col><col><col><col><col width="35%"> <col><col><col><col><col><col><col><col><col width="45%">
<thead> <thead>
<tr><th>Cave Number</th><th>Name</th><th>Finished</th><th>Survey<br>Data</th><th>Survey<br>Drawn</th><th>Marked</th><th>Photo</th><th>Position</th><th>Location</th></tr> <tr><th>Cave Number</th><th>Name</th><th>Finished</th><th>Survey<br>Data</th><th>Survey<br>Drawn</th><th>Marked</th><th>Photo</th><th>Position</th><th>Location</th></tr>
</thead> </thead>
@ -31,7 +31,7 @@
<td>{{ cave.caveandentrance_set.all.0.entrance.has_photo }} </td> <td>{{ cave.caveandentrance_set.all.0.entrance.has_photo }} </td>
<td>{{ cave.caveandentrance_set.all.0.entrance.find_location }}</td> <td>{{ cave.caveandentrance_set.all.0.entrance.find_location }}</td>
<td>{% if cave.caveandentrance_set.all.0.entrance.location_description %}Location: {{ cave.caveandentrance_set.all.0.entrance.location_description|safe }}{% endif %} <td>{% if cave.caveandentrance_set.all.0.entrance.location_description %}Location: {{ cave.caveandentrance_set.all.0.entrance.location_description|safe }}{% endif %}
{% if cave.caveandentrance_set.all.0.entrance.map_description %}Map: {{ cave.caveandentrance_set.all.0.entrance.map_description|safe }}{% endif %} {% if cave.caveandentrance_set.all.0.entrance.map_description %}Map: {{ cave.caveandentrance_set.all.0.entrance.map_description|safe }}{% endif %}
{% if cave.caveandentrance_set.all.0.entrance.approach %}Approach: {{ cave.caveandentrance_set.all.0.entrance.approach|safe }}{% endif %}</td> {% if cave.caveandentrance_set.all.0.entrance.approach %}Approach: {{ cave.caveandentrance_set.all.0.entrance.approach|safe }}{% endif %}</td>
</tr> </tr>
{% else %} {% else %}

View File

@ -51,8 +51,8 @@ actualurlpatterns = patterns('',
url(r'^cave/description/([^/]+)/?$', views_caves.caveDescription), url(r'^cave/description/([^/]+)/?$', views_caves.caveDescription),
url(r'^cave/qms/([^/]+)/?$', views_caves.caveQMs), url(r'^cave/qms/([^/]+)/?$', views_caves.caveQMs),
url(r'^cave/logbook/([^/]+)/?$', views_caves.caveLogbook), url(r'^cave/logbook/([^/]+)/?$', views_caves.caveLogbook),
url(r'^entrance/(?P<slug>[^/]+)/edit/', views_caves.editEntrance, name = "editentrance"), url(r'^entrance/(?P<caveslug>[^/]+)/(?P<slug>[^/]+)/edit/', views_caves.editEntrance, name = "editentrance"),
url(r'^entrance/new/', views_caves.editEntrance, name = "newentrance"), url(r'^entrance/new/(?P<caveslug>[^/]+)/', views_caves.editEntrance, name = "newentrance"),
#url(r'^cavedescription/(?P<cavedescription_name>[^/]+)/?$', views_caves.cave_description, name="cavedescription"), #url(r'^cavedescription/(?P<cavedescription_name>[^/]+)/?$', views_caves.cave_description, name="cavedescription"),
#url(r'^cavedescription/?$', object_list, {'queryset':CaveDescription.objects.all(),'template_name':'object_list.html'}, name="cavedescriptions"), #url(r'^cavedescription/?$', object_list, {'queryset':CaveDescription.objects.all(),'template_name':'object_list.html'}, name="cavedescriptions"),
#url(r'^cavehref/(.+)$', views_caves.cave, name="cave"),url(r'cave'), #url(r'^cavehref/(.+)$', views_caves.cave, name="cave"),url(r'cave'),