clean up import statements: more specific

This commit is contained in:
Philip Sargent 2020-06-22 00:03:23 +01:00
parent 8199e67b79
commit 674cea629d
9 changed files with 51 additions and 144 deletions

View File

@ -6,6 +6,14 @@ Troggle has been forked into two projects. The original one is maintained by Aro
and is used for Erebus caves. The CUCC variant uses files as the definitive data,
not the database and lives at http://expo.survex.com/repositories/troggle/.git/
#-----------------------------------------------------------------
# THINK before you push a file to the repo
# - Are there PASSWORDS in it ?
# - have you checked that this file is in .gitignore ?
# - have you run pre-push.sh to copy files and remove passwords?
# - we don't want to have to change the expo system password !
#-----------------------------------------------------------------
Troggle setup
=============
1. git clone troggle into correct directory structure

View File

@ -5,10 +5,9 @@ from django.http import HttpResponse
from django.core import serializers
from troggle.core.views_other import downloadLogbook
from troggle.core.models import *
from troggle.core.models import Person, PersonExpedition, Expedition, DataIssue
from troggle.core.models_caves import Cave, Area, Entrance, CaveAndEntrance, NewSubCave, OtherCaveName, CaveDescription, LogbookEntry, PersonTrip, QM
from troggle.core.models_survex import SurvexBlock, SurvexPersonRole, SurvexStation, SurvexScansFolder, SurvexScanSingle
#from troggle.reversion.admin import VersionAdmin #django-reversion version control
class TroggleModelAdmin(admin.ModelAdmin):
@ -31,11 +30,6 @@ class SurvexBlockAdmin(TroggleModelAdmin):
inlines = (RoleInline,)
# class ScannedImageInline(admin.TabularInline):
# model = ScannedImage
# extra = 4
class OtherCaveInline(admin.TabularInline):
model = OtherCaveName
extra = 1
@ -53,24 +47,16 @@ class QMsFoundInline(admin.TabularInline):
extra=1
# class PhotoInline(admin.TabularInline):
# model = DPhoto
# exclude = ['is_mugshot' ]
# extra = 1
class PersonTripInline(admin.TabularInline):
model = PersonTrip
raw_id_fields = ('personexpedition',)
extra = 1
#class LogbookEntryAdmin(VersionAdmin):
class LogbookEntryAdmin(TroggleModelAdmin):
prepopulated_fields = {'slug':("title",)}
search_fields = ('title','expedition__year')
date_heirarchy = ('date')
# inlines = (PersonTripInline, PhotoInline, QMsFoundInline)
inlines = (PersonTripInline, QMsFoundInline)
class Media:
css = {
@ -120,10 +106,8 @@ class EntranceAdmin(TroggleModelAdmin):
search_fields = ('caveandentrance__cave__kataster_number',)
#admin.site.register(DPhoto)
admin.site.register(Cave, CaveAdmin)
admin.site.register(Area)
#admin.site.register(OtherCaveName)
admin.site.register(CaveAndEntrance)
admin.site.register(NewSubCave)
admin.site.register(CaveDescription)
@ -134,15 +118,10 @@ admin.site.register(Person,PersonAdmin)
admin.site.register(SurvexPersonRole)
admin.site.register(PersonExpedition,PersonExpeditionAdmin)
admin.site.register(LogbookEntry, LogbookEntryAdmin)
#admin.site.register(PersonTrip)
admin.site.register(QM, QMAdmin)
#admin.site.register(Survey, SurveyAdmin)
#admin.site.register(ScannedImage)
admin.site.register(SurvexStation)
admin.site.register(SurvexScansFolder)
admin.site.register(SurvexScanSingle)
admin.site.register(DataIssue)
def export_as_json(modeladmin, request, queryset):

View File

@ -23,7 +23,6 @@ from troggle.parsers.logbooks import LoadLogbookForExpedition
from troggle.parsers.people import GetPersonExpeditionNameLookup
import troggle.settings as settings
from settings import *
# Django uses Context, not RequestContext when you call render
# to_response. We always want to use RequestContext, so that

View File

@ -4,8 +4,6 @@ import re
import django.db.models
from django.db.models import Min, Max
#from django.urls import reverse, resolve
#from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, render_to_response
from django.template import Context, loader
from django.template.defaultfilters import slugify
@ -17,38 +15,37 @@ from troggle.core.models_caves import Cave, LogbookEntry
from troggle.core.models_survex import SurvexLeg, SurvexBlock
import troggle.settings as settings
from settings import *
def pathsreport(request):
pathsdict={
"CAVEDESCRIPTIONS" : CAVEDESCRIPTIONS,
"DIR_ROOT" : DIR_ROOT,
"ENTRANCEDESCRIPTIONS" : ENTRANCEDESCRIPTIONS,
"EXPOUSER_EMAIL" : EXPOUSER_EMAIL,
"CAVEDESCRIPTIONS" : settings.CAVEDESCRIPTIONS,
"DIR_ROOT" : settings.DIR_ROOT,
"ENTRANCEDESCRIPTIONS" : settings.ENTRANCEDESCRIPTIONS,
"EXPOUSER_EMAIL" : settings.EXPOUSER_EMAIL,
"EXPOUSERPASS" :"<redacted>",
"EXPOUSER" : EXPOUSER,
"EXPOWEB" : EXPOWEB,
"EXPOWEB_URL" : EXPOWEB_URL,
"FILES" : FILES,
"JSLIB_URL" : JSLIB_URL,
"LOGFILE" : LOGFILE,
"LOGIN_REDIRECT_URL" : LOGIN_REDIRECT_URL,
"MEDIA_ROOT" : MEDIA_ROOT,
"MEDIA_URL" : MEDIA_URL,
"PHOTOS_URL" : PHOTOS_URL,
"PYTHON_PATH" : PYTHON_PATH,
"REPOS_ROOT_PATH" : REPOS_ROOT_PATH,
"ROOT_URLCONF" : ROOT_URLCONF,
"STATIC_URL" : STATIC_URL,
"SURVEX_DATA" : SURVEX_DATA,
"SURVEY_SCANS" : SURVEY_SCANS,
"SURVEYS" : SURVEYS,
"SURVEYS_URL" : SURVEYS_URL,
"SVX_URL" : SVX_URL,
"THREEDCACHEDIR" : THREEDCACHEDIR,
"TUNNEL_DATA" : TUNNEL_DATA,
"URL_ROOT" : URL_ROOT
"EXPOUSER" : settings.EXPOUSER,
"EXPOWEB" : settings.EXPOWEB,
"EXPOWEB_URL" : settings.EXPOWEB_URL,
"FILES" : settings.FILES,
"JSLIB_URL" : settings.JSLIB_URL,
"LOGFILE" : settings.LOGFILE,
"LOGIN_REDIRECT_URL" : settings.LOGIN_REDIRECT_URL,
"MEDIA_ROOT" : settings.MEDIA_ROOT,
"MEDIA_URL" : settings.MEDIA_URL,
"PHOTOS_URL" : settings.PHOTOS_URL,
"PYTHON_PATH" : settings.PYTHON_PATH,
"REPOS_ROOT_PATH" : settings.REPOS_ROOT_PATH,
"ROOT_URLCONF" : settings.ROOT_URLCONF,
"STATIC_URL" : settings.STATIC_URL,
"SURVEX_DATA" : settings.SURVEX_DATA,
"SURVEY_SCANS" : settings.SURVEY_SCANS,
"SURVEYS" : settings.SURVEYS,
"SURVEYS_URL" : settings.SURVEYS_URL,
"SVX_URL" : settings.SVX_URL,
"THREEDCACHEDIR" : settings.THREEDCACHEDIR,
"TUNNEL_DATA" : settings.TUNNEL_DATA,
"URL_ROOT" : settings.URL_ROOT
}
# settings are unique by paths are not
ncodes = len(pathsdict)

View File

@ -1,7 +1,7 @@
import csv
import os
import re
from datetime import *
#from datetime import *
from django.conf import settings

View File

@ -123,7 +123,7 @@ def LoadSurvexEquate(survexblock, sline):
def LoadSurvexLinePassage(survexblock, stardata, sline, comment):
# do not import *data passage.. data which is LRUD not tape/compass/clino
# do not import this: *data passage.. data which is LRUD not tape/compass/clino
pass
# This interprets the survex "*data normal" command which sets out the order of the fields in the data, e.g.

View File

@ -15,9 +15,9 @@ from utils import save_carefully
from functools import reduce
import settings
from troggle.core.models import *
from troggle.core.models_caves import *
from troggle.core.models_survex import *
#from troggle.core.models import *
#from troggle.core.models_caves import *
#from troggle.core.models_survex import *
def get_or_create_placeholder(year):
""" All surveys must be related to a logbookentry. We don't have a way to
@ -40,81 +40,6 @@ def listdir(*directories):
folders = urllib.request.urlopen(url.replace("#", "%23")).readlines()
return [folder.rstrip(r"/") for folder in folders]
# add survey scans
# def parseSurveyScans(expedition, logfile=None):
# # yearFileList = listdir(expedition.year)
# try:
# yearPath=os.path.join(settings.SURVEY_SCANS, "surveyscans", expedition.year)
# yearFileList=os.listdir(yearPath)
# print(yearFileList)
# for surveyFolder in yearFileList:
# try:
# surveyNumber=re.match(rb'\d\d\d\d#(X?)0*(\d+)',surveyFolder).groups()
# #scanList = listdir(expedition.year, surveyFolder)
# scanList=os.listdir(os.path.join(yearPath,surveyFolder))
# except AttributeError:
# print(("Ignoring file in year folder: " + surveyFolder + "\r"))
# continue
# for scan in scanList:
# # Why does this insist on renaming all the scanned image files?
# # It produces duplicates names and all images have type .jpg in the scanObj.
# # It seems to rely on end users being particularly diligent in filenames which is NGtH
# try:
# #scanChopped=re.match(rb'(?i).*(notes|elev|plan|extend|elevation)-?(\d*)\.(png|jpg|jpeg|pdf)',scan).groups()
# scanChopped=re.match(rb'(?i)([a-z_-]*\d?[a-z_-]*)(\d*)\.(png|jpg|jpeg|pdf|top|dxf|svg|tdr|th2|xml|txt)',scan).groups()
# scanType,scanNumber,scanFormat=scanChopped
# except AttributeError:
# print(("Ignored (bad name format): " + surveyFolder + '/' + scan + "\r"))
# continue
# scanTest = scanType
# scanType = 'notes'
# match = re.search(rb'(?i)(elev|extend)',scanTest)
# if match:
# scanType = 'elevation'
# match = re.search(rb'(?i)(plan)',scanTest)
# if match:
# scanType = 'plan'
# if scanNumber=='':
# scanNumber=1
# if isinstance(surveyNumber, tuple):
# surveyLetter=surveyNumber[0]
# surveyNumber=surveyNumber[1]
# try:
# placeholder=get_or_create_placeholder(year=int(expedition.year))
# survey=Survey.objects.get_or_create(wallet_number=surveyNumber, wallet_letter=surveyLetter, expedition=expedition, defaults={'logbook_entry':placeholder})[0]
# except Survey.MultipleObjectsReturned:
# survey=Survey.objects.filter(wallet_number=surveyNumber, wallet_letter=surveyLetter, expedition=expedition)[0]
# file_=os.path.join(yearPath, surveyFolder, scan)
# scanObj = ScannedImage(
# file=file_,
# contents=scanType,
# number_in_wallet=scanNumber,
# survey=survey,
# new_since_parsing=False,
# )
# print(("Added scanned image at " + str(scanObj)))
# #if scanFormat=="png":
# #if isInterlacedPNG(os.path.join(settings.SURVEY_SCANS, "surveyscans", file_)):
# # print file_+ " is an interlaced PNG. No can do."
# #continue
# scanObj.save()
# except (IOError, OSError):
# yearPath=os.path.join(settings.SURVEY_SCANS, "surveyscans", expedition.year)
# print((" ! No folder found for " + expedition.year + " at:- " + yearPath))
# dead
# def isInterlacedPNG(filePath): #We need to check for interlaced PNGs because the thumbnail engine can't handle them (uses PIL)
# file=Image.open(filePath)
# print(filePath)
# if 'interlace' in file.info:
# return file.info['interlace']
# else:
# return False
# handles url or file, so we can refer to a set of scans on another server
def GetListDir(sdir):

View File

@ -108,10 +108,10 @@ INSTALLED_APPS = (
'django.contrib.sessions',
'django.contrib.messages',
# 'django.contrib.staticfiles', # apparently not working. Using workarounds with flatpages
'registration',
'troggle.profiles',
'registration', # only for expo user. REPLACE with another non-admin, contrib.auth user ?
'troggle.profiles', # Probably don't need this at all
'troggle.core',
'troggle.flatpages',
'troggle.flatpages', # NOT django.contrib.flatpages.models.FlatPage Merge in with troggle ?
)
MIDDLEWARE_CLASSES = (

17
urls.py
View File

@ -1,17 +1,13 @@
from django.conf import settings
from django.conf.urls import *
from django.conf.urls import url, include
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 django.conf.urls.static import static
from django.urls import reverse, resolve
#
from .core.views import * # flat import
from .core.views_other import *
from .core.views_caves import *
from .core.views_survex import *
from .core.models import *
from troggle.core import views_other, views_caves, views_logbooks, views_statistics, views_survex, view_surveys
from troggle.core.views_other import logbook_entry_suggestions
from troggle.core.views_caves import ent, prospecting_image
from troggle.core.views_statistics import pathsreport, stats
from flatpages import views as flatviews
@ -22,6 +18,9 @@ admin.autodiscover()
# url( <regular expression that matches the thing in the web browser>,
# <reference to python function in 'core' folder>, <optional name>)
# Django also provides the reverse function: given an an object, provide the URL
# which is vital to writing code for the webapp. So the URL dispatch is declarative.
actualurlpatterns = [
url(r'^troggle$', views_other.frontpage, name="frontpage"),
url(r'^caves$', views_caves.caveindex, name="caveindex"),