forked from expo/troggle
Commented-out unused CaveDescription object
This commit is contained in:
31
utils.py
31
utils.py
@@ -5,7 +5,7 @@ import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django.shortcuts import render
|
||||
from troggle.core.models_caves import CaveDescription
|
||||
#from troggle.core.models_caves import CaveDescription
|
||||
"""Oddball mixture of critical, superfluous and useful functions which should
|
||||
be re-located more sensibly to other modules:
|
||||
|
||||
@@ -113,20 +113,20 @@ def get_single_match(regex, text):
|
||||
else:
|
||||
return None
|
||||
|
||||
def href_to_wikilinks(matchobj):
|
||||
"""
|
||||
Given an html link, checks for possible valid wikilinks.
|
||||
# def href_to_wikilinks(matchobj):
|
||||
# """
|
||||
# Given an html link, checks for possible valid wikilinks.
|
||||
|
||||
Returns the first valid wikilink. Valid means the target
|
||||
object actually exists.
|
||||
"""
|
||||
res=CaveDescription.objects.filter(long_name__icontains=matchobj.groupdict()['text'])
|
||||
if res and res[0]:
|
||||
return r'[[cavedescription:'+res[0].short_name+'|'+res[0].long_name+']]'
|
||||
else:
|
||||
return matchobj.group()
|
||||
#except:
|
||||
#print 'fail'
|
||||
# Returns the first valid wikilink. Valid means the target
|
||||
# object actually exists.
|
||||
# """
|
||||
# res=CaveDescription.objects.filter(long_name__icontains=matchobj.groupdict()['text'])
|
||||
# if res and res[0]:
|
||||
# return r'[[cavedescription:'+res[0].short_name+'|'+res[0].long_name+']]'
|
||||
# else:
|
||||
# return matchobj.group()
|
||||
# #except:
|
||||
# #print 'fail'
|
||||
|
||||
|
||||
re_subs = [(re.compile(r"\<b[^>]*\>(.*?)\</b\>", re.DOTALL), r"'''\1'''"),
|
||||
@@ -142,8 +142,7 @@ re_subs = [(re.compile(r"\<b[^>]*\>(.*?)\</b\>", re.DOTALL), r"'''\1'''"),
|
||||
#interpage link needed
|
||||
(re.compile(r"\<a\s+href=['\"]#([^'\"]*)['\"]\s*\>(.*?)\</a\>", re.DOTALL), r"[[cavedescription:\1|\2]]"), #assumes that all links with target ids are cave descriptions. Not great.
|
||||
(re.compile(r"\[\<a\s+href=['\"][^'\"]*['\"]\s+id=['\"][^'\"]*['\"]\s*\>([^\s]*).*?\</a\>\]", re.DOTALL), r"[[qm:\1]]"),
|
||||
(re.compile(r'<a\shref="?(?P<target>.*)"?>(?P<text>.*)</a>'),href_to_wikilinks),
|
||||
|
||||
# (re.compile(r'<a\shref="?(?P<target>.*)"?>(?P<text>.*)</a>'),href_to_wikilinks),
|
||||
]
|
||||
|
||||
def html_to_wiki(text, codec = "utf-8"):
|
||||
|
||||
Reference in New Issue
Block a user