2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-23 07:41:52 +00:00

[svn] Make QM wikilinks work in new format, and fix cave description parser to output working wikilinks.

This commit is contained in:
substantialnoninfringinguser 2009-07-09 05:08:21 +01:00
parent f359b645e6
commit 3a61639a08
3 changed files with 16 additions and 9 deletions

View File

@ -512,12 +512,19 @@ class CaveDescription(TroggleModel):
short_name = models.CharField(max_length=50, unique = True) short_name = models.CharField(max_length=50, unique = True)
long_name = models.CharField(max_length=200, blank=True, null=True) long_name = models.CharField(max_length=200, blank=True, null=True)
description = models.TextField(blank=True,null=True) description = models.TextField(blank=True,null=True)
linked_subcaves = models.ManyToManyField("NewSubCave") linked_subcaves = models.ManyToManyField("NewSubCave", blank=True,null=True)
linked_entrances = models.ManyToManyField("Entrance") linked_entrances = models.ManyToManyField("Entrance", blank=True,null=True)
linked_qms = models.ManyToManyField("QM") linked_qms = models.ManyToManyField("QM", blank=True,null=True)
def __unicode__(self): def __unicode__(self):
if self.long_name:
return unicode(self.long_name)
else:
return unicode(self.short_name) return unicode(self.short_name)
def get_absolute_url(self):
return urlparse.urljoin(settings.URL_ROOT, reverse('cavedescription', args=(self.short_name,)))
class NewSubCave(TroggleModel): class NewSubCave(TroggleModel):
name = models.CharField(max_length=200, unique = True) name = models.CharField(max_length=200, unique = True)
def __unicode__(self): def __unicode__(self):

View File

@ -71,7 +71,7 @@ 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*QM:([ABC]?)(\d*)-(\d{4})-(\d*)\]\]" qmMatchPattern="\[\[\s*[Qq][Mm]:([ABC]?)(\d{4})-(\d*)-(\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.
@ -79,7 +79,7 @@ def wiki_to_html_short(value, autoescape=None):
[[QM:C204-1999-24]] [[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.
""" """
qmdict={'urlroot':url_root,'cave':matchobj.groups()[1],'year':matchobj.groups()[2],'number':matchobj.groups()[3]} qmdict={'urlroot':url_root,'cave':matchobj.groups()[2],'year':matchobj.groups()[1],'number':matchobj.groups()[3]}
try: try:
qm=QM.objects.get(found_by__cave__kataster_number = qmdict['cave'], qm=QM.objects.get(found_by__cave__kataster_number = qmdict['cave'],
found_by__date__year = qmdict['year'], found_by__date__year = qmdict['year'],
@ -95,7 +95,7 @@ def wiki_to_html_short(value, autoescape=None):
title='placeholder' title='placeholder'
) )
qm=QM(found_by = placeholder, number = qmdict['number']) qm=QM(found_by = placeholder, number = qmdict['number'])
return r'<a class="redtext" href="%s" id="q%s">%s %s</a>' % (qm.get_absolute_url, qm.code, unicode(qm)) return r'<a class="redtext" href="%s" id="q%s">%s</a>' % (qm.get_absolute_url(), qm.code, unicode(qm))
value = re.sub(qmMatchPattern,qmrepl, value, re.DOTALL) value = re.sub(qmMatchPattern,qmrepl, value, re.DOTALL)

View File

@ -103,8 +103,8 @@ re_subs = [(re.compile(r"\<b[^>]*\>(.*?)\</b\>", re.DOTALL), r"'''\1'''"),
(re.compile(r"\<h6[^>]*\>(.*?)\</h6\>", re.DOTALL), r"======\1======"), (re.compile(r"\<h6[^>]*\>(.*?)\</h6\>", re.DOTALL), r"======\1======"),
(re.compile(r"\<a\s+id=['\"]([^'\"]*)['\"]\s*\>(.*?)\</a\>", re.DOTALL), r"[subcave:\1|\2]"), (re.compile(r"\<a\s+id=['\"]([^'\"]*)['\"]\s*\>(.*?)\</a\>", re.DOTALL), r"[subcave:\1|\2]"),
#interpage link needed #interpage link needed
(re.compile(r"\<a\s+href=['\"]#([^'\"]*)['\"]\s*\>(.*?)\</a\>", re.DOTALL), r"[cavedescription:\1|\2]"), (re.compile(r"\<a\s+href=['\"]#([^'\"]*)['\"]\s*\>(.*?)\</a\>", re.DOTALL), r"[[cavedescription:\1|\2]]"),
(re.compile(r"\[\<a\s+href=['\"][^'\"]*['\"]\s+id=['\"][^'\"]*['\"]\s*\>([^\s]*).*?\</a\>\]", re.DOTALL), r"![qm:\1]"), (re.compile(r"\[\<a\s+href=['\"][^'\"]*['\"]\s+id=['\"][^'\"]*['\"]\s*\>([^\s]*).*?\</a\>\]", re.DOTALL), r"[[qm:\1]]"),
] ]