diff options
author | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-07-11 01:36:00 +0100 |
---|---|---|
committer | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-07-11 01:36:00 +0100 |
commit | 2993ca74cccf9f0464490f91c97517d1a0fab901 (patch) | |
tree | 68e4623d707b46132cd032df76f1757b01d81dd0 /utils.py | |
parent | 1566923d5cf8680e5df2b43ce1b44d42a65ed590 (diff) | |
download | troggle-2993ca74cccf9f0464490f91c97517d1a0fab901.tar.gz troggle-2993ca74cccf9f0464490f91c97517d1a0fab901.tar.bz2 troggle-2993ca74cccf9f0464490f91c97517d1a0fab901.zip |
[svn] override save for CaveDescriptions to scan qm wikilinks and add into the manytomany field linked_qms
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -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
+
+
|