diff --git a/core/models.py b/core/models.py
index cc185a1..c438a92 100644
--- a/core/models.py
+++ b/core/models.py
@@ -546,8 +546,10 @@ class QM(TroggleModel):
comment=models.TextField(blank=True,null=True)
def __unicode__(self):
- QMnumber=str(self.found_by.cave)+'-'+str(self.found_by.date.year)+"-"+str(self.number)+self.grade
- return str(QMnumber)
+ return u"%s %s" % (self.code(), self.grade)
+
+ def code(self):
+ return u"%s-%s-%s" % (self.found_by.date.year, self.found_by.cave, self.number
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
diff --git a/core/templatetags/wiki_markup.py b/core/templatetags/wiki_markup.py
index 07e6468..8307458 100644
--- a/core/templatetags/wiki_markup.py
+++ b/core/templatetags/wiki_markup.py
@@ -38,6 +38,10 @@ def wiki_list(line, listdepth):
@register.filter()
@stringfilter
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
outValue = ""
for paragraph in re.split("\n\s*?\n", value, re.DOTALL):
@@ -50,9 +54,8 @@ def wiki_to_html(value, autoescape=None):
@stringfilter
def wiki_to_html_short(value, autoescape=None):
"""
- This is the tag which turns wiki syntax into html. Aaron wonders
- why it is called "short." It is long, and it operates on long things.
- It even has a long name itself.
+ This is the tag which turns wiki syntax into html. It is intended for short pieces of wiki.
+ Hence it is not split the wiki into paragraphs using where it find double line feeds.
"""
if autoescape:
value = conditional_escape(value)
@@ -60,36 +63,33 @@ def wiki_to_html_short(value, autoescape=None):
value = re.sub("&(.*?);", r"&\1;", value, re.DOTALL)
#italics and bold
value = re.sub("''''([^']+)''''", r"\1", value, re.DOTALL)
- value = re.sub("'''([^']+)'''", r"\1", value, re.DOTALL)
+ value = re.sub("'b''([^']+)'''", r"\1", value, re.DOTALL)
value = re.sub("''([^']+)''", r"\1", value, re.DOTALL)
#make cave links
value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'\1' % url_root, value, re.DOTALL)
#make people links
value = re.sub("\[\[\s*person:(.+)\]\]",r'\1' % url_root, value, re.DOTALL)
-
+
#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):
"""
A function for replacing wikicode qm links with html qm links.
- Given a matchobj matching a wikilink in the format
- [[cave:204 QM:1999-24C]] where the grade (C) is optional.
+ Given a matchobj matching a wikilink in the format
+ [[QM:C204-1999-24]]
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
- 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}
+ qmdict={'urlroot':url_root,'cave':matchobj.groups()[2],'year':matchobj.groups()[1],'number':matchobj.groups()[3]}
try:
- qm=QM.objects.get(found_by__cave__kataster_number=qmdict['cave'],found_by__date__year=qmdict['year'], number=qmdict['number'])
- res=r'' + str(qm) + ''
+ qm=QM.objects.get(found_by__cave__kataster_number = qmdict['cave'],
+ found_by__date__year = qmdict['year'],
+ number = qmdict['number'])
+ return r'%s %s' % ("insert url lookup here", qm.code, unicode(qm))
except QM.DoesNotExist:
- res = r'%(cave)s:%(year)s-%(number)s%(grade)s' % qmdict
- return res
+ return r'%(cave)s:%(year)s-%(number)s%(grade)s' % qmdict
+
value = re.sub(qmMatchPattern,qmrepl, value, re.DOTALL)
-
+
#make photo links for [[photo:filename]] or [[photo:filename linktext]], and
#insert photos for [[display:left photo:filename]]
photoLinkPattern="\[\[\s*photo:(?P[^\s]+)\s*(?P.*)\]\]"
@@ -100,7 +100,7 @@ def wiki_to_html_short(value, autoescape=None):
linkText=matchdict['linkText']
except KeyError:
linkText=None
-
+
try:
photo=Photo.objects.get(file=matchdict['photoName'])
if not linkText: