[svn] wiki_to_html changes.

Changes views of qm model.
This commit is contained in:
martin speleo 2009-07-04 19:35:06 +01:00
parent 7f2199405d
commit 8a9eb32aaf
2 changed files with 24 additions and 22 deletions

View File

@ -546,8 +546,10 @@ class QM(TroggleModel):
comment=models.TextField(blank=True,null=True) comment=models.TextField(blank=True,null=True)
def __unicode__(self): def __unicode__(self):
QMnumber=str(self.found_by.cave)+'-'+str(self.found_by.date.year)+"-"+str(self.number)+self.grade return u"%s %s" % (self.code(), self.grade)
return str(QMnumber)
def code(self):
return u"%s-%s-%s" % (self.found_by.date.year, self.found_by.cave, self.number
def get_absolute_url(self): def get_absolute_url(self):
#return settings.URL_ROOT + '/cave/' + self.found_by.cave.kataster_number + '/' + str(self.found_by.date.year) + '-' + '%02d' %self.number #return settings.URL_ROOT + '/cave/' + self.found_by.cave.kataster_number + '/' + str(self.found_by.date.year) + '-' + '%02d' %self.number

View File

@ -38,6 +38,10 @@ def wiki_list(line, listdepth):
@register.filter() @register.filter()
@stringfilter @stringfilter
def wiki_to_html(value, autoescape=None): def wiki_to_html(value, autoescape=None):
"""
This is the tag which turns wiki syntax into html. It is intended for long pieces of wiki.
Hence it splits the wiki into paragraphs double line feeds.
"""
#find paragraphs #find paragraphs
outValue = "" outValue = ""
for paragraph in re.split("\n\s*?\n", value, re.DOTALL): for paragraph in re.split("\n\s*?\n", value, re.DOTALL):
@ -50,9 +54,8 @@ def wiki_to_html(value, autoescape=None):
@stringfilter @stringfilter
def wiki_to_html_short(value, autoescape=None): def wiki_to_html_short(value, autoescape=None):
""" """
This is the tag which turns wiki syntax into html. Aaron wonders This is the tag which turns wiki syntax into html. It is intended for short pieces of wiki.
why it is called "short." It is long, and it operates on long things. Hence it is not split the wiki into paragraphs using where it find double line feeds.
It even has a long name itself.
""" """
if autoescape: if autoescape:
value = conditional_escape(value) value = conditional_escape(value)
@ -60,7 +63,7 @@ def wiki_to_html_short(value, autoescape=None):
value = re.sub("&(.*?);", r"&\1;", value, re.DOTALL) value = re.sub("&(.*?);", r"&\1;", value, re.DOTALL)
#italics and bold #italics and bold
value = re.sub("&#39;&#39;&#39;&#39;([^']+)&#39;&#39;&#39;&#39;", r"<b><i>\1</i></b>", value, re.DOTALL) value = re.sub("&#39;&#39;&#39;&#39;([^']+)&#39;&#39;&#39;&#39;", r"<b><i>\1</i></b>", value, re.DOTALL)
value = re.sub("&#39;&#39;&#39;([^']+)&#39;&#39;&#39;", r"<b>\1</b>", value, re.DOTALL) value = re.sub("&#39;b&#39;&#39;([^']+)&#39;&#39;&#39;", r"<b>\1</b>", value, re.DOTALL)
value = re.sub("&#39;&#39;([^']+)&#39;&#39;", r"<i>\1</i>", value, re.DOTALL) value = re.sub("&#39;&#39;([^']+)&#39;&#39;", r"<i>\1</i>", value, re.DOTALL)
#make cave links #make cave links
value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'<a href="%s/cave/\1/">\1</a>' % url_root, value, re.DOTALL) value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'<a href="%s/cave/\1/">\1</a>' % url_root, value, re.DOTALL)
@ -68,26 +71,23 @@ def wiki_to_html_short(value, autoescape=None):
value = re.sub("\[\[\s*person:(.+)\]\]",r'<a href="%s/person/\1/">\1</a>' % url_root, value, re.DOTALL) value = re.sub("\[\[\s*person:(.+)\]\]",r'<a href="%s/person/\1/">\1</a>' % url_root, value, re.DOTALL)
#make qm links. this takes a little doing #make qm links. this takes a little doing
qmMatchPattern="\[\[\s*cave:([^\s]+)\s*\s*\QM:(\d*)-(\d*)([ABCDX]?)\]\]" qmMatchPattern="\[\[\s*QM:([ABC]?)(\d*)-(\d{4})-(\d*)\]\]"
def qmrepl(matchobj): def qmrepl(matchobj):
""" """
A function for replacing wikicode qm links with html qm links. A function for replacing wikicode qm links with html qm links.
Given a matchobj matching a wikilink in the format Given a matchobj matching a wikilink in the format
[[cave:204 QM:1999-24C]] where the grade (C) is optional. [[QM:C204-1999-24]]
If the QM does not exist, the function will return a link for creating it. If the QM does not exist, the function will return a link for creating it.
""" """
# if there are four matched groups, the fourth one should be the QM grade qmdict={'urlroot':url_root,'cave':matchobj.groups()[2],'year':matchobj.groups()[1],'number':matchobj.groups()[3]}
if len(matchobj.groups())==4:
grade=matchobj.groups()[3]
else:
grade=''
qmdict={'urlroot':url_root,'cave':matchobj.groups()[0],'year':matchobj.groups()[1],'number':matchobj.groups()[2],'grade':grade}
try: try:
qm=QM.objects.get(found_by__cave__kataster_number=qmdict['cave'],found_by__date__year=qmdict['year'], number=qmdict['number']) qm=QM.objects.get(found_by__cave__kataster_number = qmdict['cave'],
res=r'<a href=' + str(qm.get_absolute_url()) +'>' + str(qm) + '</a>' found_by__date__year = qmdict['year'],
number = qmdict['number'])
return r'<a href="%s" id="q%s">%s %s</a>' % ("insert url lookup here", qm.code, unicode(qm))
except QM.DoesNotExist: except QM.DoesNotExist:
res = r'<a class="redtext" href="%(urlroot)s/cave/%(cave)s/%(year)s-%(number)s%(grade)s">%(cave)s:%(year)s-%(number)s%(grade)s</a>' % qmdict return r'<a class="redtext" href="%(urlroot)s/cave/%(cave)s/%(year)s-%(number)s%(grade)s">%(cave)s:%(year)s-%(number)s%(grade)s</a>' % qmdict
return res
value = re.sub(qmMatchPattern,qmrepl, value, re.DOTALL) value = re.sub(qmMatchPattern,qmrepl, value, re.DOTALL)
#make photo links for [[photo:filename]] or [[photo:filename linktext]], and #make photo links for [[photo:filename]] or [[photo:filename linktext]], and