2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-21 23:01:52 +00:00

Bug fixing of cave and entrance forms removal of slugs

This commit is contained in:
Martin 2012-08-14 22:51:15 +02:00
parent ecd5bbcb1d
commit 1a0e577606
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())
notes = 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)
class Meta:
model = Cave
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):
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
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
slug = forms.CharField()
class Meta:
model = Entrance
exclude = ("cached_primary_slug", "filename",)
@ -50,6 +58,11 @@ class EntranceForm(ModelForm):
CaveAndEntranceFormSet = modelformset_factory(CaveAndEntrance, exclude=('cave'))
class EntranceLetterForm(ModelForm):
class Meta:
model = CaveAndEntrance
exclude = ('cave', 'entrance')
#class PersonForm(ModelForm):
# class Meta:
# model = Person

View File

@ -571,13 +571,13 @@ class Entrance(TroggleModel):
def find_location(self):
if 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:
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:
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:
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.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm
import troggle.core.models as models
import troggle.settings as settings
from troggle.helper import login_required_if_public
@ -104,11 +104,21 @@ def edit_cave(request, slug=None):
versionControlForm = VersionControlCommentForm(request.POST)
if form.is_valid() and ceFormSet.is_valid() and versionControlForm.is_valid():
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()
form.save_m2m()
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()
ceinsts = ceFormSet.save(commit=False)
for ceinst in ceinsts:
@ -129,7 +139,8 @@ def edit_cave(request, slug=None):
})
@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:
entrance = Entrance.objects.get(entranceslug__slug = slug)
else:
@ -137,25 +148,38 @@ def editEntrance(request, slug=None):
if request.POST:
form = EntranceForm(request.POST, instance = entrance)
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.filename = form.cleaned_data["slug"] + ".html"
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()
if slug is None:
es = EntranceSlug(entrance = entrance, slug = form.cleaned_data["slug"], primary = True)
es.save()
es = EntranceSlug(entrance = entrance, slug = slugname, primary = True)
es.save()
el = entletter.save(commit = False)
el.cave = cave
el.entrance = entrance
el.save()
entrance.writeDataFile()
return HttpResponseRedirect("/" + entrance.url)
return HttpResponseRedirect("/" + cave.url)
else:
form = EntranceForm(instance = entrance)
versionControlForm = VersionControlCommentForm()
if slug is None:
entletter = EntranceLetterForm(request.POST)
else:
entletter = None
return render_with_context(request,
'editentrance.html',
{'form': form,
'versionControlForm': versionControlForm
'versionControlForm': versionControlForm,
'entletter': entletter
})
def qm(request,cave_id,qm_id,year,grade=None):

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@
{% for name, area in areas %}
<h2>{{name|safe}}</h2>
<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>
<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>
@ -31,7 +31,7 @@
<td>{{ cave.caveandentrance_set.all.0.entrance.has_photo }} </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 %}
{% 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>
</tr>
{% else %}

View File

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