summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/models.py38
-rw-r--r--core/utils.py84
-rw-r--r--core/views/logbooks.py3
3 files changed, 87 insertions, 38 deletions
diff --git a/core/models.py b/core/models.py
index 8d2d658..760c94f 100644
--- a/core/models.py
+++ b/core/models.py
@@ -22,6 +22,7 @@ from django.urls import reverse
from django.template import Context, loader
import troggle.core.models_survex
+from troggle.core.utils import get_process_memory
"""This file declares TroggleModel which inherits from django.db.models.Model
All TroggleModel subclasses inherit persistence in the django relational database. This is known as
@@ -29,43 +30,6 @@ the django Object Relational Mapping (ORM).
There are more subclasses define in models_caves.py models_survex.py etc.
"""
-# This variable is a dictionary holding gloablly visible indexes and cache functions.
-# It is a Global Object, see https://python-patterns.guide/python/module-globals/
-# troggle.models.TROG
-TROG = {
- 'pagecache' : {
- 'expedition' : {}
- }
-}
-
-def get_process_memory():
- usage=resource.getrusage(resource.RUSAGE_SELF)
- return usage[2]/1024.0
-
-
-# def get_related_by_wikilinks(wiki_text):
- # found=re.findall(settings.QM_PATTERN,wiki_text)
- # res=[]
- # for wikilink in found:
- # qmdict={'urlroot':settings.URL_ROOT,'cave':wikilink[2],'year':wikilink[1],'number':wikilink[3]}
- # try:
- # cave_slugs = models_caves.CaveSlug.objects.filter(cave__kataster_number = qmdict['cave'])
- # qm=QM.objects.get(found_by__cave_slug__in = cave_slugs,
- # found_by__date__year = qmdict['year'],
- # number = qmdict['number'])
- # res.append(qm)
- # except QM.DoesNotExist:
- # print(('fail on '+str(wikilink)))
-
- # return res
-
-try:
- logging.basicConfig(level=logging.DEBUG,
- filename=settings.LOGFILE,
- filemode='w')
-except:
-# Opening of file for writing is going to fail currently, so decide it doesn't matter for now
- pass
#This class is for adding fields and methods which all of our models will have.
class TroggleModel(models.Model):
diff --git a/core/utils.py b/core/utils.py
new file mode 100644
index 0000000..4dcee68
--- /dev/null
+++ b/core/utils.py
@@ -0,0 +1,84 @@
+import string
+import os
+import datetime
+import logging
+import re
+import resource
+from subprocess import call
+
+from urllib.parse import urljoin
+from decimal import Decimal, getcontext
+getcontext().prec=2 #use 2 significant figures for decimal calculations
+
+import settings
+
+from django.db import models
+from django.contrib import admin
+from django.contrib.auth.models import User
+from django.contrib.contenttypes.models import ContentType
+from django.conf import settings
+
+from django.urls import reverse
+from django.template import Context, loader
+
+#import troggle.core.models_survex
+
+'''This file declares TROG a globally visible object for caches.
+
+TROG is a dictionary holding gloablly visible indexes and cache functions.
+It is a Global Object, see https://python-patterns.guide/python/module-globals/
+troggle.models.TROG
+
+chaosmonkey(n) - used by survex import to regenerate some .3d files
+save_carefully() - core function that saves troggle objects in the database
+
+'''
+
+TROG = {
+ 'pagecache' : {
+ 'expedition' : {}
+ }
+}
+
+# This is module-level executable. This is a Bad Thing.
+try:
+ logging.basicConfig(level=logging.DEBUG,
+ filename=settings.LOGFILE,
+ filemode='w')
+except:
+# Opening of file for writing is going to fail currently, so decide it doesn't matter for now
+ pass
+
+def get_process_memory():
+ usage=resource.getrusage(resource.RUSAGE_SELF)
+ return usage[2]/1024.0
+
+def chaosmonkey(n):
+ # returns True once every n calls - randomly
+ if random.randrange(0,n) != 0:
+ return False
+ # print("CHAOS strikes !", file=sys.stderr)
+ return True
+
+# def get_related_by_wikilinks(wiki_text):
+ # found=re.findall(settings.QM_PATTERN,wiki_text)
+ # res=[]
+ # for wikilink in found:
+ # qmdict={'urlroot':settings.URL_ROOT,'cave':wikilink[2],'year':wikilink[1],'number':wikilink[3]}
+ # try:
+ # cave_slugs = models_caves.CaveSlug.objects.filter(cave__kataster_number = qmdict['cave'])
+ # qm=QM.objects.get(found_by__cave_slug__in = cave_slugs,
+ # found_by__date__year = qmdict['year'],
+ # number = qmdict['number'])
+ # res.append(qm)
+ # except QM.DoesNotExist:
+ # print(('fail on '+str(wikilink)))
+
+ # return res
+
+
+
+
+
+
+
diff --git a/core/views/logbooks.py b/core/views/logbooks.py
index dcdb6f4..1db2edc 100644
--- a/core/views/logbooks.py
+++ b/core/views/logbooks.py
@@ -14,7 +14,8 @@ from django.views.generic.list import ListView
#import troggle.parsers.logbooks as logbookparsers
from troggle.core.forms import getTripForm # , get_name, PersonForm
-from troggle.core.models import Expedition, Person, PersonExpedition, TROG
+from troggle.core.models import Expedition, Person, PersonExpedition
+from troggle.core.utils import TROG
from troggle.core.models_caves import LogbookEntry, PersonTrip
from troggle.core.models_survex import SurvexBlock
from .login import login_required_if_public