From 6f0be2c492cce8012a9bcd4cd31e91566511f3cb Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Sat, 11 Jul 2009 01:36:00 +0100 Subject: [svn] override save for CaveDescriptions to scan qm wikilinks and add into the manytomany field linked_qms --- utils.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'utils.py') diff --git a/utils.py b/utils.py index 2c181c7..5245589 100644 --- a/utils.py +++ b/utils.py @@ -1,8 +1,5 @@ from django.conf import settings -try: - from django.db import models -except:#We want to get rid of this try statement if possible - from troggle.core.models import LogbookEntry + import random, re, logging def weighted_choice(lst): @@ -14,16 +11,17 @@ def weighted_choice(lst): return item def randomLogbookSentence(): + from troggle.core.models import LogbookEntry randSent={} # needs to handle empty logbooks without crashing #Choose a random logbook entry - randSent['entry']=models.LogbookEntry.objects.order_by('?')[0] + randSent['entry']=LogbookEntry.objects.order_by('?')[0] #Choose again if there are no sentances (this happens if it is a placeholder entry) while len(re.findall('[A-Z].*?\.',randSent['entry'].text))==0: - randSent['entry']=models.LogbookEntry.objects.order_by('?')[0] + randSent['entry']=LogbookEntry.objects.order_by('?')[0] #Choose a random sentence from that entry. Store the sentence as randSent['sentence'], and the number of that sentence in the entry as randSent['number'] sentenceList=re.findall('[A-Z].*?\.',randSent['entry'].text) @@ -157,4 +155,6 @@ def html_to_wiki(text, codec = "utf-8"): #substitutions for regex, repl in re_subs: out = regex.sub(repl, out) - return out \ No newline at end of file + return out + + -- cgit v1.2.3