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 | 6f0be2c492cce8012a9bcd4cd31e91566511f3cb (patch) | |
tree | 7d4ded87df2007c0141eda3b7f298b84305bc4dd /utils.py | |
parent | 3a61639a08b08c312130abe971652ad210e2b78d (diff) | |
download | troggle-6f0be2c492cce8012a9bcd4cd31e91566511f3cb.tar.gz troggle-6f0be2c492cce8012a9bcd4cd31e91566511f3cb.tar.bz2 troggle-6f0be2c492cce8012a9bcd4cd31e91566511f3cb.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
+
+
|