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"\