From d841faa0572dd6652348ee9b34c2d8c754801455 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 2 Apr 2021 15:51:14 +0100 Subject: [PATCH] login decorator moved into views & .gitignore --- .gitignore | 16 ++++++++++------ core/TESTS/tests.py | 21 ++++++++++++--------- core/admin.py | 6 ++++++ core/views/caves.py | 2 +- core/views/expo.py | 2 +- core/views/logbooks.py | 2 +- helper/__init__.py => core/views/login.py | 0 core/views/other.py | 2 +- 8 files changed, 32 insertions(+), 19 deletions(-) rename helper/__init__.py => core/views/login.py (100%) diff --git a/.gitignore b/.gitignore index 45a5c84..2e94370 100644 --- a/.gitignore +++ b/.gitignore @@ -15,22 +15,17 @@ _1623.pos _1623.svx _16230.svx cave-lookup.json -core/migrations/0001_initial.py -credentials.py +core/migrations/* db* desktop.ini diffsettings.txt -flatpages/migrations/0001_initial.py ignored-files.log import_profile.json lines-of-python.txt lines-of-templates.txt loadlogbk.log loadsurvexblks.log -localsettings.py -localsettings-expo-live.py logbktrips.shelve -media/images/* memdump.sql my_project.dot parsing_log.txt @@ -45,4 +40,13 @@ troggle.sqlite-journal troggle_log.txt tunnel-import.log logbktrips.shelve.db + +credentials.py localsettings.py +localsettings-expo-live.py +_deploy/old/localsettings-expo-live.py +_deploy/old/localsettings.py +debian/localsettings.py +debian/credentials.py +wsl/localsettings.py +wsl/credentials.py diff --git a/core/TESTS/tests.py b/core/TESTS/tests.py index 7936fb0..b8b915d 100644 --- a/core/TESTS/tests.py +++ b/core/TESTS/tests.py @@ -60,7 +60,7 @@ class SimpleTest(SimpleTestCase): from troggle.core.models 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.helper import login_required_if_public + from troggle.core.views.login import login_required_if_public from django.contrib.auth.decorators import login_required from django.conf import settings def test_import_parsers_mix(self): @@ -92,6 +92,9 @@ class SimpleTest(SimpleTestCase): #class SimplePageTest(unittest.TestCase): class PageTests(TestCase): + '''These tests may appear to be redundant, but in fact they exercise different bits of code. The urls.py + dispatcher is sending these URLs view via different 'view' handlers, and they all need verifying. + ''' @classmethod def setUpTestData(cls): # Set up data for the whole TestCase @@ -112,14 +115,6 @@ class PageTests(TestCase): phmatch = re.search(ph, content) self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") - def test_expoweb_root(self): - response = self.client.get('') - content = response.content.decode() - self.assertEqual(response.status_code, 200) - ph = r'CUCC in Austria' - phmatch = re.search(ph, content) - self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") - def test_expoweb_root_slash(self): response = self.client.get('/') content = response.content.decode() @@ -177,6 +172,11 @@ class PageTests(TestCase): phmatch = re.search(ph, content) self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + def test_expoweb_via_areaid(self): + # the dispatcher takes a detour via the cave renering procedure for this + response = self.client.get('/1623/others/t/via201.jpg') + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.content), 6057) def test_cave_kataster_not_found(self): # database not loaded, so no caves found @@ -378,6 +378,9 @@ class PageTests(TestCase): phmatch = re.search(ph, content) self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") +# ADD TESTS when we are redirecting /expofiles/ to get the actual files using e.g. +# import requests +# page = requests.get("http://dataquestio.github.io/web-scraping-pages/simple.html") # these need a fixture to load the datbase before they will pass # we also need tests for invalid queries to check that error pages are right diff --git a/core/admin.py b/core/admin.py index 5f62fbd..375bdc7 100644 --- a/core/admin.py +++ b/core/admin.py @@ -9,6 +9,12 @@ from troggle.core.models import Person, PersonExpedition, Expedition, DataIssue from troggle.core.models_caves import Cave, Area, Entrance, CaveAndEntrance, LogbookEntry, PersonTrip, QM from troggle.core.models_survex import SurvexBlock, SurvexPersonRole, SurvexStation, ScansFolder, SingleScan +'''This code significantly adds to the capabilities of the Django Management control panel for Troggle data. +In particular, it enables JSON export of any data with 'export_as_json' +and configures the search fields to be used within the control panel. + +What is the search path for the css and js inclusions in the Media subclasses though ?! +''' class TroggleModelAdmin(admin.ModelAdmin): diff --git a/core/views/caves.py b/core/views/caves.py index 1f89376..1dd6bf5 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -19,7 +19,7 @@ from troggle.core.views import expo from troggle.core.models 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.helper import login_required_if_public +from .login import login_required_if_public class MapLocations(object): p = [ diff --git a/core/views/expo.py b/core/views/expo.py index 07cb9c2..0afb7f0 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -13,7 +13,7 @@ from django.contrib import admin import django.forms as forms -from troggle.helper import login_required_if_public +from .login import login_required_if_public from troggle.core.models_caves import Cave import troggle.core.views.caves import troggle.settings as settings diff --git a/core/views/logbooks.py b/core/views/logbooks.py index 512c77c..11ea3d6 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -18,7 +18,7 @@ from troggle.core.forms import getTripForm # , get_name, PersonForm from troggle.core.models import Expedition, Person, PersonExpedition from troggle.core.models_caves import LogbookEntry, PersonTrip from troggle.core.models_survex import SurvexBlock -from troggle.helper import login_required_if_public +from .login import login_required_if_public from troggle.parsers.logbooks import LoadLogbookForExpedition from troggle.parsers.people import GetPersonExpeditionNameLookup diff --git a/helper/__init__.py b/core/views/login.py similarity index 100% rename from helper/__init__.py rename to core/views/login.py diff --git a/core/views/other.py b/core/views/other.py index 83acc4c..1985096 100644 --- a/core/views/other.py +++ b/core/views/other.py @@ -11,7 +11,7 @@ from django.template import Context, loader import troggle.parsers.imports from troggle.core.models import Expedition, Person, PersonExpedition from troggle.core.models_caves import LogbookEntry, QM, Cave, PersonTrip -from troggle.helper import login_required_if_public +from .login import login_required_if_public from troggle.core.forms import UploadFileForm print("** importing troggle/core/views.other.py")