New url dispatcher OK 1.9.13

This commit is contained in:
Philip Sargent 2020-06-17 22:55:51 +01:00
parent 4941d230e2
commit 55dd577275
4 changed files with 64 additions and 56 deletions

View File

@ -6,7 +6,9 @@ import difflib
from django import forms
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render_to_response, render
from django.core.context_processors import csrf
#from django.core.context_processors import csrf
from django.template.context_processors import csrf
from django.http import HttpResponse, Http404
import troggle.settings as settings

View File

@ -8,25 +8,34 @@ import settings
os.environ['PYTHONPATH'] = settings.PYTHON_PATH
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
import django
from django.core import management
from django.db import connection, close_old_connections, connections
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.core.urlresolvers import reverse
print(" - settings on loading databaseReset.py")
from troggle.core.models_caves import Cave, Entrance
import django
print(" - django.setup - next")
try:
django.setup()
except:
print(" ! Cyclic reference failure. Can occur when the initial db is empty. Fixed now (in UploadFileForm) but easy to reintroduce..")
raise
print(" - django.setup - done")
import troggle.flatpages.models
import troggle.logbooksdump
from troggle.parsers.imports import import_caves, import_people, import_surveyscans, \
import_logbooks, import_QMs, import_survex, import_tunnelfiles
import troggle.core.models
import troggle.core.models_survex
from django.core import management
from django.db import connection, close_old_connections, connections
from django.http import HttpResponse
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from troggle.core.models_caves import Cave, Entrance
from troggle.parsers.imports import import_caves, import_people, import_surveyscans, \
import_logbooks, import_QMs, import_survex, import_tunnelfiles
import troggle.logbooksdump
# NOTE databaseReset.py is *imported* by views_other.py as it is used in the control panel
# presented there.
@ -80,7 +89,12 @@ def reinit_db():
#Sync user - needed after reload
print(" - Migrating: " + django.db.connections.databases['default']['NAME'])
management.call_command('makemigrations','core', interactive=False)
management.call_command('makemigrations','flatpages', interactive=False)
management.call_command('migrate', interactive=False)
management.call_command('migrate','core', interactive=False)
management.call_command('migrate','flatpages', interactive=False)
print(" - done migration on: " + settings.DATABASES['default']['NAME'])
print("users in db already: ",len(User.objects.all()))
try:
@ -467,13 +481,6 @@ if __name__ == "__main__":
store_dbsettings()
#set_in_memory_dbsettings()
print(" - django.setup - next")
try:
django.setup()
except:
print(" ! Cyclic reference failure. Can occur when the initial db is empty. Fixed now (in UploadFileForm) but easy to reintroduce..")
raise
print(" - django.setup - done")
#set_in_memory_dbsettings() # seems to be ignored. Appears to be set but in reality.
#jq.run_now_django_tests(1) # actually does set db to :memory: - but invisibly !

View File

@ -98,7 +98,6 @@ SECRET_KEY = 'a#vaeozn0)uz_9t_%v5n#tj)m+%ace6b_0(^fj!355qki*v)j2'
LOGIN_REDIRECT_URL = '/'
INSTALLED_APPS = (
# 'django.auth',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
@ -111,7 +110,6 @@ INSTALLED_APPS = (
'troggle.flatpages',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
@ -148,6 +146,4 @@ TEST_RUNNER = 'django.test.runner.DiscoverRunner'
from localsettings import *
#localsettings needs to take precedence. Call it to override any existing vars.
#print("INSTALLED_APPS ",INSTALLED_APPS)
print("++ finished importing troggle/settings.py")

63
urls.py
View File

@ -3,6 +3,7 @@ from django.conf.urls import *
from django.views.generic.edit import UpdateView
from django.views.generic.list import ListView
from django.contrib import admin
from django.contrib.staticfiles import views as staticviews
from .core.views import * # flat import
from .core.views_other import *
@ -10,6 +11,7 @@ from .core.views_caves import *
from .core.views_survex import *
from .core.models import *
from troggle.core.views_statistics import pathsreport, stats
from flatpages import views as flatviews
admin.autodiscover()
@ -20,7 +22,7 @@ admin.autodiscover()
# <reference to python function in 'core' folder>,
# <name optional argument for URL reversing (doesn't do much)>)
actualurlpatterns = patterns('',
actualurlpatterns = [
url(r'^troggle$', views_other.frontpage, name="frontpage"),
url(r'^caves$', views_caves.caveindex, name="caveindex"),
@ -65,7 +67,7 @@ actualurlpatterns = patterns('',
#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'),
#(r'^cavesearch', caveSearch),
#url(r'^cavesearch', caveSearch),
url(r'^prospecting_guide/$', views_caves.prospecting),
@ -78,32 +80,16 @@ actualurlpatterns = patterns('',
url(r'^logbook(?P<year>\d\d\d\d)\.(?P<extension>.*)/?$',views_other.downloadLogbook),
url(r'^logbook/?$',views_other.downloadLogbook, name="downloadlogbook"),
url(r'^cave/(?P<cave_id>[^/]+)/qm\.csv/?$', views_other.downloadQMs, name="downloadqms"),
(r'^downloadqms$', views_other.downloadQMs),
url(r'^downloadqms$', views_other.downloadQMs),
(r'^admin/doc/?', include('django.contrib.admindocs.urls')), # needs docutils Python module (http://docutils.sf.net/).
#url(r'^admin/(.*)', admin.site.get_urls, name="admin"),
(r'^admin/', include(admin.site.urls)),
# don't know why this needs troggle/ in here. nice to get it out
url(r'^troggle/media-admin/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ADMIN_DIR, 'show_indexes':True}),
(r'^accounts/', include('registration.backends.default.urls')),
(r'^profiles/', include('profiles.urls')),
url(r'^admin/doc/?', include('django.contrib.admindocs.urls')), # needs docutils Python module (http://docutils.sf.net/).
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('registration.backends.default.urls')),
url(r'^profiles/', include('profiles.urls')),
# (r'^personform/(.*)$', personForm),
(r'^expofiles/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.EXPOFILES, 'show_indexes': True}),
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_ROOT, 'show_indexes': True}),
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
#(r'^tinymce_media/(?P<path>.*)$', 'django.views.static.serve',
# {'document_root': settings.TINY_MCE_MEDIA_ROOT, 'show_indexes': True}),
#(r'^photos/(?P<path>.*)$', 'django.views.static.serve',
# {'document_root': settings.PHOTOS_ROOT, 'show_indexes':True}),
# (r'^gallery/(?P<path>.*)$', 'django.views.static.serve',
# {'document_root': settings.PHOTOS_ROOT, 'show_indexes':True}),
url(r'^survexblock/(.+)$', views_caves.survexblock, name="survexblock"),
url(r'^survexfile/(?P<survex_file>.*?)\.svx$', views_survex.svx, name="svx"),
@ -115,7 +101,7 @@ actualurlpatterns = patterns('',
url(r'^survexfile/(?P<survex_cave>.*)$', views_survex.survexcavesingle, name="survexcavessingle"),
url(r'^survexfileraw/(?P<survex_file>.*?)\.svx$', views_survex.svxraw, name="svxraw"),
(r'^survey_files/download/(?P<path>.*)$', view_surveys.download),
url(r'^survey_files/download/(?P<path>.*)$', view_surveys.download),
#(r'^survey_scans/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.SURVEY_SCANS, 'show_indexes':True}),
url(r'^survey_scans/$', view_surveys.surveyscansfolders, name="surveyscansfolders"),
@ -132,11 +118,28 @@ actualurlpatterns = patterns('',
url(r'^prospecting/(?P<name>[^.]+).png$', prospecting_image, name="prospecting_image"),
url(r'^(.*)_edit$', 'flatpages.views.editflatpage', name="editflatpage"),
url(r'^(.*)$', 'flatpages.views.flatpage', name="flatpage"),
)
url(r'^expofiles/(?P<path>.*)$', staticviews.serve,
{'document_root': settings.EXPOFILES, 'show_indexes': True}),
url(r'^static/(?P<path>.*)$', staticviews.serve,
{'document_root': settings.STATIC_ROOT, 'show_indexes': True}),
url(r'^site_media/(?P<path>.*)$', staticviews.serve,
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
#url(r'^tinymce_media/(?P<path>.*)$', staticviews.serve,
# {'document_root': settings.TINY_MCE_MEDIA_ROOT, 'show_indexes': True}),
#url(r'^photos/(?P<path>.*)$', staticviews.serve,
# {'document_root': settings.PHOTOS_ROOT, 'show_indexes':True}),
# url(r'^gallery/(?P<path>.*)$', staticviews.serve,
# {'document_root': settings.PHOTOS_ROOT, 'show_indexes':True}),
# don't know why this needs troggle/ in here. nice to get it out
url(r'^troggle/media-admin/(?P<path>.*)$', staticviews.serve,
{'document_root': settings.MEDIA_ADMIN_DIR, 'show_indexes':True}),
url(r'^(.*)_edit$', flatviews.editflatpage, name="editflatpage"),
url(r'^(.*)$', flatviews.flatpage, name="flatpage"),
]
#Allow prefix to all urls
urlpatterns = patterns ('',
('^%s' % settings.DIR_ROOT, include(actualurlpatterns))
)
urlpatterns = [
url('^%s' % settings.DIR_ROOT, include(actualurlpatterns))
]