Making entrances work for pending caves

This commit is contained in:
Philip Sargent
2021-04-26 02:10:45 +01:00
parent a656ada67a
commit 72fa8a5883
7 changed files with 143 additions and 61 deletions

View File

@@ -60,7 +60,7 @@ class SimpleTest(SimpleTestCase):
import troggle.core.views.expo
from troggle.core.models.troggle import Expedition
from troggle.core.models.caves import CaveSlug, Cave, CaveAndEntrance, QM, EntranceSlug, Entrance, Area, SurvexStation
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, EntranceForm, EntranceLetterForm
from troggle.core.views.login import login_required_if_public
from django.contrib.auth.decorators import login_required
from django.conf import settings

View File

@@ -54,10 +54,10 @@ class CaveForm(ModelForm):
self._errors["url"] = self.error_class(["This field cannot start with a /."])
return self.cleaned_data
class VersionControlCommentForm(forms.Form):
'''Was appended to all forms. Not used currently
'''
description_of_change = forms.CharField(required = True, widget=forms.Textarea(attrs={'rows':2}))
# class VersionControlCommentForm(forms.Form):
# '''Was appended to all forms. Not used currently
# '''
# description_of_change = forms.CharField(required = True, widget=forms.Textarea(attrs={'rows':2}))
class EntranceForm(ModelForm):

View File

@@ -5,6 +5,7 @@ import re
import json
from subprocess import call
from collections import defaultdict
from pathlib import Path
from urllib.parse import urljoin
@@ -22,6 +23,20 @@ from django.template import Context, loader
from troggle.core.models.troggle import TroggleModel, Person, Expedition, DataIssue
from troggle.core.models.survex import SurvexStation
'''The model declarations for Areas, Caves and Entrances. Also LogBookENtry, QM, PersonTrip
'''
todo='''- Move utility function into utils.py
- Find out why we have separate objects CaveSlug and EntranceSlug and why
these are not just a single field on the Model. Do we ever need more
than one slug per cave or entrance? Surely that would break everything??
- Move PersonTrip to be with Person and Expedition elsewhere
- Restore constraint: unique_together = (("area", "kataster_number"), ("area", "unofficial_number"))
'''
class Area(TroggleModel):
short_name = models.CharField(max_length=100)
name = models.CharField(max_length=200, blank=True, null=True)
@@ -344,6 +359,9 @@ class Entrance(TroggleModel):
self.save()
return self.cached_primary_slug
def get_file_path(self):
return Path(settings.ENTRANCEDESCRIPTIONS, self.filename)
def writeDataFile(self):
try:
f = open(os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename), "w")

View File

@@ -18,7 +18,8 @@ import troggle.settings as settings
from troggle.core.views import expo
from troggle.core.models.troggle import Expedition, DataIssue
from troggle.core.models.caves import CaveSlug, Cave, CaveAndEntrance, QM, EntranceSlug, Entrance, Area, SurvexStation, GetCaveLookup
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, EntranceForm, EntranceLetterForm
#from troggle.core.forms import VersionControlCommentForm
from .login import login_required_if_public
'''Manages the complex procedures to assemble a cave description out of the compnoents
@@ -323,7 +324,7 @@ def edit_cave(request, slug=None):
if request.POST:
form = CaveForm(request.POST, instance=cave)
ceFormSet = CaveAndEntranceFormSet(request.POST)
versionControlForm = VersionControlCommentForm(request.POST)
#versionControlForm = VersionControlCommentForm(request.POST)
if form.is_valid() and ceFormSet.is_valid():
#print(f'! POST is valid. {cave}')
cave = form.save(commit = False)
@@ -397,8 +398,6 @@ def edit_entrance(request, caveslug=None, slug=None):
slugname = cave.slug() + entletter.cleaned_data["entrance_letter"]
else:
slugname = cave.slug()
# Converting a PENDING cave to a real cave by saving this form
slugname = slugname.replace('-PENDING-', '-')
entrance.cached_primary_slug = slugname
entrance.filename = slugname + ".html"
entrance.save()

View File

@@ -32,7 +32,7 @@ todo = '''
- But how does this interact with troggle/logbooksdump.py ?
- deleted nefile() - check on deleted UploadFileForm using the editfile.html template which is about re-submitting
- deleted newfile() - check on deleted UploadFileForm using the editfile.html template which is about re-submitting
a LBE aka TripReport
'''
@@ -44,12 +44,16 @@ def todos(request, module):
from troggle.core.TESTS.tests import todo as tests
from troggle.core.views.logbooks import todo as viewlogbooks
from troggle.parsers.logbooks import todo as parserslogbooks
from troggle.parsers.survex import todo as parserssurvex
from troggle.core.models.caves import todo as modelcaves
from troggle.core.forms import todo as forms
from troggle.core.templatetags.wiki_markup import todo as wiki
tododict = {'views/other': todo,
'tests': tests,
'views/logbooks': viewlogbooks,
'parsers/logbooks': parserslogbooks,
'parsers/survex': parserssurvex,
'core/models/caves': modelcaves,
'core/forms': forms,
'core/templatetags/wiki_markup': wiki}
return render(request,'core/todos.html', {'tododict': tododict})