From 3a61639a08b08c312130abe971652ad210e2b78d Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Thu, 9 Jul 2009 05:08:21 +0100 Subject: [PATCH] [svn] Make QM wikilinks work in new format, and fix cave description parser to output working wikilinks. --- core/models.py | 15 +++++++++++---- core/templatetags/wiki_markup.py | 6 +++--- utils.py | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/core/models.py b/core/models.py index cb2d8d4..facc5ff 100644 --- a/core/models.py +++ b/core/models.py @@ -512,11 +512,18 @@ class CaveDescription(TroggleModel): short_name = models.CharField(max_length=50, unique = True) long_name = models.CharField(max_length=200, blank=True, null=True) description = models.TextField(blank=True,null=True) - linked_subcaves = models.ManyToManyField("NewSubCave") - linked_entrances = models.ManyToManyField("Entrance") - linked_qms = models.ManyToManyField("QM") + linked_subcaves = models.ManyToManyField("NewSubCave", blank=True,null=True) + linked_entrances = models.ManyToManyField("Entrance", blank=True,null=True) + linked_qms = models.ManyToManyField("QM", blank=True,null=True) + def __unicode__(self): - return unicode(self.short_name) + if self.long_name: + return unicode(self.long_name) + else: + 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): name = models.CharField(max_length=200, unique = True) diff --git a/core/templatetags/wiki_markup.py b/core/templatetags/wiki_markup.py index fabd11b..b4d97ac 100644 --- a/core/templatetags/wiki_markup.py +++ b/core/templatetags/wiki_markup.py @@ -71,7 +71,7 @@ def wiki_to_html_short(value, autoescape=None): value = re.sub("\[\[\s*person:(.+)\]\]",r'\1' % url_root, value, re.DOTALL) #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): """ 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]] 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: qm=QM.objects.get(found_by__cave__kataster_number = qmdict['cave'], found_by__date__year = qmdict['year'], @@ -95,7 +95,7 @@ def wiki_to_html_short(value, autoescape=None): title='placeholder' ) qm=QM(found_by = placeholder, number = qmdict['number']) - return r'%s %s' % (qm.get_absolute_url, qm.code, unicode(qm)) + return r'%s' % (qm.get_absolute_url(), qm.code, unicode(qm)) value = re.sub(qmMatchPattern,qmrepl, value, re.DOTALL) diff --git a/utils.py b/utils.py index 1db7e0b..2c181c7 100644 --- a/utils.py +++ b/utils.py @@ -103,8 +103,8 @@ re_subs = [(re.compile(r"\]*\>(.*?)\", re.DOTALL), r"'''\1'''"), (re.compile(r"\]*\>(.*?)\", re.DOTALL), r"======\1======"), (re.compile(r"\(.*?)\", re.DOTALL), r"[subcave:\1|\2]"), #interpage link needed - (re.compile(r"\(.*?)\", re.DOTALL), r"[cavedescription:\1|\2]"), - (re.compile(r"\[\([^\s]*).*?\\]", re.DOTALL), r"![qm:\1]"), + (re.compile(r"\(.*?)\", re.DOTALL), r"[[cavedescription:\1|\2]]"), + (re.compile(r"\[\([^\s]*).*?\\]", re.DOTALL), r"[[qm:\1]]"), ]