diff --git a/core/models/caves.py b/core/models/caves.py index 536ace8..c76b8b5 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -373,7 +373,6 @@ class LogbookEntry(TroggleModel): place = models.CharField(max_length=100,blank=True, null=True,help_text="Only use this if you haven't chosen a cave") text = models.TextField() slug = models.SlugField(max_length=50) - filename = models.CharField(max_length=200,null=True) entry_type = models.CharField(default="wiki",null=True,choices=LOGBOOK_ENTRY_TYPES,max_length=50) class Meta: @@ -412,7 +411,7 @@ class LogbookEntry(TroggleModel): return urljoin(settings.URL_ROOT, reverse('logbookentry',kwargs={'date':self.date,'slug':self.slug})) def __str__(self): - return "%s: (%s)" % (self.date, self.title) + return f'{self.date}: {self.title}' def get_next_by_id(self): LogbookEntry.objects.get(id=self.id+1) @@ -507,7 +506,7 @@ class PersonTrip(TroggleModel): return self.logbook_entry.cave and self.logbook_entry.cave or self.logbook_entry.place def __str__(self): - return "%s (%s)" % (self.personexpedition, self.logbook_entry.date) + return f'{self.personexpedition} ({self.logbook_entry.date})' scansFileStorage = FileSystemStorage(location=settings.SURVEY_SCANS, base_url=settings.SURVEYS_URL) def get_scan_path(instance, filename): diff --git a/core/models/troggle.py b/core/models/troggle.py index c41e6f0..927ee44 100644 --- a/core/models/troggle.py +++ b/core/models/troggle.py @@ -70,6 +70,7 @@ class DataIssue(TroggleModel): class Expedition(TroggleModel): year = models.CharField(max_length=20, unique=True) name = models.CharField(max_length=100) + logbookfile = models.CharField(max_length=100, blank=True, null=True) def __str__(self): return self.year diff --git a/core/views/logbooks.py b/core/views/logbooks.py index 00ac4e4..4abe966 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -115,16 +115,13 @@ class Expeditions_jsonListView(ListView): def person(request, first_name='', last_name='', ): - this_person = Person.objects.get(first_name = first_name, last_name = last_name) + try: + this_person = Person.objects.get(first_name = first_name, last_name = last_name) + return render(request,'person.html', {'person': this_person, }) + except: + message = f'Person not found - possibly Scottish? (We have a name parser issue with Mc, Mac etc.)' + return render(request, 'errors/generic.html', {'message': message}) - # This is for removing the reference to the user's profile, in case they set it to the wrong person - if request.method == 'GET': - if request.GET.get('clear_profile')=='True': - this_person.user=None - this_person.save() - return HttpResponseRedirect(reverse('profiles_select_profile')) - - return render(request,'person.html', {'person': this_person, }) def get_person_chronology(personexpedition): diff --git a/core/views/other.py b/core/views/other.py index 569264b..b179f82 100644 --- a/core/views/other.py +++ b/core/views/other.py @@ -134,14 +134,12 @@ def ajax_QM_number(request): return HttpResponse(res) - -#print(" - newFile() is next in troggle/core/views/other.py") - @login_required_if_public def newFile(request, pslug = None): + ''' not known quite what this was for or where it fits in - original 2006 troggle idea never finished? + ''' if pslug: previousfile = LogbookEntry.objects.get(slug = pslug, date = previousdate, expedition = expedition) - #assert previousfile.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) @@ -175,16 +173,4 @@ def newFile(request, pslug = None): return render(request, 'editfile.html', {'fileForm': fileform, }) -@login_required_if_public -def deleteFile(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 delFile(f): - for pt in lbe.persontrip_set.all(): - pt.delete() - lbe.delete() - os.remove(lbe.filename) diff --git a/parsers/logbooks.py b/parsers/logbooks.py index 8afb0fa..4310fdb 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -447,11 +447,14 @@ def LoadLogbookForExpedition(expedition, expect): if expedition.year in yearlinks: logbookfile = os.path.join(expologbase, yearlinks[expedition.year][0]) + expedition.logbookfile = yearlinks[expedition.year][0] parsefunc = yearlinks[expedition.year][1] else: logbookfile = os.path.join(expologbase, expedition.year, settings.DEFAULT_LOGBOOK_FILE) + expedition.logbookfile = settings.DEFAULT_LOGBOOK_FILE parsefunc = settings.DEFAULT_LOGBOOK_PARSER cache_filename = logbookfile + ".cache" + expedition.save() try: bad_cache = False diff --git a/templates/errors/generic.html b/templates/errors/generic.html index 66655a1..19bed46 100644 --- a/templates/errors/generic.html +++ b/templates/errors/generic.html @@ -13,7 +13,15 @@

There has been an error.

-

We are terribly sorry but an unknown fault has occurred.

+ + + + {% if message %} + {{message}} + {% else %} +

We are terribly sorry but an unknown fault has occurred.

+ + {% endif %})
diff --git a/templates/logbookentry.html b/templates/logbookentry.html index 1af88bd..9407e72 100644 --- a/templates/logbookentry.html +++ b/templates/logbookentry.html @@ -1,4 +1,5 @@ {% extends "base.html" %} + {% load wiki_markup %} {% block title %}Logbook {{logbookentry.id}}{% endblock %} @@ -10,12 +11,14 @@

{{logbookentry.title|safe}}

-{% if logbookentry.filename %}Edit Delete{%endif%} - - {% endblock %} diff --git a/templates/newlogbookentry.html b/templates/newlogbookentry.html index fdb4cbd..bdb0919 100644 --- a/templates/newlogbookentry.html +++ b/templates/newlogbookentry.html @@ -1,4 +1,5 @@ {% extends "base.html" %} + {% load csrffaker %} {% block title %}Logbook {{logbookentry.id}}{% endblock %} {% block head %}