From 5b3b0e67e9744671fadeca78e5565d3dbd1f81c1 Mon Sep 17 00:00:00 2001
From: Philip Sargent
Date: Tue, 13 Apr 2021 00:43:57 +0100
Subject: create core/models/ directroy
---
core/TESTS/test_imports.py | 8 +-
core/admin.py | 2 +-
core/context.py | 2 +-
core/forms.py | 42 +--------
core/models.py | 225 ---------------------------------------------
core/models/__init__.py | 0
core/models/troggle.py | 225 +++++++++++++++++++++++++++++++++++++++++++++
core/models_caves.py | 3 +-
core/unused.py | 10 +-
core/utils.py | 20 +---
core/views/caves.py | 2 +-
core/views/logbooks.py | 2 +-
core/views/other.py | 2 +-
core/views/statistics.py | 2 +-
core/views/survex.py | 2 +-
databaseReset.py | 4 +-
parsers/QMs.py | 2 +-
parsers/caves.py | 2 +-
parsers/logbooks.py | 2 +-
parsers/surveys.py | 2 +-
20 files changed, 250 insertions(+), 309 deletions(-)
delete mode 100644 core/models.py
create mode 100644 core/models/__init__.py
create mode 100644 core/models/troggle.py
diff --git a/core/TESTS/test_imports.py b/core/TESTS/test_imports.py
index 46c590d..01e76c7 100644
--- a/core/TESTS/test_imports.py
+++ b/core/TESTS/test_imports.py
@@ -27,7 +27,7 @@ class SimpleTest(SimpleTestCase):
from django.conf import settings
self.assertEqual(settings.EMAIL_BACKEND, 'django.core.mail.backends.locmem.EmailBackend')
def test_import_TroggleModel(self):
- from troggle.core.models import TroggleModel
+ from troggle.core.models.troggle import TroggleModel
def test_import_Cave(self):
from troggle.core.models_caves import Cave
def test_import_parsers_surveys(self):
@@ -36,7 +36,7 @@ class SimpleTest(SimpleTestCase):
from functools import reduce
def test_import_parsers_survex(self):
import troggle.settings as settings
- import troggle.core.models as models
+ import troggle.core.models.troggle as models
import troggle.core.models_caves as models_caves
import troggle.core.models_survex as models_survex
from troggle.parsers.people import GetPersonExpeditionNameLookup
@@ -49,14 +49,14 @@ class SimpleTest(SimpleTestCase):
def test_import_parsers_logbooks(self):
from django.template.defaultfilters import slugify
from django.utils.timezone import get_current_timezone, make_aware
- from troggle.core.models import DataIssue, Expedition
+ from troggle.core.models.troggle import DataIssue, Expedition
from troggle.core.models_caves import Cave, LogbookEntry, PersonTrip
from parsers.people import GetPersonExpeditionNameLookup
def test_import_core_views_caves(self):
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
import troggle.core.views.expo
- from troggle.core.models import Expedition
+ from troggle.core.models.troggle 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.core.views.login import login_required_if_public
diff --git a/core/admin.py b/core/admin.py
index 375bdc7..0a9015b 100644
--- a/core/admin.py
+++ b/core/admin.py
@@ -5,7 +5,7 @@ from django.http import HttpResponse
from django.core import serializers
from troggle.core.views.other import downloadLogbook
-from troggle.core.models import Person, PersonExpedition, Expedition, DataIssue
+from troggle.core.models.troggle 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
diff --git a/core/context.py b/core/context.py
index 6b3b928..908cd69 100644
--- a/core/context.py
+++ b/core/context.py
@@ -1,5 +1,5 @@
from django.conf import settings
-from troggle.core.models import Expedition
+from troggle.core.models.troggle import Expedition
def troggle_context(request):
return { 'settings':settings, 'Expedition':Expedition }
\ No newline at end of file
diff --git a/core/forms.py b/core/forms.py
index d3941b0..c7eb551 100644
--- a/core/forms.py
+++ b/core/forms.py
@@ -8,7 +8,7 @@ from django.contrib.admin.widgets import AdminDateWidget
#from tinymce.widgets import TinyMCE
-from troggle.core.models import Person, PersonExpedition, Expedition
+from troggle.core.models.troggle import Person, PersonExpedition, Expedition
from troggle.core.models_caves import Cave, LogbookEntry, QM, Entrance, CaveAndEntrance
class CaveForm(ModelForm):
@@ -76,46 +76,6 @@ class EntranceLetterForm(ModelForm):
model = CaveAndEntrance
exclude = ('cave', 'entrance')
-#This was all commneted out by Martin Green in 2012 !
-#class PersonForm(ModelForm):
-# class Meta:
-# model = Person
-
-#class LogbookEntryForm(ModelForm):
-# class Meta:
-# model = LogbookEntry#
-
-# def wikiLinkHints(LogbookEntry=None):
-# """
-# This function returns html-formatted paragraphs for each of the
-# wikilink types that are related to this logbookentry. Each paragraph
-# contains a list of all of the related wikilinks.
-#
-# Perhaps an admin javascript solution would be better.
-# """
-# res = ["Please use the following wikilinks, which are related to this logbook entry:"]
-#
-# res.append(r'
QMs found:')
-# for QM in LogbookEntry.instance.QMs_found.all():
-# res.append(QM.wiki_link())
-
-# res.append(r'
QMs ticked off:')
-# for QM in LogbookEntry.instance.QMs_ticked_off.all():
-# res.append(QM.wiki_link())
-
-# res.append(r'
People')
-# for persontrip in LogbookEntry.instance.persontrip_set.all():
-# res.append(persontrip.wiki_link())
-# res.append(r'
')
-
-# return string.join(res, r'
')
-
-# def __init__(self, *args, **kwargs):
-# super(LogbookEntryForm, self).__init__(*args, **kwargs)
-# self.fields['text'].help_text=self.wikiLinkHints()#
-
-#class CaveForm(forms.Form):
-# html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
def getTripForm(expedition):
diff --git a/core/models.py b/core/models.py
deleted file mode 100644
index 760c94f..0000000
--- a/core/models.py
+++ /dev/null
@@ -1,225 +0,0 @@
-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
-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
-the django Object Relational Mapping (ORM).
-There are more subclasses define in models_caves.py models_survex.py etc.
-"""
-
-
-#This class is for adding fields and methods which all of our models will have.
-class TroggleModel(models.Model):
- new_since_parsing = models.BooleanField(default=False, editable=False)
- non_public = models.BooleanField(default=False)
- def object_name(self):
- return self._meta.object_name
-
- def get_admin_url(self):
- return urljoin(settings.URL_ROOT, "/admin/core/" + self.object_name().lower() + "/" + str(self.pk))
-
- class Meta:
- abstract = True
-
-class DataIssue(TroggleModel):
- """When importing cave data any validation problems produce a message which is
- recorded as a DataIssue. The django admin system automatically prodiuces a page listing
- these at /admin/core/dataissue/
- This is a use of the NOTIFICATION pattern:
- https://martinfowler.com/eaaDev/Notification.html
-
- And we need to use it to replace all assertions in the code too:
- https://martinfowler.com/articles/replaceThrowWithNotification.html
- """
- date = models.DateTimeField(auto_now_add=True, blank=True)
- parser = models.CharField(max_length=50, blank=True, null=True)
- message = models.CharField(max_length=400, blank=True, null=True)
- url = models.CharField(max_length=300, blank=True, null=True) # link to offending object
-
- class Meta:
- ordering = ['date']
-
- def __str__(self):
- return "%s - %s" % (self.parser, self.message)
-
-#
-# single Expedition, usually seen by year
-#
-class Expedition(TroggleModel):
- year = models.CharField(max_length=20, unique=True)
- name = models.CharField(max_length=100)
-
- def __str__(self):
- return self.year
-
- class Meta:
- ordering = ('-year',)
- get_latest_by = 'year'
-
- def get_absolute_url(self):
- return urljoin(settings.URL_ROOT, reverse('expedition', args=[self.year]))
-
- # construction function. should be moved out
- def get_expedition_day(self, date):
- expeditiondays = self.expeditionday_set.filter(date=date)
- if expeditiondays:
- if len(expeditiondays) == 1:
- return expeditiondays[0]
- else:
- message ='! - more than one datum in an expeditionday: {}'.format(date)
- DataIssue.objects.create(parser='expedition', message=message)
- return expeditiondays[0]
- res = ExpeditionDay(expedition=self, date=date)
- res.save()
- return res
-
- def day_min(self):
- res = self.expeditionday_set.all()
- return res and res[0] or None
-
- def day_max(self):
- res = self.expeditionday_set.all()
- return res and res[len(res) - 1] or None
-
-class ExpeditionDay(TroggleModel):
- expedition = models.ForeignKey("Expedition",on_delete=models.CASCADE)
- date = models.DateField()
-
- class Meta:
- ordering = ('date',)
-
- def GetPersonTrip(self, personexpedition):
- personexpeditions = self.persontrip_set.filter(expeditionday=self)
- return personexpeditions and personexpeditions[0] or None
-
-class Person(TroggleModel):
- """single Person, can go on many years
- """
- first_name = models.CharField(max_length=100)
- last_name = models.CharField(max_length=100)
- fullname = models.CharField(max_length=200)
- is_vfho = models.BooleanField(help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.", default=False)
- mug_shot = models.CharField(max_length=100, blank=True,null=True)
- blurb = models.TextField(blank=True,null=True)
-
- #href = models.CharField(max_length=200)
- orderref = models.CharField(max_length=200) # for alphabetic
- user = models.OneToOneField(User, null=True, blank=True,on_delete=models.CASCADE)
- def get_absolute_url(self):
- return urljoin(settings.URL_ROOT,reverse('person',kwargs={'first_name':self.first_name,'last_name':self.last_name}))
-
- class Meta:
- verbose_name_plural = "People"
- ordering = ('orderref',) # "Wookey" makes too complex for: ('last_name', 'first_name')
-
- def __str__(self):
- if self.last_name:
- return "%s %s" % (self.first_name, self.last_name)
- return self.first_name
-
-
- def notability(self):
- notability = Decimal(0)
- max_expo_val = 0
-
- max_expo_year = Expedition.objects.all().aggregate(models.Max('year'))
- max_expo_val = int(max_expo_year['year__max']) + 1
-
- for personexpedition in self.personexpedition_set.all():
- if not personexpedition.is_guest:
- notability += Decimal(1) / (max_expo_val - int(personexpedition.expedition.year))
- return notability
-
- def bisnotable(self):
- return self.notability() > Decimal(1)/Decimal(3)
-
- def surveyedleglength(self):
- return sum([personexpedition.surveyedleglength() for personexpedition in self.personexpedition_set.all()])
-
- def first(self):
- return self.personexpedition_set.order_by('-expedition')[0]
- def last(self):
- return self.personexpedition_set.order_by('expedition')[0]
-
-class PersonExpedition(TroggleModel):
- """Person's attendance to one Expo
- """
- expedition = models.ForeignKey(Expedition,on_delete=models.CASCADE)
- person = models.ForeignKey(Person,on_delete=models.CASCADE)
- slugfield = models.SlugField(max_length=50,blank=True, null=True)
-
- is_guest = models.BooleanField(default=False)
- COMMITTEE_CHOICES = (
- ('leader','Expo leader'),
- ('medical','Expo medical officer'),
- ('treasurer','Expo treasurer'),
- ('sponsorship','Expo sponsorship coordinator'),
- ('research','Expo research coordinator'),
- )
- expo_committee_position = models.CharField(blank=True,null=True,choices=COMMITTEE_CHOICES,max_length=200)
- nickname = models.CharField(max_length=100,blank=True, null=True)
-
- def GetPersonroles(self):
- res = [ ]
- for personrole in self.personrole_set.order_by('survexblock'):
- if res and res[-1]['survexpath'] == personrole.survexblock.survexpath:
- res[-1]['roles'] += ", " + str(personrole.role)
- else:
- res.append({'date':personrole.survexblock.date, 'survexpath':personrole.survexblock.survexpath, 'roles':str(personrole.role)})
- return res
-
- class Meta:
- ordering = ('-expedition',)
- #order_with_respect_to = 'expedition'
-
- def __str__(self):
- return "%s: (%s)" % (self.person, self.expedition)
-
- #why is the below a function in personexpedition, rather than in person? - AC 14 Feb 09
- def name(self):
- if self.nickname:
- return "%s (%s) %s" % (self.person.first_name, self.nickname, self.person.last_name)
- if self.person.last_name:
- return "%s %s" % (self.person.first_name, self.person.last_name)
- return self.person.first_name
-
- def get_absolute_url(self):
- return urljoin(settings.URL_ROOT, reverse('personexpedition',kwargs={'first_name':self.person.first_name,'last_name':self.person.last_name,'year':self.expedition.year}))
-
- def surveyedleglength(self):
- survexblocks = [personrole.survexblock for personrole in self.survexpersonrole_set.all() ]
- return sum([survexblock.legslength for survexblock in set(survexblocks)])
-
- # would prefer to return actual person trips so we could link to first and last ones
- def day_min(self):
- res = self.persontrip_set.aggregate(day_min=Min("expeditionday__date"))
- return res["day_min"]
-
- def day_max(self):
- res = self.persontrip_set.all().aggregate(day_max=models.Max("expeditionday__date"))
- return res["day_max"]
-
-
diff --git a/core/models/__init__.py b/core/models/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/core/models/troggle.py b/core/models/troggle.py
new file mode 100644
index 0000000..760c94f
--- /dev/null
+++ b/core/models/troggle.py
@@ -0,0 +1,225 @@
+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
+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
+the django Object Relational Mapping (ORM).
+There are more subclasses define in models_caves.py models_survex.py etc.
+"""
+
+
+#This class is for adding fields and methods which all of our models will have.
+class TroggleModel(models.Model):
+ new_since_parsing = models.BooleanField(default=False, editable=False)
+ non_public = models.BooleanField(default=False)
+ def object_name(self):
+ return self._meta.object_name
+
+ def get_admin_url(self):
+ return urljoin(settings.URL_ROOT, "/admin/core/" + self.object_name().lower() + "/" + str(self.pk))
+
+ class Meta:
+ abstract = True
+
+class DataIssue(TroggleModel):
+ """When importing cave data any validation problems produce a message which is
+ recorded as a DataIssue. The django admin system automatically prodiuces a page listing
+ these at /admin/core/dataissue/
+ This is a use of the NOTIFICATION pattern:
+ https://martinfowler.com/eaaDev/Notification.html
+
+ And we need to use it to replace all assertions in the code too:
+ https://martinfowler.com/articles/replaceThrowWithNotification.html
+ """
+ date = models.DateTimeField(auto_now_add=True, blank=True)
+ parser = models.CharField(max_length=50, blank=True, null=True)
+ message = models.CharField(max_length=400, blank=True, null=True)
+ url = models.CharField(max_length=300, blank=True, null=True) # link to offending object
+
+ class Meta:
+ ordering = ['date']
+
+ def __str__(self):
+ return "%s - %s" % (self.parser, self.message)
+
+#
+# single Expedition, usually seen by year
+#
+class Expedition(TroggleModel):
+ year = models.CharField(max_length=20, unique=True)
+ name = models.CharField(max_length=100)
+
+ def __str__(self):
+ return self.year
+
+ class Meta:
+ ordering = ('-year',)
+ get_latest_by = 'year'
+
+ def get_absolute_url(self):
+ return urljoin(settings.URL_ROOT, reverse('expedition', args=[self.year]))
+
+ # construction function. should be moved out
+ def get_expedition_day(self, date):
+ expeditiondays = self.expeditionday_set.filter(date=date)
+ if expeditiondays:
+ if len(expeditiondays) == 1:
+ return expeditiondays[0]
+ else:
+ message ='! - more than one datum in an expeditionday: {}'.format(date)
+ DataIssue.objects.create(parser='expedition', message=message)
+ return expeditiondays[0]
+ res = ExpeditionDay(expedition=self, date=date)
+ res.save()
+ return res
+
+ def day_min(self):
+ res = self.expeditionday_set.all()
+ return res and res[0] or None
+
+ def day_max(self):
+ res = self.expeditionday_set.all()
+ return res and res[len(res) - 1] or None
+
+class ExpeditionDay(TroggleModel):
+ expedition = models.ForeignKey("Expedition",on_delete=models.CASCADE)
+ date = models.DateField()
+
+ class Meta:
+ ordering = ('date',)
+
+ def GetPersonTrip(self, personexpedition):
+ personexpeditions = self.persontrip_set.filter(expeditionday=self)
+ return personexpeditions and personexpeditions[0] or None
+
+class Person(TroggleModel):
+ """single Person, can go on many years
+ """
+ first_name = models.CharField(max_length=100)
+ last_name = models.CharField(max_length=100)
+ fullname = models.CharField(max_length=200)
+ is_vfho = models.BooleanField(help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.", default=False)
+ mug_shot = models.CharField(max_length=100, blank=True,null=True)
+ blurb = models.TextField(blank=True,null=True)
+
+ #href = models.CharField(max_length=200)
+ orderref = models.CharField(max_length=200) # for alphabetic
+ user = models.OneToOneField(User, null=True, blank=True,on_delete=models.CASCADE)
+ def get_absolute_url(self):
+ return urljoin(settings.URL_ROOT,reverse('person',kwargs={'first_name':self.first_name,'last_name':self.last_name}))
+
+ class Meta:
+ verbose_name_plural = "People"
+ ordering = ('orderref',) # "Wookey" makes too complex for: ('last_name', 'first_name')
+
+ def __str__(self):
+ if self.last_name:
+ return "%s %s" % (self.first_name, self.last_name)
+ return self.first_name
+
+
+ def notability(self):
+ notability = Decimal(0)
+ max_expo_val = 0
+
+ max_expo_year = Expedition.objects.all().aggregate(models.Max('year'))
+ max_expo_val = int(max_expo_year['year__max']) + 1
+
+ for personexpedition in self.personexpedition_set.all():
+ if not personexpedition.is_guest:
+ notability += Decimal(1) / (max_expo_val - int(personexpedition.expedition.year))
+ return notability
+
+ def bisnotable(self):
+ return self.notability() > Decimal(1)/Decimal(3)
+
+ def surveyedleglength(self):
+ return sum([personexpedition.surveyedleglength() for personexpedition in self.personexpedition_set.all()])
+
+ def first(self):
+ return self.personexpedition_set.order_by('-expedition')[0]
+ def last(self):
+ return self.personexpedition_set.order_by('expedition')[0]
+
+class PersonExpedition(TroggleModel):
+ """Person's attendance to one Expo
+ """
+ expedition = models.ForeignKey(Expedition,on_delete=models.CASCADE)
+ person = models.ForeignKey(Person,on_delete=models.CASCADE)
+ slugfield = models.SlugField(max_length=50,blank=True, null=True)
+
+ is_guest = models.BooleanField(default=False)
+ COMMITTEE_CHOICES = (
+ ('leader','Expo leader'),
+ ('medical','Expo medical officer'),
+ ('treasurer','Expo treasurer'),
+ ('sponsorship','Expo sponsorship coordinator'),
+ ('research','Expo research coordinator'),
+ )
+ expo_committee_position = models.CharField(blank=True,null=True,choices=COMMITTEE_CHOICES,max_length=200)
+ nickname = models.CharField(max_length=100,blank=True, null=True)
+
+ def GetPersonroles(self):
+ res = [ ]
+ for personrole in self.personrole_set.order_by('survexblock'):
+ if res and res[-1]['survexpath'] == personrole.survexblock.survexpath:
+ res[-1]['roles'] += ", " + str(personrole.role)
+ else:
+ res.append({'date':personrole.survexblock.date, 'survexpath':personrole.survexblock.survexpath, 'roles':str(personrole.role)})
+ return res
+
+ class Meta:
+ ordering = ('-expedition',)
+ #order_with_respect_to = 'expedition'
+
+ def __str__(self):
+ return "%s: (%s)" % (self.person, self.expedition)
+
+ #why is the below a function in personexpedition, rather than in person? - AC 14 Feb 09
+ def name(self):
+ if self.nickname:
+ return "%s (%s) %s" % (self.person.first_name, self.nickname, self.person.last_name)
+ if self.person.last_name:
+ return "%s %s" % (self.person.first_name, self.person.last_name)
+ return self.person.first_name
+
+ def get_absolute_url(self):
+ return urljoin(settings.URL_ROOT, reverse('personexpedition',kwargs={'first_name':self.person.first_name,'last_name':self.person.last_name,'year':self.expedition.year}))
+
+ def surveyedleglength(self):
+ survexblocks = [personrole.survexblock for personrole in self.survexpersonrole_set.all() ]
+ return sum([survexblock.legslength for survexblock in set(survexblocks)])
+
+ # would prefer to return actual person trips so we could link to first and last ones
+ def day_min(self):
+ res = self.persontrip_set.aggregate(day_min=Min("expeditionday__date"))
+ return res["day_min"]
+
+ def day_max(self):
+ res = self.persontrip_set.all().aggregate(day_max=models.Max("expeditionday__date"))
+ return res["day_max"]
+
+
diff --git a/core/models_caves.py b/core/models_caves.py
index f28f3b6..b0ecb53 100644
--- a/core/models_caves.py
+++ b/core/models_caves.py
@@ -20,9 +20,8 @@ from django.conf import settings
from django.urls import reverse
from django.template import Context, loader
-from troggle.core.models import TroggleModel, Person, Expedition
+from troggle.core.models.troggle import TroggleModel, Person, Expedition, DataIssue
from troggle.core.models_survex import SurvexStation
-from troggle.core.models import DataIssue
class Area(TroggleModel):
short_name = models.CharField(max_length=100)
diff --git a/core/unused.py b/core/unused.py
index e26a212..e9943e7 100644
--- a/core/unused.py
+++ b/core/unused.py
@@ -90,11 +90,11 @@ def html_to_wiki(text, codec = "utf-8"):
lists = ""
#lists
while text:
- mstar = re.match("^(.*?)]*>\s*- ]*>(.*?)
(.*)$", text, re.DOTALL)
- munstar = re.match("^(\s*)
(.*)$", text, re.DOTALL)
- mhash = re.match("^(.*?)]*>\s*- ]*>(.*?)
(.*)$", text, re.DOTALL)
- munhash = re.match("^(\s*)
(.*)$", text, re.DOTALL)
- mitem = re.match("^(\s*)]*>(.*?)(.*)$", text, re.DOTALL)
+ mstar = re.match(r"^(.*?)]*>\s*- ]*>(.*?)
(.*)$", text, re.DOTALL)
+ munstar = re.match(r"^(\s*)
(.*)$", text, re.DOTALL)
+ mhash = re.match(r"^(.*?)]*>\s*- ]*>(.*?)
(.*)$", text, re.DOTALL)
+ munhash = re.match(r"^(\s*)
(.*)$", text, re.DOTALL)
+ mitem = re.match(r"^(\s*)]*>(.*?)(.*)$", text, re.DOTALL)
ms = [len(m.groups()[0]) for m in [mstar, munstar, mhash, munhash, mitem] if m]
def min_(i, l):
try:
diff --git a/core/utils.py b/core/utils.py
index 84a8191..b2a9249 100644
--- a/core/utils.py
+++ b/core/utils.py
@@ -21,13 +21,11 @@ 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
+troggle.utils.TROG
chaosmonkey(n) - used by survex import to regenerate some .3d files
save_carefully() - core function that saves troggle objects in the database
@@ -102,22 +100,6 @@ def save_carefully(objectType, lookupAttribs={}, nonLookupAttribs={}):
logging.info(str(instance) + " existed in the database unchanged since last parse. It was overwritten by the current script. \n")
return (instance, created)
-# 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/caves.py b/core/views/caves.py
index e3b114d..8c02ea2 100644
--- a/core/views/caves.py
+++ b/core/views/caves.py
@@ -17,7 +17,7 @@ from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
import troggle.settings as settings
#import troggle.core.models as models
from troggle.core.views import expo
-from troggle.core.models import Expedition, DataIssue
+from troggle.core.models.troggle 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 .login import login_required_if_public
diff --git a/core/views/logbooks.py b/core/views/logbooks.py
index 1db2edc..f74c21f 100644
--- a/core/views/logbooks.py
+++ b/core/views/logbooks.py
@@ -14,7 +14,7 @@ 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
+from troggle.core.models.troggle 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
diff --git a/core/views/other.py b/core/views/other.py
index d65f3e6..30b3093 100644
--- a/core/views/other.py
+++ b/core/views/other.py
@@ -9,7 +9,7 @@ from django.shortcuts import render
from django.template import Context, loader
import troggle.parsers.imports
-from troggle.core.models import Expedition, Person, PersonExpedition
+from troggle.core.models.troggle import Expedition, Person, PersonExpedition
from troggle.core.models_caves import LogbookEntry, QM, Cave, PersonTrip
from .login import login_required_if_public
from troggle.core.forms import UploadFileForm
diff --git a/core/views/statistics.py b/core/views/statistics.py
index ac1e7ac..9c45f9f 100644
--- a/core/views/statistics.py
+++ b/core/views/statistics.py
@@ -11,7 +11,7 @@ from django.template.defaultfilters import slugify
from django.utils import timezone
#from django.views.generic.list import ListView
-from troggle.core.models import Expedition, Person, PersonExpedition, DataIssue
+from troggle.core.models.troggle import Expedition, Person, PersonExpedition, DataIssue
from troggle.core.models_caves import Cave, LogbookEntry
from troggle.core.models_survex import SurvexBlock
diff --git a/core/views/survex.py b/core/views/survex.py
index 0818e0c..3aee5f8 100644
--- a/core/views/survex.py
+++ b/core/views/survex.py
@@ -14,7 +14,7 @@ from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
import troggle.settings as settings
import parsers.survex
-from troggle.core.models import Expedition, Person, PersonExpedition
+from troggle.core.models.troggle import Expedition, Person, PersonExpedition
from troggle.core.models_survex import SurvexBlock, SurvexPersonRole, SurvexFile, SurvexDirectory
from troggle.core.models_caves import Cave, PersonTrip, LogbookEntry
from troggle.parsers.people import GetPersonExpeditionNameLookup
diff --git a/databaseReset.py b/databaseReset.py
index 9151a43..aec6922 100644
--- a/databaseReset.py
+++ b/databaseReset.py
@@ -33,7 +33,7 @@ except:
raise
print(" - Memory footprint after loading Django: {:.3f} MB".format(resource.getrusage(resource.RUSAGE_SELF)[2]/1024.0))
-import troggle.core.models
+from troggle.core.models import DataIssue
import troggle.core.models_survex
from django.core import management
@@ -43,7 +43,7 @@ from django.urls import reverse
from django.contrib.auth.models import User
from django.db import transaction
-from troggle.core.models import get_process_memory
+from troggle.core.utils import get_process_memory
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_loadpos, import_drawingsfiles
diff --git a/parsers/QMs.py b/parsers/QMs.py
index 7449a8a..2816c8a 100644
--- a/parsers/QMs.py
+++ b/parsers/QMs.py
@@ -5,7 +5,7 @@ from datetime import date
from django.conf import settings
-from troggle.core.models import DataIssue
+from troggle.core.models.troggle import DataIssue
from troggle.core.models_caves import QM, Cave, LogbookEntry
from troggle.core.utils import save_carefully
diff --git a/parsers/caves.py b/parsers/caves.py
index 533bf61..8ddc424 100644
--- a/parsers/caves.py
+++ b/parsers/caves.py
@@ -4,7 +4,7 @@ import re
from django.conf import settings
from django.db import transaction
-from troggle.core.models import DataIssue, get_process_memory
+from troggle.core.models.troggle import DataIssue
from troggle.core.models_caves import Area, Cave, Entrance, CaveSlug, EntranceSlug, CaveAndEntrance
'''Reads all the cave description data by parsing the xml files (stored as e.g. :EXPOWEB:/cave-data/1623-161.html )
and creating the various Cave, Entrance and necessary Area objects.
diff --git a/parsers/logbooks.py b/parsers/logbooks.py
index b6a326c..58e425b 100644
--- a/parsers/logbooks.py
+++ b/parsers/logbooks.py
@@ -10,7 +10,7 @@ from django.conf import settings
from django.template.defaultfilters import slugify
from django.utils.timezone import get_current_timezone, make_aware
-from troggle.core.models import DataIssue, Expedition
+from troggle.core.models.troggle import DataIssue, Expedition
from troggle.core.utils import TROG, save_carefully
from troggle.core.models_caves import Cave, LogbookEntry, PersonTrip, GetCaveLookup
from parsers.people import GetPersonExpeditionNameLookup
diff --git a/parsers/surveys.py b/parsers/surveys.py
index 3207194..c75bf7c 100644
--- a/parsers/surveys.py
+++ b/parsers/surveys.py
@@ -12,7 +12,7 @@ from functools import reduce
import settings
from troggle.core.models_survex import SingleScan, ScansFolder, TunnelFile
-from troggle.core.models import DataIssue
+from troggle.core.models.troggle import DataIssue
from troggle.core.utils import save_carefully
--
cgit v1.2.3