Removing editLogbookEntry capability

This commit is contained in:
Philip Sargent 2020-07-26 03:22:37 +01:00
parent 924c5a3bf8
commit 69b843a824
4 changed files with 76 additions and 76 deletions

View File

@ -73,6 +73,7 @@ class EntranceLetterForm(ModelForm):
model = CaveAndEntrance
exclude = ('cave', 'entrance')
#This was all commneted out by Martin Green in 2012 !
#class PersonForm(ModelForm):
# class Meta:
# model = Person

View File

@ -85,7 +85,6 @@ def get_absolute_url(self):
return ('expedition', (expedition.year))
class ExpeditionListView(ListView):
model = Expedition
def get_context_data(self, **kwargs):
@ -93,7 +92,6 @@ class ExpeditionListView(ListView):
context['now'] = timezone.now()
return context
def person(request, first_name='', last_name='', ):
this_person = Person.objects.get(first_name = first_name, last_name = last_name)
@ -168,82 +166,83 @@ def personForm(request,pk):
form=PersonForm(instance=person)
return render(request,'personform.html', {'form':form,})
@login_required_if_public
def newLogbookEntry(request, expeditionyear, pdate = None, pslug = None):
expedition = Expedition.objects.get(year=expeditionyear)
PersonTripFormSet, TripForm = getTripForm(expedition)
if pslug and pdate:
previousdate = datetime.date(*[int(x) for x in pdate.split("-")])
previouslbe = LogbookEntry.objects.get(slug = pslug, date = previousdate, expedition = expedition)
assert previouslbe.filename
if request.method == 'POST': # If the form has been submitted...
tripForm = TripForm(request.POST) # A form bound to the POST data
personTripFormSet = PersonTripFormSet(request.POST)
if tripForm.is_valid() and personTripFormSet.is_valid(): # All validation rules pass
dateStr = tripForm.cleaned_data["date"].strftime("%Y-%m-%d")
directory = os.path.join(settings.EXPOWEB,
"years",
expedition.year,
"autologbook")
filename = os.path.join(directory,
dateStr + "." + slugify(tripForm.cleaned_data["title"])[:50] + ".html")
if not os.path.isdir(directory):
os.mkdir(directory)
if pslug and pdate:
delLogbookEntry(previouslbe)
f = open(filename, "w")
template = loader.get_template('dataformat/logbookentry.html')
context = Context({'trip': tripForm.cleaned_data,
'persons': personTripFormSet.cleaned_data,
'date': dateStr,
'expeditionyear': expeditionyear})
f.write(template.render(context))
f.close()
print((logbookparsers.parseAutoLogBookEntry(filename)))
return HttpResponseRedirect(reverse('expedition', args=[expedition.year])) # Redirect after POST
else:
if pslug and pdate:
if previouslbe.cave:
tripForm = TripForm(initial={"date": previousdate,
"title": previouslbe.title,
"cave": previouslbe.cave.reference(),
"location": None,
"caveOrLocation": "cave",
"html": previouslbe.text})
else:
tripForm = TripForm(initial={"date": previousdate,
"title": previouslbe.title,
"cave": None,
"location": previouslbe.place,
"caveOrLocation": "location",
"html": previouslbe.text})
personTripFormSet = PersonTripFormSet(initial=[{"name": get_name(py.personexpedition),
"TU": py.time_underground,
"author": py.is_logbook_entry_author}
for py in previouslbe.persontrip_set.all()])
else:
tripForm = TripForm() # An unbound form
personTripFormSet = PersonTripFormSet()
# tried to delete all this, and the reference in urls.py, but got impenetrable django error message
# @login_required_if_public
# def newLogbookEntry(request, expeditionyear, pdate = None, pslug = None):
# expedition = Expedition.objects.get(year=expeditionyear)
# PersonTripFormSet, TripForm = getTripForm(expedition)
# if pslug and pdate:
# previousdate = datetime.date(*[int(x) for x in pdate.split("-")])
# previouslbe = LogbookEntry.objects.get(slug = pslug, date = previousdate, expedition = expedition)
# assert previouslbe.filename
# if request.method == 'POST': # If the form has been submitted...
# tripForm = TripForm(request.POST) # A form bound to the POST data
# personTripFormSet = PersonTripFormSet(request.POST)
# if tripForm.is_valid() and personTripFormSet.is_valid(): # All validation rules pass
# dateStr = tripForm.cleaned_data["date"].strftime("%Y-%m-%d")
# directory = os.path.join(settings.EXPOWEB,
# "years",
# expedition.year,
# "autologbook")
# filename = os.path.join(directory,
# dateStr + "." + slugify(tripForm.cleaned_data["title"])[:50] + ".html")
# if not os.path.isdir(directory):
# os.mkdir(directory)
# if pslug and pdate:
# delLogbookEntry(previouslbe)
# f = open(filename, "w")
# template = loader.get_template('dataformat/logbookentry.html')
# context = Context({'trip': tripForm.cleaned_data,
# 'persons': personTripFormSet.cleaned_data,
# 'date': dateStr,
# 'expeditionyear': expeditionyear})
# f.write(template.render(context))
# f.close()
# print((logbookparsers.parseAutoLogBookEntry(filename)))
# return HttpResponseRedirect(reverse('expedition', args=[expedition.year])) # Redirect after POST
# else:
# if pslug and pdate:
# if previouslbe.cave:
# tripForm = TripForm(initial={"date": previousdate,
# "title": previouslbe.title,
# "cave": previouslbe.cave.reference(),
# "location": None,
# "caveOrLocation": "cave",
# "html": previouslbe.text})
# else:
# tripForm = TripForm(initial={"date": previousdate,
# "title": previouslbe.title,
# "cave": None,
# "location": previouslbe.place,
# "caveOrLocation": "location",
# "html": previouslbe.text})
# personTripFormSet = PersonTripFormSet(initial=[{"name": get_name(py.personexpedition),
# "TU": py.time_underground,
# "author": py.is_logbook_entry_author}
# for py in previouslbe.persontrip_set.all()])
# else:
# tripForm = TripForm() # An unbound form
# personTripFormSet = PersonTripFormSet()
return render(request, 'newlogbookentry.html', {
'tripForm': tripForm,
'personTripFormSet': personTripFormSet,
# return render(request, 'newlogbookentry.html', {
# 'tripForm': tripForm,
# 'personTripFormSet': personTripFormSet,
})
# })
@login_required_if_public
def deleteLogbookEntry(request, expeditionyear, date = None, slug = None):
expedition = Expedition.objects.get(year=expeditionyear)
previousdate = datetime.date(*[int(x) for x in date.split("-")])
previouslbe = LogbookEntry.objects.get(slug = slug, date = previousdate, expedition = expedition)
delLogbookEntry(previouslbe)
return HttpResponseRedirect(reverse('expedition', args=[expedition.year])) # Redirect after POST
# @login_required_if_public
# def deleteLogbookEntry(request, expeditionyear, date = None, slug = None):
# expedition = Expedition.objects.get(year=expeditionyear)
# previousdate = datetime.date(*[int(x) for x in date.split("-")])
# previouslbe = LogbookEntry.objects.get(slug = slug, date = previousdate, expedition = expedition)
# delLogbookEntry(previouslbe)
# return HttpResponseRedirect(reverse('expedition', args=[expedition.year])) # Redirect after POST
def delLogbookEntry(lbe):
for pt in lbe.persontrip_set.all():
pt.delete()
lbe.delete()
os.remove(lbe.filename)
# def delLogbookEntry(lbe):
# for pt in lbe.persontrip_set.all():
# pt.delete()
# lbe.delete()
# os.remove(lbe.filename)
def get_people(request, expeditionslug):
exp = Expedition.objects.get(year = expeditionslug)

View File

@ -63,7 +63,7 @@ an "S" for a survey trip. The colours are the same for people on the same trip.
<form action="" method="GET"><input type="submit" name="reload" value="Reload"></form>
<h3>Logbooks and survey trips per day</h3>
<a href="{% url "newLogBookEntry" expeditionyear=expedition.year %}">New logbook entry</a>
<table class="expeditionlogbooks">
<tr><th>Date</th><th>Logged trips</th><th>Surveys</th></tr>
{% regroup dateditems|dictsort:"date" by date as dates %}

View File

@ -47,7 +47,7 @@ actualurlpatterns = [
url(r'^expeditions/?$', views_logbooks.ExpeditionListView.as_view(), name="expeditions"),
url(r'^personexpedition/(?P<first_name>[A-Z]*[a-z&;]*)[^a-zA-Z]*(?P<last_name>[A-Z]*[a-zA-Z&;]*)/(?P<year>\d+)/?$', views_logbooks.personexpedition, name="personexpedition"),
url(r'^logbookentry/(?P<date>.*)/(?P<slug>.*)/?$', views_logbooks.logbookentry,name="logbookentry"),
url(r'^newlogbookentry/(?P<expeditionyear>.*)$', views_logbooks.newLogbookEntry, name="newLogBookEntry"), # Needed !
# url(r'^newlogbookentry/(?P<expeditionyear>.*)$', views_logbooks.newLogbookEntry, name="newLogBookEntry"), # Needed !
# url(r'^editlogbookentry/(?P<expeditionyear>[^/]*)/(?P<pdate>[^/]*)/(?P<pslug>[^/]*)/$', views_logbooks.newLogbookEntry, name="editLogBookEntry"), # working !
# url(r'^deletelogbookentry/(?P<expeditionyear>[^/]*)/(?P<date>[^/]*)/(?P<slug>[^/]*)/$', views_logbooks.deleteLogbookEntry, name="deleteLogBookEntry"),
url(r'^newfile', views_other.newFile, name="newFile"), # oddly broken, needs investigating more